%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyo

�
�9Zc@`s�dZddlmZmZmZddlZddlZddlZeZ	de
fd��YZe�Zdej
d�Zde
fd	��YZd
efd��YZdS(s�A 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 seemlessly 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`s2eZdZd�Zd�Zd�Zd�ZRS(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<Wntk
r@nXy ddl}|j|jd<Wntk
rtnXt|_dS(Nis.bz2s.gz(Rtbz2tBZ2FileRtImportErrortgzipRtTrue(R	RR((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt_loadNs	

cC`s|j�t|jj��S(s\
        Return the keys of currently supported file openers.

        Parameters
        ----------
        None

        Returns
        -------
        keys : list
            The keys are None for uncompressed files and the file extension
            strings (i.e. ``'.gz'``, ``'.bz2'``) for supported compression
            methods.

        (RtlistRtkeys(R	((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR]s
cC`s|j�|j|S(N(RR(R	tkey((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt__getitem__ps
(t__name__t
__module__t__doc__R
RRR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR2s
			trcC`st|�}|j||�S(s�
    Open `path` with `mode` and return the file object.

    If ``path`` is an URL, it will be downloaded, stored in the
    `DataSource` `destpath` directory and opened from there.

    Parameters
    ----------
    path : str
        Local file path or URL to open.
    mode : str, 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'.
    destpath : str, 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.

    Returns
    -------
    out : file object
        The opened file.

    Notes
    -----
    This is a convenience function that instantiates a `DataSource` and
    returns the file object from ``DataSource.open(path)``.

    (t
DataSourceR(tpathtmodetdestpathtds((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRvs RcB`s�eZdZejd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
d�ZRS(s 
    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 = 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')
        <open file '/home/guido.foobar.txt', mode 'r' at 0x91d4430>
        >>> 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|j�ndS(N(R!tshutiltrmtreeR (R	((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt__del__�s	cC`s(tjj|�\}}|tj�kS(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_iszip�scC`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_iswritemode�s

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_splitzipext�scC`sP|g}|j|�sLx1tj�D] }|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_names�s	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|��s�tjtj	j|��n|j
|�r yK||�}t|d�}ztj||�Wd|j�|j�XWq0|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$tcopyfileobjtclosetcopyfile(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(sxSearches 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 occurence found.

        N(RAR5RRHRQR(R	Rtfilelisttname((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt	_findfile8s

c
C`s�tjddkr&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`s�d}tjj|�}xd||kr~|}|jtj�jd�}|jtj�jd�}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.pyRW�scC`s�tjddkr6ddlm}ddlm}n ddlm}ddlm}tjj	|�rlt
S|j|�}tjj	|�r�t
S|j|�r�y!||�}|j
�~t
SWq�|k
r�tSXntS(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.pyRH�s& 

RcC`s�|j|�r-|j|�r-td��n|j|�}|r�|j|�\}}|dkrv|jdd�nt||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 writeableRR-tRs
%s not found.N(RAR0t
ValueErrorRTR1treplaceRtIOError(R	RRtfoundt_fnameR*((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR�s(RRRRtcurdirR
R&R+R0R1R5RARQRTRRWRHR(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyR�s/
			
	
				%		-		;t
RepositorycB`s_eZdZejd�Zd�Zd�Zd�Zd�Z	d�Z
dd�Zd	�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|j�r!td��ntj|j�SdS(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.pyRp�s(
RRRRRiR
R&RnRTRRHRRp(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyRj�s&						"(Rt
__future__RRRRR7R$RRKtobjectRRRiRRj(((sH/opt/alt/python27/lib64/python2.7/site-packages/numpy/lib/_datasource.pyt<module>#sB	$�_

Zerion Mini Shell 1.0