ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ ]c@`sdZddlmZmZmZddlZddlZddlZeZ de fdYZ e Z dej dZde fd YZd efd YZdS( sA file interface for handling local and remote data files. The goal of datasource is to abstract some of the file system operations when dealing with data files so the researcher doesn't have to know all the low-level details. Through datasource, a researcher can obtain and use a file with one function call, regardless of location of the file. DataSource is meant to augment standard python libraries, not replace them. It should work seamlessly with standard file IO operations and the os module. DataSource files can originate locally or remotely: - local files : '/home/guido/src/local/data.txt' - URLs (http, ftp, ...) : 'http://www.scipy.org/not/real/data.txt' DataSource files can also be compressed or uncompressed. Currently only gzip and bz2 are supported. Example:: >>> # Create a DataSource, use os.curdir (default) for local storage. >>> ds = datasource.DataSource() >>> >>> # Open a remote file. >>> # DataSource downloads the file, stores it locally in: >>> # './www.google.com/index.html' >>> # opens the file and returns a file object. >>> fp = ds.open('http://www.google.com/index.html') >>> >>> # Use the file as you normally would >>> fp.read() >>> fp.close() i(tdivisiontabsolute_importtprint_functionNt _FileOpenerscB`s2eZdZdZdZdZdZRS(s Container for different methods to open (un-)compressed files. `_FileOpeners` contains a dictionary that holds one method for each supported file format. Attribute lookup is implemented in such a way that an instance of `_FileOpeners` itself can be indexed with the keys of that dictionary. Currently uncompressed files as well as files compressed with ``gzip`` or ``bz2`` compression are supported. Notes ----- `_file_openers`, an instance of `_FileOpeners`, is made available for use in the `_datasource` module. Examples -------- >>> np.lib._datasource._file_openers.keys() [None, '.bz2', '.gz'] >>> np.lib._datasource._file_openers['.gz'] is gzip.open True cC`st|_itd6|_dS(N(tFalset_loadedtopentNonet _file_openers(tself((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt__init__Js cC`s|jr dSy ddl}|j|jd>> repos = 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 = DataSource('/home/guido') >>> urlname = 'http://www.google.com/index.html' >>> gfile = ds.open('http://www.google.com/index.html') # remote file >>> ds.abspath(urlname) '/home/guido/www.google.com/site/index.html' >>> ds = DataSource(None) # use with temporary file >>> ds.open('/home/guido/foobar.txt') >>> ds.abspath('/home/guido/foobar.txt') '/tmp/tmpy4pgsP/home/guido/foobar.txt' cC`sO|r'tjj||_t|_n$ddl}|j|_t|_dS(s2Create a DataSource with a local path at destpath.iN( tosRtabspatht _destpathRt _istmpdestttempfiletmkdtempR(R RR"((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR s   cC`s |jrtj|jndS(N(R!tshutiltrmtreeR (R ((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt__del__s cC`s(tjj|\}}|tjkS(sNTest if the filename is a zip file by looking at the file extension. (RRtsplitextRR(R tfilenametfnametext((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt_iszipscC`s+d}x|D]}||kr tSq WtS(s4Test if the given mode will open a file for writing.twt+(R,R-(RR(R Rt _writemodestc((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt _iswritemodes   cC`s-|j|rtjj|S|dfSdS(sxSplit zip extension from filename and return filename. *Returns*: base, zip_ext : {tuple} N(R+RRR'R(R R(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt _splitzipextscC`sP|g}|j|sLx1tjD] }|r%|j||q%q%Wn|S(s9Return a tuple containing compressed filename variations.(R+RRtappend(R R(tnamestzipext((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt_possible_namess  c C`sdtjddkr&ddlm}nddlm}||\}}}}}}t|o`|S(s=Test if path is a net location. Tests the scheme and netloc.ii(turlparse(tsyst version_infot urllib.parseR6tbool( R RR6tschemetnetloctupathtuparamstuquerytufrag((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt_isurls cC`s4tjddkr6ddlm}ddlm}n ddlm}ddlm}|j|}tj j tj j |stj tj j |n|j |r yK||}t|d}ztj||Wd|j|jXWq0|k r|d|q0Xntj|||S(shCache the file specified by path. Creates a copy of the file in the datasource cache. ii(turlopen(tURLErrortwbNsURL not found: %s(R7R8turllib.requestRBt urllib.errorRCturllib2RRRtexiststdirnametmakedirsRAt_openR$t copyfileobjtclosetcopyfile(R RRBRCR=t openedurltf((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt_caches(   cC`s|j|s=|j|}||j|j|7}n+|j|j|}||j|}xB|D]:}|j|ro|j|r|j|}n|SqoWdS(sySearches for ``path`` and returns full path if found. If path is an URL, _findfile will cache a local copy and return the path to the cached file. If path is a local file, _findfile will return a path to that local file. The search will include possible compressed versions of the file and return the first occurrence found. N(RAR5RRHRQR(R Rtfilelisttname((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt _findfile8s  c C`stjddkr&ddlm}nddlm}|j|jd}t|dkrj|d}n||\}}}}}} |j|}|j|}tj j |j||S(sF Return absolute path of file in the DataSource directory. If `path` is an URL, then `abspath` will return either the location the file exists locally or the location it would exist when opened using the `open` method. Parameters ---------- path : str Can be a local file or a remote URL. Returns ------- out : str Complete path, including the `DataSource` destination directory. Notes ----- The functionality is based on `os.path.abspath`. ii(R6ii( R7R8R9R6tsplitR tlent_sanitize_relative_pathRRtjoin( R RR6t splitpathR;R<R=R>R?R@((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRWs  cC`sd}tjj|}xd||kr~|}|jtjjd}|jtjjd}tjj|\}}qW|S(svReturn a sanitised relative path for which os.path.abspath(os.path.join(base, path)).startswith(base) t/s..N(RRRtnormpathtlstriptseptpardirt splitdrive(R Rtlasttdrive((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRWscC`stjddkr6ddlm}ddlm}n ddlm}ddlm}tjj |rlt S|j |}tjj |rt S|j |ry!||}|j ~t SWq|k rtSXntS(s3 Test if path exists. Test if `path` exists as (and in this order): - a local file. - a remote URL that has been downloaded and stored locally in the `DataSource` directory. - a remote URL that has not been downloaded, but is valid and accessible. Parameters ---------- path : str Can be a local file or a remote URL. Returns ------- out : bool True if `path` exists. Notes ----- When `path` is an URL, `exists` will return True if it's either stored locally in the `DataSource` directory, or is a valid remote URL. `DataSource` does not discriminate between the two, the file is accessible if it exists in either location. ii(RB(RC(R7R8RERBRFRCRGRRRHRRRARMR(R RRBRCR=tnetfile((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRHs&    RcC`s|j|r-|j|r-tdn|j|}|r|j|\}}|dkrv|jddnt||d|Std|dS(sR Open and return file-like object. If `path` is an URL, it will be downloaded, stored in the `DataSource` directory and opened from there. Parameters ---------- path : str Local file path or URL to open. mode : {'r', 'w', 'a'}, optional Mode to open `path`. Mode 'r' for reading, 'w' for writing, 'a' to append. Available modes depend on the type of object specified by `path`. Default is 'r'. Returns ------- out : file object File object. sURLs are not writeableR R-tRs %s not found.N(RAR0t ValueErrorRTR1treplaceRtIOError(R RRtfoundt_fnameR*((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRs (RRRRtcurdirR R&R+R0R1R5RARQRTRRWRHR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRs/    %  -  ;t RepositorycB`s_eZdZejdZdZdZdZdZ dZ ddZ d Z RS( s Repository(baseurl, destpath='.') A data repository where multiple DataSource's share a base URL/directory. `Repository` extends `DataSource` by prepending a base URL (or directory) to all the files it handles. Use `Repository` when you will be working with multiple files from one base URL. Initialize `Repository` with the base URL, then refer to each file by its filename only. Parameters ---------- baseurl : str Path to the local directory or remote location that contains the data files. 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. Examples -------- To analyze all files in the repository, do something like this (note: this is not self-contained code):: >>> repos = np.lib._datasource.Repository('/home/user/data/dir/') >>> for filename in filelist: ... fp = repos.open(filename) ... fp.analyze() ... fp.close() Similarly you could use a URL for a repository:: >>> repos = np.lib._datasource.Repository('http://www.xyz.edu/data') cC`s tj|d|||_dS(s>Create a Repository with a shared url or directory of baseurl.RN(RR t_baseurl(R tbaseurlR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR scC`stj|dS(N(RR&(R ((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR&%scC`sL|j|jd}t|dkrBtjj|j|}n|}|S(s>Return complete path for path. Prepends baseurl if necessary.ii(RURkRVRRRX(R RRYtresult((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt _fullpath(s cC`stj||j|S(s8Extend DataSource method to prepend baseurl to ``path``.(RRTRn(R R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRT1scC`stj||j|S(sk Return absolute path of file in the Repository directory. If `path` is an URL, then `abspath` will return either the location the file exists locally or the location it would exist when opened using the `open` method. Parameters ---------- path : str Can be a local file or a remote URL. This may, but does not have to, include the `baseurl` with which the `Repository` was initialized. Returns ------- out : str Complete path, including the `DataSource` destination directory. (RRRn(R R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR5scC`stj||j|S(s Test if path exists prepending Repository base URL to path. Test if `path` exists as (and in this order): - a local file. - a remote URL that has been downloaded and stored locally in the `DataSource` directory. - a remote URL that has not been downloaded, but is valid and accessible. Parameters ---------- path : str Can be a local file or a remote URL. This may, but does not have to, include the `baseurl` with which the `Repository` was initialized. Returns ------- out : bool True if `path` exists. Notes ----- When `path` is an URL, `exists` will return True if it's either stored locally in the `DataSource` directory, or is a valid remote URL. `DataSource` does not discriminate between the two, the file is accessible if it exists in either location. (RRHRn(R R((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRHLs RcC`stj||j||S(s Open and return file-like object prepending Repository base URL. If `path` is an URL, it will be downloaded, stored in the DataSource directory and opened from there. Parameters ---------- path : str Local file path or URL to open. This may, but does not have to, include the `baseurl` with which the `Repository` was initialized. mode : {'r', 'w', 'a'}, optional Mode to open `path`. Mode 'r' for reading, 'w' for writing, 'a' to append. Available modes depend on the type of object specified by `path`. Default is 'r'. Returns ------- out : file object File object. (RRRn(R RR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRnscC`s5|j|jr!tdntj|jSdS(s  List files in the source Repository. Returns ------- files : list of str List of file names (not containing a directory part). Notes ----- Does not currently work for remote repositories. s-Directory listing of URLs, not supported yet.N(RARktNotImplementedErrorRtlistdir(R ((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRps ( RRRRRiR R&RnRTRRHRRp(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRjs&    " (Rt __future__RRRRR7R$RRKtobjectRRRiRRj(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt#s   B $_