관리-도구
편집 파일: _datasource.cpython-311.pyc
� �܋fgX � �� � d Z ddlZddlZddlmZ eZd� Z G d� d� � Z e� � Z dej ddfd �Z ed � � G d� d� � � � Z G d � 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 � � d| v rd| v rt d| ��� � �dS |�t d� � �|�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: Nz0Argument 'encoding' not supported in binary modez/Argument 'newline' not supported in binary mode)� ValueError��mode�encoding�newlines �L/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/lib/_datasource.py�_check_moder . sf � � �d�{�{��$�;�;��*�4�4�9�:�:�:� �;� ���O�P�P�P����N�O�O�O� �� c �* � e Zd ZdZd� Zd� Zd� Zd� ZdS )�_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 �: � d| _ d t j i| _ d S )NF)�_loaded�io�open� _file_openers��selfs r �__init__z_FileOpeners.__init__c s � ����"�B�G�_����r c �0 � | j rd S dd l}|j | j d<