File: //usr/local/lib/python3.10/dist-packages/numpy/lib/__pycache__/_datasource.cpython-310.pyc
o
���ggX � @ s~ d Z ddlZddlZddlmZ eZdd� ZG dd� d�Ze� Z d ej
ddfd
d�Zed�G d
d� d��ZG dd� de�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, bz2 and xz are supported.
Example::
>>> # Create a DataSource, use os.curdir (default) for local storage.
>>> from numpy import DataSource
>>> ds = 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/') # doctest: +SKIP
>>>
>>> # Use the file as you normally would
>>> fp.read() # doctest: +SKIP
>>> fp.close() # doctest: +SKIP
� N� )�
set_modulec C sF d| v rd| v rt d| f ��dS |durt d��|dur!t d��dS )z�Check mode and that encoding and newline are compatible.
Parameters
----------
mode : str
File open mode.
encoding : str
File encoding.
newline : str
Newline for text files.
�t�bzInvalid mode: %rNz0Argument 'encoding' not supported in binary modez/Argument 'newline' not supported in binary mode)�
ValueError��mode�encoding�newline� r �@/usr/local/lib/python3.10/dist-packages/numpy/lib/_datasource.py�_check_mode. s
��r
c @ s0 e Zd ZdZdd� 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``, ``bz2`` or ``xz`` compression are supported.
Notes
-----
`_file_openers`, an instance of `_FileOpeners`, is made available for
use in the `_datasource` module.
Examples
--------
>>> import gzip
>>> np.lib._datasource._file_openers.keys()
[None, '.bz2', '.gz', '.xz', '.lzma']
>>> np.lib._datasource._file_openers['.gz'] is gzip.open
True
c C s d| _ d tji| _d S )NF)�_loaded�io�open�
_file_openers��selfr r r �__init__c s z_FileOpeners.__init__c C s� | j rd S zdd l}|j| jd<