
    +d                     B    d dl mZmZ  G d dej                  Zd ZdS )   )baseimport_namec                   R     e Zd ZdZdZdZdZdZd fd	Zd	 Z	d
 Z
d Zd Zd Z xZS )TextFilesSourcea  Read textfiles as sequence of lines

    Prototype of sources reading sequential data.

    Takes a set of files, and returns an iterator over the text in each of them.
    The files can be local or remote. Extra parameters for encoding, etc.,
    go into ``storage_options``.
    	textfilesz0.0.1pythonTutf8Nc	                 ,   || _         |pi | _        d| _        d| _        t	          |t
                    rt          |          }|| _        || _        |rdnd| _	        || _
        || _        t          t          |                               |           dS )a  

        Parameters
        ----------
        urlpath : str or list(str)
            Target files. Can be a glob-path (with "*") and include protocol
            specified (e.g., "s3://"). Can also be a list of absolute paths.
        text_mode : bool
            Whether to open the file in text mode, recoding binary
            characters on the fly
        text_encoding : str
            If text_mode is True, apply this encoding. UTF* is by far the most
            common
        compression : str or None
            If given, decompress the file with the given codec on load. Can
            be something like "gzip", "bz2", or to try to guess from the filename,
            'infer'
        decoder : function, str or None
            Use this to decode the contents of files. If None, you will get
            a list of lines of text/bytes. If a function, it must operate on
            an open file-like object or a bytes/str instance, and return a
            list
        read : bool
            If decoder is not None, this flag controls whether bytes/str get
            passed to the function indicated (True) or the open file-like
            object (False)
        storage_options: dict
            Options to pass to the file reader backend, including text-specific
            encoding arguments, and parameters specific to the remote
            file-system driver, if using.
        Nrtrb)metadata)_urlpath_storage_options
_dataframe_files
isinstancestrr   decodercompressionmodeencoding_readsuperr   __init__)
selfurlpath	text_modetext_encodingr   r   readr   storage_options	__class__s
            7lib/python3.11/site-packages/intake/source/textfiles.pyr   zTextFilesSource.__init__   s    @   / 52gs## 	+!'**G&%/DD4	%
ot$$--x-@@@@@    c                    ddl m} | j        _|                     | j                  d         } ||f| j        | j        | j        d| j        | _        t          | j                  | _
        t          j        d d| j
        | j                  S )N    )
open_files)r   r   r   N)dtypeshapenpartitionsextra_metadata)fsspecr&   r   
_get_cacher   r   r   r   r   lenr*   r   Schemar   )r   r&   r   s      r"   _get_schemazTextFilesSource._get_schemaH   s    %%%%%%; 	0oodm44Q7G$*W  M49t}bfbr  M  Mvz  wL  M  MDK"4;//D{W$BRcgcpqqqqr#   c                 N    t          | j        |         | j        | j                  S r'   )get_filer   r   r   )r   is     r"   _get_partitionzTextFilesSource._get_partitionR   s    AdjAAAr#   c                 v    |                                   |                                                                 S r'   )r0   to_daskcompute)r   s    r"   r   zTextFilesSource.readU   s.    ||~~%%'''r#   c                 b    ddl m}  |dd| j        ffgi           }|                                S )Nr%   )SparkHolderFtextFile)intake_spark.baser9   r   setup)r   r9   hs      r"   to_sparkzTextFilesSource.to_sparkY   sB    111111Kdm-= >?DDwwyyr#   c                      dd l m} ddlm}                                    |t
                    |                     fd j        D                       S )Nr%   )delayedc                 >    g | ]} |j         j                  S  )r   r   ).0fdfiler   s     r"   
<listcomp>z+TextFilesSource.to_dask.<locals>.<listcomp>e   s+    XXXqatz B BXXXr#   )dask.bagbagdaskr@   r0   r2   from_delayedr   )r   dbr@   rE   s   `  @r"   r6   zTextFilesSource.to_dask_   su          !!XXXXXDKXXXYYYr#   )Tr	   NNTNN)__name__
__module____qualname____doc__nameversion	containerpartition_accessr   r0   r4   r   r>   r6   __classcell__)r!   s   @r"   r   r      s          DGI,A ,A ,A ,A ,A ,A\r r rB B B( ( (  Z Z Z Z Z Z Zr#   r   c                    | 5 } |t          |           cddd           S |r|                                 n| } ||          }t          |t          t           f          r|cddd           S |gcddd           S # 1 swxY w Y   dS )z?Serializable function to take an OpenFile object and read linesN)listr   r   tuple)rD   r   r   douts        r"   r2   r2   h   s   	
 	a 	77	 	 	 	 	 	 	 	 !'aA'!**C#t}-- 	 	 	 	 	 	 	 	 u	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A=A A=.A==BBN) r   r   
DataSourcer   r2   rB   r#   r"   <module>r\      su            ZZ ZZ ZZ ZZ ZZdo ZZ ZZ ZZz    r#   