
    bi                        d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZmZ 	 	 	 	 	 	 d
dZd	 Zy)    )annotationsN)OpenFileget_fs_token_paths)infer_compression
read_block)tokenize)delayed)
is_integerparse_bytesc                   t        | t        t        t        t        j
                  f      st        d      t        | d|      \  }}	}
t        |
      dk(  rt        d| z        |<t        |t              rt        |      }t        |      st        d      t        |      }|"dggt        |
      z  }dggt        |
      z  }n5g }g }|
D ]+  }|dk(  rt        |      }n|}|t        d	      |j                  |      d
   }|t        d      |dk(  r#|j!                  g        |j!                  g        m||z  r||kD  r	|||z  z  }n|}d}dg}g }||z
  |dz  dz
  kD  rH||z  }|j!                  t        |             |j!                  |d   |d   z
         ||z
  |dz  dz
  kD  rH|j!                  ||d   z
         |rd|d<   |dxx   dz  cc<   |j!                  |       |j!                  |       . t#        t$              }g }t'        |
||      D ]  \  }}}t)        |	|||j+                  |      ||      }|D cg c]
  }d| d|  }}t'        |||      D cg c]  \  }}} |t-        |||      ||||      ! }}}}|j!                  |        |r|du rd}t        |t              rt        |      }t-        ||
d   |      5 }||j/                  |      }nN|j/                  |      }	 |j/                  |      }|sn&||v r||j1                  |d      d   z   |z   }n||z   }:|}ddd       |r|||
fS ||fS c c}w c c}}}w # 1 sw Y    xY w)aU	  Given a path or paths, return delayed objects that read from those paths.

    The path may be a filename like ``'2015-01-01.csv'`` or a globstring
    like ``'2015-*-*.csv'``.

    The path may be preceded by a protocol, like ``s3://`` or ``hdfs://`` if
    those libraries are installed.

    This cleanly breaks data by a delimiter if given, so that block boundaries
    start directly after a delimiter and end on the delimiter.

    Parameters
    ----------
    urlpath : string or list
        Absolute or relative filepath(s). Prefix with a protocol like ``s3://``
        to read from alternative filesystems. To read from multiple files you
        can pass a globstring or a list of paths, with the caveat that they
        must all have the same protocol.
    delimiter : bytes
        An optional delimiter, like ``b'\n'`` on which to split blocks of
        bytes.
    not_zero : bool
        Force seek of start-of-file delimiter, discarding header.
    blocksize : int, str
        Chunk size in bytes, defaults to "128 MiB"
    compression : string or None
        String like 'gzip' or 'xz'.  Must support efficient random access.
    sample : int, string, or boolean
        Whether or not to return a header sample.
        Values can be ``False`` for "no sample requested"
        Or an integer or string value like ``2**20`` or ``"1 MiB"``
    include_path : bool
        Whether or not to include the path with the bytes representing a particular file.
        Default is False.
    **kwargs : dict
        Extra options that make sense to a particular storage connection, e.g.
        host, port, username, password, etc.

    Examples
    --------
    >>> sample, blocks = read_bytes('2015-*-*.csv', delimiter=b'\n')  # doctest: +SKIP
    >>> sample, blocks = read_bytes('s3://bucket/2015-*-*.csv', delimiter=b'\n')  # doctest: +SKIP
    >>> sample, paths, blocks = read_bytes('2015-*-*.csv', include_path=True)  # doctest: +SKIP

    Returns
    -------
    sample : bytes
        The sample header
    blocks : list of lists of ``dask.Delayed``
        Each list corresponds to a file, and each delayed object computes to a
        block of bytes from that file.
    paths : list of strings, only included if include_path is True
        List of same length as blocks, where each item is the path to the file
        represented in the corresponding block.

    z3Path should be a string, os.PathLike, list or tuplerb)modestorage_optionsr   z%s resolved to no filesNzblocksize must be an integerinferzHCannot do chunked reads on compressed files. To read, set blocksize=NonesizezfBacking filesystem couldn't determine file size, cannot do chunked reads. To read, set blocksize=None.      zread-block--)compression)dask_key_nameT10 kiB)
isinstancestrlisttupleosPathLike	TypeErrorr   lenOSErrorr   r
   intr   
ValueErrorinfoappendr	   read_block_from_filezipr   ukeyr   readsplit) urlpath	delimiternot_zero	blocksizesampler   include_pathkwargsfsfs_tokenpathsoffsetslengthspathcompr   
blocksize1placeofflengthdelayed_readoutoffsettokenokeyskeylvaluesfsample_buffnews                                    J/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/dask/bytes/core.py
read_bytesrK      s   D gT5"++>?MNN,W4QWXB%
5zQ/'9::i%#I.I)$:;;	N	3%#e*$6(SZ' *	'Dg%(." 2  774=(D| E 
 r"r" )#y(8!%):!;J!*Jc Ulj1n%99Z'EJJs5z*MM#b'CG"34 Ulj1n%99 dSWn-CF1INIs#v&U*	'X /0L
C #E7G < ff9dBGGDM;PVW39:a+aS%):: !v6	
 	
 3 T{;!	
 	
 	

6 T>Ffc" (Fb%(< 	% ffVn&&.C C''#))Iq*A!*DDyP $ "-"3K  %!	%" sE!!3;K ;	
"	% 	%s   M
%$M
A#MMc                    t        j                   |       5 }|dk(  r||j                         cd d d        S t        ||||      cd d d        S # 1 sw Y   y xY w)Nr   )copyr*   r   )	lazy_filer<   bsr-   rG   s        rJ   r'   r'      sS    	9	 1!8
6681 1 !S"i01 1 1s   AAA)NFz128 MiBr   NF)
__future__r   rM   r   fsspec.corer   r   fsspec.utilsr   r   	dask.baser   dask.delayedr	   
dask.utilsr
   r   rK   r'        rJ   <module>rX      s=    "  	 4 6    .
 m`1rW   