MCPcopy Create free account
hub / github.com/numpy/numpy / DataSource

Class DataSource

numpy/lib/_datasource.py:197–533  ·  view source on GitHub ↗

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 pa

Source from the content-addressed store, hash-verified

195
196@set_module('numpy')
197class DataSource:
198 """
199 DataSource(destpath='.')
200
201 A generic data source file (file, http, ftp, ...).
202
203 DataSources can be local files or remote files/URLs. The files may
204 also be compressed or uncompressed. DataSource hides some of the
205 low-level details of downloading the file, allowing you to simply pass
206 in a valid file path (or URL) and obtain a file object.
207
208 Parameters
209 ----------
210 destpath : str or None, optional
211 Path to the directory where the source file gets downloaded to for
212 use. If `destpath` is None, a temporary directory will be created.
213 The default path is the current directory.
214
215 Notes
216 -----
217 URLs require a scheme string (``http://``) to be used, without it they
218 will fail::
219
220 >>> repos = np.DataSource()
221 >>> repos.exists('www.google.com/index.html')
222 False
223 >>> repos.exists('http://www.google.com/index.html')
224 True
225
226 Temporary directories are deleted when the DataSource is deleted.
227
228 Examples
229 --------
230 ::
231
232 >>> ds = np.DataSource('/home/guido')
233 >>> urlname = 'http://www.google.com/'
234 >>> gfile = ds.open('http://www.google.com/')
235 >>> ds.abspath(urlname)
236 '/home/guido/www.google.com/index.html'
237
238 >>> ds = np.DataSource(None) # use with temporary file
239 >>> ds.open('/home/guido/foobar.txt')
240 <open file '/home/guido.foobar.txt', mode 'r' at 0x91d4430>
241 >>> ds.abspath('/home/guido/foobar.txt')
242 '/tmp/.../home/guido/foobar.txt'
243
244 """
245
246 def __init__(self, destpath=os.curdir):
247 """Create a DataSource with a local path at destpath."""
248 if destpath:
249 self._destpath = os.path.abspath(destpath)
250 self._istmpdest = False
251 else:
252 import tempfile # deferring import to improve startup time
253 self._destpath = tempfile.mkdtemp()
254 self._istmpdest = True

Callers 1

openFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected