class_docstr: DataSource(destpath='.')
  
  A generic data source file (file, http, ftp, ...).
  
  DataSources can be local files or remote files/URLs.  The files may
  also be compressed or uncompressed. DataSource hides some of the
  low-level details of downloading the file, allowing you to simply pass
  in a valid file path (or URL) and obtain a file object.
  
  Parameters
  ----------
  destpath : str or None, optional
      Path to the directory where the source file gets downloaded to for
      use.  If `destpath` is None, a temporary directory will be created.
      The default path is the current directory.
  
  Notes
  -----
  URLs require a scheme string (``http://``) to be used, without it they
  will fail::
  
      >>> repos = np.DataSource()
      >>> repos.exists('www.google.com/index.html')
      False
      >>> repos.exists('http://www.google.com/index.html')
      True
  
  Temporary directories are deleted when the DataSource is deleted.
  
  Examples
  --------
  ::
  
      >>> ds = np.DataSource('/home/guido')
      >>> urlname = 'http://www.google.com/'
      >>> gfile = ds.open('http://www.google.com/')
      >>> ds.abspath(urlname)
      '/home/guido/www.google.com/index.html'
  
      >>> ds = np.DataSource(None)  # use with temporary file
      >>> ds.open('/home/guido/foobar.txt')
      <open file '/home/guido.foobar.txt', mode 'r' at 0x91d4430>
      >>> ds.abspath('/home/guido/foobar.txt')
      '/tmp/.../home/guido/foobar.txt'
class_docstr_tok: ["DataSource","(","destpath=","'",".","'",")","A","generic","data","source","file","(","file",",","http",",","ftp",",","...",")",".","DataSources","can","be","local","files","or","remote","files\/URLs",".","The","files","may","also","be","compressed","or","uncompressed",".","DataSource","hides","some","of","the","low-level","details","of","downloading","the","file",",","allowing","you","to","simply","pass","in","a","valid","file","path","(","or","URL",")","and","obtain","a","file","object",".","Parameters","--","--","--","--","--","destpath",":","str","or","None",",","optional","Path","to","the","directory","where","the","source","file","gets","downloaded","to","for","use",".","If","`","destpath","`","is","None",",","a","temporary","directory","will","be","created",".","The","default","path","is","the","current","directory",".","Notes","--","--","-","URLs","require","a","scheme","string","(","``","http",":","\/\/","``",")","to","be","used",",","without","it","they","will","fail",":",":",">",">",">","repos","=","np.DataSource","(",")",">",">",">","repos.exists","(","'www.google.com\/index.html","'",")","False",">",">",">","repos.exists","(","'http",":","\/\/www.google.com\/index.html","'",")","True","Temporary","directories","are","deleted","when","the","DataSource","is","deleted",".","Examples","--","--","--","--",":",":",">",">",">","ds","=","np.DataSource","(","'\/home\/guido","'",")",">",">",">","urlname","=","'http",":","\/\/www.google.com\/'",">",">",">","gfile","=","ds.open","(","'http",":","\/\/www.google.com\/","'",")",">",">",">","ds.abspath","(","urlname",")","'\/home\/guido\/www.google.com\/index.html'",">",">",">","ds","=","np.DataSource","(","None",")","#","use","with","temporary","file",">",">",">","ds.open","(","'\/home\/guido\/foobar.txt","'",")","<","open","file","'\/home\/guido.foobar.txt","'",",","mode","'","r","'","at","0x91d4430",">",">",">",">","ds.abspath","(","'\/home\/guido\/foobar.txt","'",")","'\/tmp\/","...","\/home\/guido\/foobar.txt","'"]
docstr: Cache the file specified by path.
  
  Creates a copy of the file in the datasource cache.
docstr_tok: ["Cache","the","file","specified","by","path",".","Creates","a","copy","of","the","file","in","the","datasource","cache","."]
code: def _cache(self, path):
      """Cache the file specified by path.
  
      Creates a copy of the file in the datasource cache.
  
      """
      # We import these here because importing them is slow and
      # a significant fraction of numpy's total import time.
      import shutil
      from urllib.request import urlopen
  
      upath = self.abspath(path)
  
      # ensure directory exists
      if not os.path.exists(os.path.dirname(upath)):
          os.makedirs(os.path.dirname(upath))
  
      # TODO: Doesn't handle compressed files!
      if self._isurl(path):
          with urlopen(path) as openedurl:
              with _open(upath, "wb") as f:
                  shutil.copyfileobj(openedurl, f)
      else:
          shutil.copyfile(path, upath)
      return upath
  
imports: import os
  import io
  from .._utils import set_module
label_desc: Use image node_id 8 for calling the DataSource obj's underlying member method code with example usage: obj._cache(path) and returns: upath