403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.19.244.133
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/__pycache__/_datasource.cpython-37.pyc
B

��FdS�@s~dZddlmZmZmZddlZddlZddlZeZ	Gdd�de
�Ze�Zdej
fdd�ZGd	d
�d
e
�ZGdd�de�ZdS)
a�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 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()

�)�division�absolute_import�print_functionNc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_FileOpenersa�
    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

    cCsd|_dti|_dS)NF)�_loaded�open�
_file_openers)�self�r
�H/opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/_datasource.py�__init__Jsz_FileOpeners.__init__cCsp|jr
dSyddl}|j|jd<Wntk
r6YnXyddl}|j|jd<Wntk
rdYnXd|_dS)Nrz.bz2z.gzT)r�bz2�BZ2Filer�ImportError�gzipr)r	r
rr
r
r�_loadNsz_FileOpeners._loadcCs|��t|j���S)a\
        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.

        )r�listr�keys)r	r
r
rr]sz_FileOpeners.keyscCs|��|j|S)N)rr)r	�keyr
r
r�__getitem__psz_FileOpeners.__getitem__N)�__name__�
__module__�__qualname__�__doc__rrrrr
r
r
rr2s
r�rcCst|�}|�||�S)a�
    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)``.

    )�
DataSourcer)�path�mode�destpath�dsr
r
rrvs rc@s�eZdZdZejfdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zddd�ZdS)ra 
    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'

    cCs6|rtj�|�|_d|_nddl}|��|_d|_dS)z2Create a DataSource with a local path at destpath.FrNT)�osr�abspath�	_destpath�
_istmpdest�tempfile�mkdtemp)r	rr$r
r
rr�s
zDataSource.__init__cCs|jrt�|j�dS)N)r#�shutil�rmtreer")r	r
r
r�__del__�szDataSource.__del__cCstj�|�\}}|t��kS)zNTest if the filename is a zip file by looking at the file extension.

        )r r�splitextrr)r	�filename�fname�extr
r
r�_iszip�szDataSource._iszipcCs"d}x|D]}||kr
dSq
WdS)z4Test if the given mode will open a file for writing.)�w�+TFr
)r	rZ_writemodes�cr
r
r�_iswritemode�s

zDataSource._iswritemodecCs"|�|�rtj�|�S|dfSdS)zxSplit zip extension from filename and return filename.

        *Returns*:
            base, zip_ext : {tuple}

        N)r-r rr))r	r*r
r
r�_splitzipext�s
zDataSource._splitzipextcCs8|g}|�|�s4x"t��D]}|r|�||�qW|S)z9Return a tuple containing compressed filename variations.)r-rr�append)r	r*�namesZzipextr
r
r�_possible_names�s
zDataSource._possible_namesc	CsHtjddkrddlm}nddlm}||�\}}}}}}t|oD|�S)z=Test if path is a net location.  Tests the scheme and netloc.r�)�urlparse)�sys�version_info�urllib.parser7�bool)	r	rr7�scheme�netloc�upath�uparams�uquery�ufragr
r
r�_isurls
zDataSource._isurlcCs�tjddkr(ddlm}ddlm}nddlm}ddlm}|�|�}tj	�
tj	�|��spt�tj	�|��|�
|�r�y:||�}t|d�}zt�||�Wd|��|��XWq�|k
r�|d|��Yq�Xnt�||�|S)zhCache the file specified by path.

        Creates a copy of the file in the datasource cache.

        rr6)�urlopen)�URLError�wbNzURL not found: %s)r8r9�urllib.requestrC�urllib.errorrD�urllib2r!r r�exists�dirname�makedirsrB�_openr&�copyfileobj�close�copyfile)r	rrCrDr>Z	openedurl�fr
r
r�_caches(


zDataSource._cachecCs||�|�s*|�|�}||�|�|��7}n|�|�|��}||�|�}x.|D]&}|�|�rN|�|�rp|�|�}|SqNWdS)aySearches 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)rBr5r!rIrQ)r	r�filelist�namer
r
r�	_findfile8s





zDataSource._findfilec
Cs�tjddkrddlm}nddlm}|�|jd�}t|�dkrJ|d}||�\}}}}}}	|�|�}|�|�}tj	�
|j||�S)aF
        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`.

        rr6)r7��)r8r9r:r7�splitr"�len�_sanitize_relative_pathr r�join)
r	rr7�	splitpathr<r=r>r?r@rAr
r
rr!Ws


zDataSource.abspathcCsZd}tj�|�}xD||krT|}|�tj��d�}|�tj��d�}tj�|�\}}qW|S)zvReturn a sanitised relative path for which
        os.path.abspath(os.path.join(base, path)).startswith(base)
        N�/z..)r r�normpath�lstrip�sep�pardir�
splitdrive)r	r�last�driver
r
rrY�s
z"DataSource._sanitize_relative_pathcCs�tjddkr(ddlm}ddlm}nddlm}ddlm}tj�	|�rPdS|�
|�}tj�	|�rjdS|�|�r�y||�}|��~dS|k
r�dSXdS)a3
        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.

        rr6)rC)rDTF)
r8r9rFrCrGrDrHr rrIr!rBrN)r	rrCrDr>Znetfiler
r
rrI�s& 

zDataSource.existsrcCsl|�|�r|�|�rtd��|�|�}|r\|�|�\}}|dkrL|�dd�t|||d�Std|��dS)aR
        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.

        zURLs are not writeabler
r/�)rz
%s not found.N)rBr1�
ValueErrorrTr2�replacer�IOError)r	rr�foundZ_fnamer,r
r
rr�s
zDataSource.openN)r)rrrrr �curdirrr(r-r1r2r5rBrQrTr!rYrIrr
r
r
rr�s/


	%-;rc@sXeZdZdZejfdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zddd�Zdd�Z
dS)�
Repositorya
    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')

    cCstj||d�||_dS)z>Create a Repository with a shared url or directory of baseurl.)rN)rr�_baseurl)r	Zbaseurlrr
r
rr szRepository.__init__cCst�|�dS)N)rr()r	r
r
rr(%szRepository.__del__cCs4|�|jd�}t|�dkr,tj�|j|�}n|}|S)z>Return complete path for path.  Prepends baseurl if necessary.rUrV)rWrkrXr rrZ)r	rr[�resultr
r
r�	_fullpath(s
zRepository._fullpathcCst�||�|��S)z8Extend DataSource method to prepend baseurl to ``path``.)rrTrm)r	rr
r
rrT1szRepository._findfilecCst�||�|��S)ak
        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.

        )rr!rm)r	rr
r
rr!5szRepository.abspathcCst�||�|��S)a�
        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.

        )rrIrm)r	rr
r
rrILs zRepository.existsrcCst�||�|�|�S)a�
        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.

        )rrrm)r	rrr
r
rrnszRepository.opencCs&|�|j�rtd��nt�|j�SdS)a
        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.

        z-Directory listing of URLs, not supported yet.N)rBrk�NotImplementedErrorr �listdir)r	r
r
rro�szRepository.listdirN)r)rrrrr rirr(rmrTr!rIrror
r
r
rrj�s&	"
rj)r�
__future__rrrr r8r&rrL�objectrrrirrjr
r
r
r�<module>#sB$`

Youez - 2016 - github.com/yon3zu
LinuXploit