Fetches a file, unpacking it if necessary.
542510
def select(self, binary_request):
    """"""

    logger.debug("binary_request: {!r}".format(binary_request))

    try:
      download_path = self._get_download_path(binary_request)
    except self.MissingMachineInfo as e:
      raise self.BinaryResolutionError(binary_request, e)

    try:
      url_generator = self._get_url_generator(binary_request)
    except self.NoBaseUrlsError as e:
      raise self.BinaryResolutionError(binary_request, e)

    urls = self._get_urls(url_generator, binary_request)
    if not isinstance(urls, list):
      # TODO: add test for this error!
      raise self.BinaryResolutionError(
        binary_request,
        TypeError("urls must be a list: was '{}'.".format(urls)))
    fetch_request = BinaryFetchRequest(
      download_path=download_path,
      urls=urls)

    logger.debug("fetch_request: {!r}".format(fetch_request))

    try:
      downloaded_file = self._binary_tool_fetcher.fetch_binary(fetch_request)
    except BinaryToolFetcher.BinaryNotFound as e:
      raise self.BinaryResolutionError(binary_request, e)

    # NB: we mark the downloaded file executable if it is not an archive.
    archiver = binary_request.archiver
    if archiver is None:
      chmod_plus_x(downloaded_file)
      return downloaded_file

    download_dir = os.path.dirname(downloaded_file)
    # Use the 'name' given in the request as the directory name to extract to.
    unpacked_dirname = os.path.join(download_dir, binary_request.name)
    if not os.path.isdir(unpacked_dirname):
      logger.info("Extracting {} to {} .".format(downloaded_file, unpacked_dirname))
      archiver.extract(downloaded_file, unpacked_dirname, concurrency_safe=True)
    return unpacked_dirname
1052045
def from_file(cls, path, encoding, dialect, fields, converters, field_index):
        """"""

        return cls(open(path, 'r', encoding=encoding), dialect, fields, converters, field_index)
73720
def load(cls, path):
        """"""
        assert os.path.exists(path), "No such file: %r" % path

        (folder, filename) = os.path.split(path)
        (name, extension) = os.path.splitext(filename)

        image = Image(None)
        image._path = path
        image._format = Image.image_format(extension)

        return image
392138
def load_stream(filename):
    """"""
    rawfile = pkg_resources.resource_stream(__name__, filename)
    if six.PY2:
        return rawfile
    return io.TextIOWrapper(rawfile, 'utf-8')
1303335
def load(self, filename, offset):
        """"""
        try:
            self.offset = offset
            # self.fd = open(filename, 'rb')
            # self.fd.close()
        except IOError as e:
            print(e)
452891
def unpack(file, dest)
      ::Zip::ZipFile.foreach(file) do |zentry|
        epath = "#{dest}/#{zentry}"
        dirname = File.dirname(epath)
        FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
        zentry.extract(epath) unless File.exists?(epath)
      end
    end
934396
def _fromfile(self):
        """"""
        self._fd.seek(0)
        try:
            self.byte_order = {b'II': '<', b'MM': '>'}[self._fd.read(2)]
        except KeyError:
            raise ValueError("not a valid TIFF file")
        version = struct.unpack(self.byte_order+'H', self._fd.read(2))[0]
        if version == 43:  # BigTiff
            self.offset_size, zero = struct.unpack(self.byte_order+'HH',
                                                   self._fd.read(4))
            if zero or self.offset_size != 8:
                raise ValueError("not a valid BigTIFF file")
        elif version == 42:
            self.offset_size = 4
        else:
            raise ValueError("not a TIFF file")
        self.pages = []
        while True:
            try:
                page = TIFFpage(self)
                self.pages.append(page)
            except StopIteration:
                break
        if not self.pages:
            raise ValueError("empty TIFF file")
140512
def load(self, file, name=None):
        """"""
        if name is None:
            name = self.format_from_extension(op.splitext(file)[1])
        file_format = self.file_type(name)
        if file_format == 'text':
            return _read_text(file)
        elif file_format == 'json':
            return _read_json(file)
        else:
            load_function = self._formats[name].get('load', None)
            if load_function is None:
                raise IOError("The format must declare a file type or "
                              "load/save functions.")
            return load_function(file)
67343
def fetch(bank, key, cachedir):
    '''
    
    '''
    inkey = False
    key_file = os.path.join(cachedir, os.path.normpath(bank), '{0}.p'.format(key))
    if not os.path.isfile(key_file):
        # The bank includes the full filename, and the key is inside the file
        key_file = os.path.join(cachedir, os.path.normpath(bank) + '.p')
        inkey = True

    if not os.path.isfile(key_file):
        log.debug('Cache file "%s" does not exist', key_file)
        return {}
    try:
        with salt.utils.files.fopen(key_file, 'rb') as fh_:
            if inkey:
                return __context__['serial'].load(fh_)[key]
            else:
                return __context__['serial'].load(fh_)
    except IOError as exc:
        raise SaltCacheError(
            'There was an error reading the cache file "{0}": {1}'.format(
                key_file, exc
            )
        )
50967
def get_file(fn):
    """"""
    fn = os.path.join(os.path.dirname(__file__), 'data', fn)
    f = open(fn, 'rb')
    lines = [line.decode('utf-8').strip() for line in f.readlines()]
    return lines
478660
private static void unpackFile(InputStream in, File file) {
        byte[] buffer = new byte[4096];

        try {
            OutputStream out = new FileOutputStream(file);
            int read;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
189926
def read(self, file):
        """"""
        content = self._read_content(file)
        self._validate(content)
        self._parse(content)

        return self
779108
def _maybe_read_file(filename):
  
  try:
    with open(filename) as infile:
      return infile.read()
  except IOError as e:
    if e.errno == errno.ENOENT:
      return None
959053
def unpackfile(filename, destdir):
    """"""
    if filename.endswith(".mar"):
        return unpackmar(filename, destdir)
    elif filename.endswith(".exe"):
        return unpackexe(filename, destdir)
    elif filename.endswith(".tar") or filename.endswith(".tar.gz") \
            or filename.endswith(".tgz"):
        return unpacktar(filename, destdir)
    else:
        raise ValueError("Unknown file type: %s" % filename)
552882
def extract_file_from_zip(bytes_io, expected_file):
    """"""
    zipf = zipfile.ZipFile(bytes_io) 
    return zipf.read(expected_file)
916688
def from_file(filename, serverEndpoint=ServerEndpoint):
    '''
    
    '''
    tarOutput = parse1('unpack', filename, serverEndpoint,
                       responseMimeType='application/x-tar',
                       services={'meta': '/meta', 'text': '/tika',
                                 'all': '/rmeta/xml', 'unpack': '/unpack/all'},
                       rawResponse=True)
    return _parse(tarOutput)
1059947
def reads(s, filename=None, loader=None, implicit_tuple=True, allow_errors=False):
  """"""
  return ast.reads(s,
      filename=filename or '<input>',
      loader=loader or default_loader,
      implicit_tuple=implicit_tuple,
      allow_errors=allow_errors)