U
    ¾mœdŒž  ã                   @  sà  d Z ddlmZ ddlmZmZ ddlZddlmZ ddl	Z	ddl
Z
ddlZddlmZmZmZmZmZmZ ddlZddlZddlmZ ddlZddlZddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd	l&m'Z'm(Z)m*Z*m+Z+m,Z, ddl-Z-ddl.Z.dd
l/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z> ddl?m@Z@ ddlAmBZB ddlCmDZDmEZEmFZFmGZG ddlHmIZI ddlJmKZK eLe,e* e+ ƒZMeM Nd¡ e Od¡ZPe#de0d�ZQe	jRG dd„ dƒƒZSe	jRG dd„ dee ƒƒZTdddœdd„ZUe%d d d!œd"d#„ƒZVe%ddd!œd$d#„ƒZVd%d%d!œd&d#„ZVdd'd(œd)d*„ZWe%dŠd,dd d-œd.d/„ƒZXe%d‹dddd-œd0d/„ƒZXdŒd2dd%d-œd3d/„ZXd4d5„ ZYd6ddœd7d8„ZZe@eKd9 eKd: d; d<�d�d6d d?d d@ddAœdBdC„ƒZ[d d dDœdEdF„Z\dGdGdGdGdHdIdJdKdLdMœ	Z]eLe] ^¡ ƒZ_d?dNdOœdPdQ„Z`e@eKd: d; dR�d6dSdSdTœdUdV„ƒZadWd'dDœdXdY„Zbe%d+d+d+d+d+dZœd6d dSd?dd[dSd@d\d]œ	d^d_„ƒZce%d+d+d+d+d+d+d`œd6d dSd?ddadSd@dbd]œ	dcd_„ƒZce%d+d+d+d+d+d+d`œd6d dSd?dddSd@ddd]œ	ded_„ƒZce@eKd: df dR�ddd1dgddd`œd6d dSd?dddSd@ddd]œ	dhd_„ƒZcG didj„ djeeƒZdG dkdl„ dledƒZeG dmdn„ dnedƒZfG dodp„ dpƒZgG dqdr„ drƒZhdsddtduœdvdw„Zid6dd!œdxdy„Zjd6d ddzœd{d|„Zke
jld}d~œdd€„ƒZmdŽd�d‚ddƒœd„d…„Znd†dd†d‡œdˆd‰„ZodS )�zCommon IO api utilitiesé    )Úannotations)ÚABCÚabstractmethodN)Údefaultdict)ÚBufferedIOBaseÚBytesIOÚ	RawIOBaseÚStringIOÚ
TextIOBaseÚTextIOWrapper)ÚPath)ÚIOÚAnyÚAnyStrÚDefaultDictÚGenericÚHashableÚLiteralÚMappingÚSequenceÚTypeVarÚcastÚoverload)ÚurljoinÚurlparseÚuses_netlocÚuses_paramsÚuses_relative)Ú
BaseBufferÚCompressionDictÚCompressionOptionsÚFilePathÚ
ReadBufferÚReadCsvBufferÚStorageOptionsÚWriteBuffer)Úget_lzma_file)Úimport_optional_dependency)ÚBZ2File)Údoc)Úfind_stack_level)Úis_boolÚis_file_likeÚ
is_integerÚis_list_like)Ú
MultiIndex)Ú_shared_docsÚ z^[A-Za-z][A-Za-z0-9+\-+.]*://ÚBaseBufferT)Úboundc                   @  s>   e Zd ZU dZded< ded< ded< ded< d	Zd
ed< dS )ÚIOArgsz?
    Return value of io/common.py:_get_filepath_or_buffer.
    ústr | BaseBufferÚfilepath_or_bufferÚstrÚencodingÚmoder   ÚcompressionFÚboolÚshould_closeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r<   © rB   rB   úI/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/pandas/io/common.pyr4   S   s   
r4   c                   @  sn   e Zd ZU dZded< ded< ejed�Zded< d	Z	d
ed< ddœdd„Z
ddœdd„Zdddœdd„ZdS )Ú	IOHandlesau  
    Return value of io/common.py:get_handle

    Can be used as a context manager.

    This is used to easily close created buffers and to handle corner cases when
    TextIOWrapper is inserted.

    handle: The file handle to be used.
    created_handles: All file handles that are created by get_handle
    is_wrapped: Whether a TextIOWrapper needs to be detached.
    z
IO[AnyStr]Úhandler   r:   )Údefault_factoryzlist[IO[bytes] | IO[str]]Úcreated_handlesFr;   Ú
is_wrappedÚNone©Úreturnc                 C  s\   | j r8t| jtƒst‚| j ¡  | j ¡  | j | j¡ | jD ]}| 	¡  q>g | _d| _ dS )zµ
        Close all created buffers.

        Note: If a TextIOWrapper was inserted, it is flushed and detached to
        avoid closing the potentially user-created buffer.
        FN)
rH   Ú
isinstancerE   r   ÚAssertionErrorÚflushÚdetachrG   ÚremoveÚclose)ÚselfrE   rB   rB   rC   rQ   u   s    



zIOHandles.closezIOHandles[AnyStr]c                 C  s   | S ©NrB   ©rR   rB   rB   rC   Ú	__enter__†   s    zIOHandles.__enter__r   )ÚargsrK   c                 G  s   |   ¡  d S rS   )rQ   )rR   rV   rB   rB   rC   Ú__exit__‰   s    zIOHandles.__exit__N)r=   r>   r?   r@   rA   ÚdataclassesÚfieldÚlistrG   rH   rQ   rU   rW   rB   rB   rB   rC   rD   `   s   
rD   Úobjectr;   )ÚurlrK   c                 C  s   t | tƒsdS t| ƒjtkS )zÚ
    Check to see if a URL has a valid protocol.

    Parameters
    ----------
    url : str or unicode

    Returns
    -------
    isurl : bool
        If `url` has a valid protocol return True otherwise False.
    F)rL   r7   Ú	parse_urlÚschemeÚ_VALID_URLS©r\   rB   rB   rC   Úis_url�   s    
ra   r7   )r6   rK   c                 C  s   d S rS   rB   ©r6   rB   rB   rC   Ú_expand_userŸ   s    rc   c                 C  s   d S rS   rB   rb   rB   rB   rC   rc   ¤   s    zstr | BaseBufferTc                 C  s   t | tƒrtj | ¡S | S )a]  
    Return the argument with an initial component of ~ or ~user
    replaced by that user's home directory.

    Parameters
    ----------
    filepath_or_buffer : object to be converted if possible

    Returns
    -------
    expanded_filepath_or_buffer : an expanded filepath or the
                                  input if not expandable
    )rL   r7   ÚosÚpathÚ
expanduserrb   rB   rB   rC   rc   ©   s    
rI   )ÚheaderrK   c                 C  s˜   | d krd S t | ƒr2tt| ƒ} | dk r.tdƒ‚d S t| dd�r|tt| ƒ} ttt | ƒƒs^tdƒ‚tdd„ | D ƒƒrxtdƒ‚d S t	| ƒrŒt
d	ƒ‚tdƒ‚d S )
Nr   zUPassing negative integer to header is invalid. For no header, use header=None insteadF)Z
allow_setsz*header must be integer or list of integersc                 s  s   | ]}|d k V  qdS )r   NrB   )Ú.0ÚirB   rB   rC   Ú	<genexpr>Ì   s     z&validate_header_arg.<locals>.<genexpr>z8cannot specify multi-index header with negative integersz–Passing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names)r-   r   ÚintÚ
ValueErrorr.   r   ÚallÚmapÚanyr+   Ú	TypeError)rg   rB   rB   rC   Úvalidate_header_arg¼   s*    
ÿ
ÿrq   .r!   )r6   Úconvert_file_likerK   c                 C  s   d S rS   rB   ©r6   rr   rB   rB   rC   Ústringify_pathÙ   s    rt   c                 C  s   d S rS   rB   rs   rB   rB   rC   rt   Þ   s    FzFilePath | BaseBufferTc                 C  s2   |st | ƒrtt| ƒS t| tjƒr*|  ¡ } t| ƒS )aó  
    Attempt to convert a path-like object to a string.

    Parameters
    ----------
    filepath_or_buffer : object to be converted

    Returns
    -------
    str_filepath_or_buffer : maybe a string version of the object

    Notes
    -----
    Objects supporting the fspath protocol (python 3.6+) are coerced
    according to its __fspath__ method.

    Any other object is passed through unchanged, which includes bytes,
    strings, buffers, or anything else that's not even path-like.
    )r,   r   r2   rL   rd   ÚPathLikeÚ
__fspath__rc   rs   rB   rB   rC   rt   å   s
    
c                  O  s   ddl }|jj| |ŽS )z`
    Lazy-import wrapper for stdlib urlopen, as that imports a big chunk of
    the stdlib.
    r   N)Úurllib.requestÚrequestÚurlopen)rV   ÚkwargsÚurllibrB   rB   rC   ry     s    ry   zFilePath | BaseBufferc                 C  s$   t | tƒo"tt | ¡ƒo"|  d¡ S )zR
    Returns true if the given URL looks like
    something fsspec can handle
    )zhttp://zhttps://)rL   r7   r;   Ú_RFC_3986_PATTERNÚmatchÚ
startswithr`   rB   rB   rC   Úis_fsspec_url  s
    
ÿ
ýr   Ústorage_optionsÚcompression_optionsr6   )r€   r�   úutf-8Úrr    r$   )r6   r8   r:   r9   r€   rK   c              	   C  sÐ  t | ƒ} t|ƒ\}}t| |ƒ}|rJt| dƒrJd|krJtjdttƒ d� d}t||d�}d|krŠ|dkrŠ|d	krŠtj|› d
|› �t	tƒ d� |}d|kr¦d|kr¦|d7 }t
| tƒ�r.t| ƒ�r.|pÂi }ddl}|jj| |d�}t|ƒ�2}	|	j dd¡}
|
dk�rddi}t|	 ¡ ƒ}W 5 Q R X t|||d|d�S t| ƒ�rXt
| tƒ�sHt‚|  d¡�r`|  dd¡} |  d¡�rx|  dd¡} tdƒ}g }z&tdƒ ddlm}m} ||tg}W n tk
�rÀ   Y nX z$|j | fd|i|�pÚi —Ž  ¡ }W n^ t!|ƒk
�rD   |dk�rddi}nt|ƒ}d|d< |j | fd|i|�p6i —Ž  ¡ }Y nX t|||d|d�S |�rft"dƒ‚t
| tt#t$j$fƒ�r�tt%| ƒ||d|d�S t| dƒ�s¾t| dƒ�s¾dt&| ƒ› �}t"|ƒ‚t| ||d|d�S )a%  
    If the filepath_or_buffer is a url, translate and return the buffer.
    Otherwise passthrough.

    Parameters
    ----------
    filepath_or_buffer : a url, filepath (str, py.path.local or pathlib.Path),
                         or buffer
    {compression_options}

        .. versionchanged:: 1.4.0 Zstandard support.

    encoding : the encoding to use to decode bytes, default is 'utf-8'
    mode : str, optional

    {storage_options}

        .. versionadded:: 1.2.0

    ..versionchange:: 1.2.0

      Returns the dataclass IOArgs.
    ÚwriteÚbzDcompression has no effect when passing a non-binary object as input.)Ú
stacklevelN)ÚmethodÚw)Úbz2Úxz)zutf-16zutf-32z( will not write the byte order mark for Útr   )ÚheaderszContent-EncodingÚgzipr‡   T)r6   r8   r:   r<   r9   zs3a://zs3://zs3n://ÚfsspecZbotocore)ÚClientErrorÚNoCredentialsErrorr9   Zanonz?storage_options passed with file object or non-fsspec file pathFÚreadz)Invalid file path or buffer object type: )'rt   Úget_compression_methodÚinfer_compressionÚhasattrÚwarningsÚwarnÚRuntimeWarningr*   ÚdictÚUnicodeWarningrL   r7   ra   rw   rx   ÚRequestry   rŒ   Úgetr   r‘   r4   r   rM   r~   Úreplacer'   Zbotocore.exceptionsr�   r�   ÚPermissionErrorÚImportErrorÚopenÚtuplerl   ÚbytesÚmmaprc   Útype)r6   r8   r:   r9   r€   Úcompression_methodZfsspec_moder{   Úreq_infoÚreqÚcontent_encodingÚreaderrŽ   Zerr_types_to_retry_with_anonr�   r�   Zfile_objÚmsgrB   rB   rC   Ú_get_filepath_or_buffer  sâ    "
ýÿþýý	

û
 ÿ
ýÿÿÿ

ÿÿÿûÿûÿÿûrª   )re   rK   c                 C  s   ddl m} td|| ƒƒS )z©
    converts an absolute native path to a FILE URL.

    Parameters
    ----------
    path : a path in native format

    Returns
    -------
    a valid FILE URL
    r   )Úpathname2urlzfile:)rw   r«   r   )re   r«   rB   rB   rC   Úfile_path_to_urlÓ  s    r¬   Útarr�   r‰   ÚziprŠ   Úzstd)	ú.tarú.tar.gzú.tar.bz2ú.tar.xzú.gzú.bz2ú.zipú.xzz.zstz"tuple[str | None, CompressionDict])r:   rK   c              
   C  s`   t | tƒrPt| ƒ}z| d¡}W qX tk
rL } ztdƒ|‚W 5 d}~X Y qXX ni }| }||fS )a  
    Simplifies a compression argument to a compression method string and
    a mapping containing additional arguments.

    Parameters
    ----------
    compression : str or mapping
        If string, specifies the compression method. If mapping, value at key
        'method' specifies compression method.

    Returns
    -------
    tuple of ({compression method}, Optional[str]
              {compression arguments}, Dict[str, Any])

    Raises
    ------
    ValueError on mapping missing 'method' key
    r‡   z.If mapping, compression must have key 'method'N)rL   r   r˜   ÚpopÚKeyErrorrl   )r:   Úcompression_argsr¤   ÚerrrB   rB   rC   r’   ó  s    
r’   )r�   ú
str | None)r6   r:   rK   c                 C  s’   |dkrdS |dkrZt | dd�} t| tƒs.dS t ¡ D ]\}}|  ¡  |¡r6|  S q6dS |tkrf|S ddgttƒ }d|› d|› �}t	|ƒ‚dS )a/  
    Get the compression method for filepath_or_buffer. If compression='infer',
    the inferred compression method is returned. Otherwise, the input
    compression method is returned unchanged, unless it's invalid, in which
    case an error is raised.

    Parameters
    ----------
    filepath_or_buffer : str or file handle
        File path or object.
    {compression_options}

        .. versionchanged:: 1.4.0 Zstandard support.

    Returns
    -------
    string or None

    Raises
    ------
    ValueError on invalid compression specified.
    NZinferT)rr   úUnrecognized compression type: z
Valid compression types are )
rt   rL   r7   Úextension_to_compressionÚitemsÚlowerÚendswithÚ_supported_compressionsÚsortedrl   )r6   r:   Ú	extensionZvalidr©   rB   rB   rC   r“     s     

ÿr“   z
Path | strc                 C  s&   t | ƒj}| ¡ s"td|› d�ƒ‚dS )z±
    Check if parent directory of a file exists, raise OSError if it does not

    Parameters
    ----------
    path: Path or str
        Path to check parent directory of
    z1Cannot save file into a non-existent directory: 'ú'N)r   ÚparentÚis_dirÚOSError)re   rÆ   rB   rB   rC   Úcheck_parent_directoryM  s    	
rÉ   )r8   r:   Ú
memory_mapÚerrorsr€   zLiteral[False]zIOHandles[bytes])	Úpath_or_bufr9   r8   r:   rÊ   Úis_textrË   r€   rK   c                C  s   d S rS   rB   ©rÌ   r9   r8   r:   rÊ   rÍ   rË   r€   rB   rB   rC   Ú
get_handle[  s    rÏ   )r8   r:   rÊ   rÍ   rË   r€   zLiteral[True]zIOHandles[str]c                C  s   d S rS   rB   rÎ   rB   rB   rC   rÏ   j  s    z!IOHandles[str] | IOHandles[bytes]c                C  s   d S rS   rB   rÎ   rB   rB   rC   rÏ   y  s    rÌ   Tc                C  s¼  |pd}|pd}t | |ƒr*d|kr*|d7 }t |¡ t|tƒrHt |¡ t| ||||d�}|j}	t|	|ƒ\}	}}
t|	tƒ}t	|j
ƒ}| d¡}d|kr¦|r¦tt|	ƒƒ |�rP|dkrÆ|j dd	¡|_n |dkræd|jkræ| jd7  _|d
k�r2t|	tƒ�rtjf |	|jdœ|—Ž}	ntjf |	|jdœ|—Ž}	�n|dk�rVt|	fd|ji|—Ž}	�nÞ|dk�rÚt|	|jf|Ž}	|	jjdk�r4|
 |	¡ |	j ¡ }t|ƒdk�r²|	j | ¡ ¡}	n$|�sÈtd| › �ƒ‚ntd|› �ƒ‚�nZ|dk�r®| d|j¡ t|	tƒ�rtf d|	i|—Ž}	ntf d|	i|—Ž}	t|	tƒ�s4t‚d|	jjk�r4|
 |	¡ |	j ¡ }t|ƒdk�rˆ|	j |d ¡}|dk	�s‚t‚|}	n$|�sžtd| › �ƒ‚ntd|› �ƒ‚n†|dk�rÈtƒ |	|jƒ}	nl|dk�r"tdƒ}d|jk�rød|j f |Ži}nd|j!f |Ži}|j|	fd|ji|—Ž}	nd|› �}t|ƒ‚t|	tƒ�rDt‚|
 |	¡ nNt|	tƒ�rž|j"�rˆd|jk�rˆt|	|j|j"|d	d�}	nt|	|jƒ}	|
 |	¡ d }|�sÐ|jd!k�rÐt|	t#ƒ�rÐt$|	|j"d"�}	n~|�rN|�sð|�sðt |	|jƒ�rNt%|	d#ƒ�rt%|	d$ƒ�rt%|	d%ƒ�st&|	ƒ}	t'|	|j"|d	d�}	|
 |	¡ t|jtƒ�pJ|j( }d|jk�r|t%|	d&ƒ�s|t)d't*|jƒ› d(�ƒ‚|
 +¡  |j(�rªt|jtƒ�ržt‚|
 |j¡ t,|	|
||j
d)�S )*aŽ  
    Get file handle for given path/buffer and mode.

    Parameters
    ----------
    path_or_buf : str or file handle
        File path or object.
    mode : str
        Mode to open path_or_buf with.
    encoding : str or None
        Encoding to use.
    {compression_options}

        .. versionchanged:: 1.0.0
           May now be a dict with key 'method' as compression mode
           and other keys as compression options if compression
           mode is 'zip'.

        .. versionchanged:: 1.1.0
           Passing compression options as keys in dict is now
           supported for compression modes 'gzip', 'bz2', 'zstd' and 'zip'.

        .. versionchanged:: 1.4.0 Zstandard support.

    memory_map : bool, default False
        See parsers._parser_params for more information. Only used by read_csv.
    is_text : bool, default True
        Whether the type of the content passed to the file/buffer is string or
        bytes. This is not the same as `"b" not in mode`. If a string content is
        passed to a binary file/buffer, a wrapper is inserted.
    errors : str, default 'strict'
        Specifies how encoding and decoding errors are to be handled.
        See the errors argument for :func:`open` for a full list
        of options.
    storage_options: StorageOptions = None
        Passed to _get_filepath_or_buffer

    .. versionchanged:: 1.2.0

    Returns the dataclass IOHandles
    r‚   Ústrictr…   )r8   r:   r9   r€   r‡   rƒ   r¯   r‹   r1   r�   )Úfilenamer9   )Úfileobjr9   r‰   r9   r®   é   zZero files found in ZIP file z9Multiple files found in ZIP file. Only one file per ZIP: r­   ÚnamerÒ   r   Nz Zero files found in TAR archive zDMultiple files found in TAR archive. Only one file per TAR archive: rŠ   Ú	zstandardZdctxZcctxr½   )r8   rË   ÚnewlineFÚrb)r8   ÚreadableÚwritableÚseekabler‘   z1Expected file path name or file-like object, got z type)rE   rG   rH   r:   )-Ú_is_binary_modeÚcodecsÚlookuprL   r7   Úlookup_errorrª   r6   Ú_maybe_memory_mapr˜   r:   r¸   rÉ   r9   rœ   r�   ÚGzipFileÚ_BZ2FileÚ_BytesZipFileÚbufferÚappendÚnamelistÚlenrŸ   rl   Ú
setdefaultÚ_BytesTarFilerM   ÚgetnamesÚextractfiler&   r'   ÚZstdDecompressorZZstdCompressorr8   r
   Ú_BytesIOWrapperr”   Ú
_IOWrapperr   r<   rp   r£   ÚreverserD   )rÌ   r9   r8   r:   rÊ   rÍ   rË   r€   ZioargsrE   ÚhandlesZis_pathrº   Z	zip_namesÚfilesÚfiler¯   Z	open_argsr©   rH   rB   rB   rC   rÏ   ˆ  s>   6


û



þýüû
	
ÿþý

 ÿÿ

ÿ
ÿÿ

ÿ

ÿþý
û	
þÿÿ
ÿÿþýü
ÿÿ÷c                      s8   e Zd ZdZeddœdd„ƒZddœ‡ fdd„Z‡  ZS )Ú_BufferedWriterz�
    Some objects do not support multiple .write() calls (TarFile and ZipFile).
    This wrapper writes to the underlying buffer on close.
    rI   rJ   c                 C  s   d S rS   rB   rT   rB   rB   rC   Úwrite_to_buffer¦  s    z_BufferedWriter.write_to_bufferc              	     sP   | j r
d S |  ¡ r8|  d¡ | j� |  ¡  W 5 Q R X n
| j ¡  tƒ  ¡  d S )Nr   )ÚclosedÚgetvalueÚseekrã   ró   rQ   ÚsuperrT   ©Ú	__class__rB   rC   rQ   ª  s    

z_BufferedWriter.close)r=   r>   r?   r@   r   ró   rQ   Ú__classcell__rB   rB   rø   rC   rò      s   rò   c                      sX   e Zd Zdddddddœ‡ fdd	„Zd
d
dœdd„Zddœdd„Zddœdd„Z‡  ZS )rè   Nrƒ   r¼   zLiteral[('r', 'a', 'w', 'x')]z-ReadBuffer[bytes] | WriteBuffer[bytes] | NonerI   )rÔ   r9   rÒ   Úarchive_namerK   c                   s<   t ƒ  ¡  || _|| _tjjf ||  |¡|dœ|—Ž| _d S )N)rÔ   r9   rÒ   )	r÷   Ú__init__rû   rÔ   ÚtarfileÚTarFilerŸ   Úextend_moderã   )rR   rÔ   r9   rÒ   rû   rz   rø   rB   rC   rü   »  s    
ýüz_BytesTarFile.__init__r7   )r9   rK   c                 C  sP   |  dd¡}|dkr|S | jd k	rLt| jƒj}|dkrL|› d|dd … › �}|S )Nr…   r1   rˆ   )r´   r·   rµ   ú:rÓ   )rœ   rÔ   r   Úsuffix)rR   r9   r  rB   rB   rC   rÿ   Ð  s    
z_BytesTarFile.extend_moderJ   c                 C  sP   | j dkrdS t| j ƒ}|jdkr.| d¡j S |jdkrJ| d¡ d¡j S |j S )z¶
        If an explicit archive_name is not given, we still want the file inside the zip
        file not to be named something.tar, because that causes confusion (GH39465).
        Nr°   r1   )r±   r²   r³   )rÔ   r   r  Úwith_suffix©rR   rÑ   rB   rB   rC   Úinfer_filenameÚ  s    



z_BytesTarFile.infer_filenamec                 C  s>   | j p|  ¡ pd}tj|d�}t|  ¡ ƒ|_| j || ¡ d S )Nr­   ©rÔ   )	rû   r  rý   ÚTarInforæ   rõ   Úsizerã   Úaddfile)rR   rû   ÚtarinforB   rB   rC   ró   é  s    z_BytesTarFile.write_to_buffer)Nrƒ   NN)r=   r>   r?   rü   rÿ   r  ró   rú   rB   rB   rø   rC   rè   º  s       û
rè   c                      sF   e Zd Zddddddœ‡ fdd„Zdd	œd
d„Zdd	œdd„Z‡  ZS )râ   Nz1FilePath | ReadBuffer[bytes] | WriteBuffer[bytes]r7   r¼   rI   )rñ   r9   rû   rK   c                   s@   t ƒ  ¡  | dd¡}|| _| dtj¡ tj||f|Ž| _d S )Nr…   r1   r:   )	r÷   rü   rœ   rû   rç   ÚzipfileÚZIP_DEFLATEDÚZipFilerã   )rR   rñ   r9   rû   rz   rø   rB   rC   rü   ò  s
    
z_BytesZipFile.__init__rJ   c                 C  s@   t | jjtjtfƒr<t| jjƒ}|jdkr6| d¡j	S |j	S dS )z¶
        If an explicit archive_name is not given, we still want the file inside the zip
        file not to be named something.zip, because that causes confusion (GH39465).
        r¶   r1   N)
rL   rã   rÑ   rd   ru   r7   r   r  r  rÔ   r  rB   rB   rC   r    s    
z_BytesZipFile.infer_filenamec                 C  s(   | j p|  ¡ pd}| j ||  ¡ ¡ d S )Nr®   )rû   r  rã   Úwritestrrõ   )rR   rû   rB   rB   rC   ró     s    z_BytesZipFile.write_to_buffer)N)r=   r>   r?   rü   r  ró   rú   rB   rB   rø   rC   râ   ñ  s    ürâ   c                   @  sT   e Zd Zdddœdd„Zddœdd	„Zd
dœdd„Zd
dœdd„Zd
dœdd„ZdS )rí   r   rI   )rã   rK   c                 C  s
   || _ d S rS   )rã   )rR   rã   rB   rB   rC   rü     s    z_IOWrapper.__init__r7   r  c                 C  s   t | j|ƒS rS   ©Úgetattrrã   )rR   rÔ   rB   rB   rC   Ú__getattr__  s    z_IOWrapper.__getattr__r;   rJ   c                 C  s   t | jdƒr| j ¡ S dS )NrØ   T)r”   rã   rØ   rT   rB   rB   rC   rØ   "  s    
z_IOWrapper.readablec                 C  s   t | jdƒr| j ¡ S dS )NrÚ   T)r”   rã   rÚ   rT   rB   rB   rC   rÚ   '  s    
z_IOWrapper.seekablec                 C  s   t | jdƒr| j ¡ S dS )NrÙ   T)r”   rã   rÙ   rT   rB   rB   rC   rÙ   ,  s    
z_IOWrapper.writableN)r=   r>   r?   rü   r  rØ   rÚ   rÙ   rB   rB   rB   rC   rí     s
   rí   c                   @  s@   e Zd Zdddddœdd„Zddœd	d
„Zddddœdd„ZdS )rì   r‚   zStringIO | TextIOBaser7   rI   )rã   r8   rK   c                 C  s   || _ || _d| _d S )Nó    )rã   r8   Úoverflow)rR   rã   r8   rB   rB   rC   rü   5  s    z_BytesIOWrapper.__init__)Úattrc                 C  s   t | j|ƒS rS   r  )rR   r  rB   rB   rC   r  >  s    z_BytesIOWrapper.__getattr__éÿÿÿÿz
int | Noner¡   )ÚnrK   c                 C  st   | j d k	st‚| j  |¡ | j¡}| j| }|d ksH|dk sH|t|ƒkrRd| _|S |d |… }||d … | _|S d S )Nr   r  )rã   rM   r‘   Úencoder8   r  ræ   )rR   r  Ú
bytestringZcombined_bytestringZ	to_returnrB   rB   rC   r‘   A  s    
z_BytesIOWrapper.readN)r‚   )r  )r=   r>   r?   rü   r  r‘   rB   rB   rB   rC   rì   2  s   	rì   r5   z/tuple[str | BaseBuffer, bool, list[BaseBuffer]])rE   rÊ   rK   c              	   C  s–   g }|t | dƒpt| tƒM }|s*| ||fS tt| ƒ} t| tƒrRt| dƒ} | | ¡ zt	t
j
|  ¡ dt
jd�ƒ}W 5 t|ƒD ]} |  ¡  qzX |||gfS )zTry to memory map file/buffer.Úfilenor×   r   )Úaccess)r”   rL   r7   r   r#   rŸ   rä   ÚreversedrQ   rí   r¢   r  ÚACCESS_READ)rE   rÊ   rï   ÚwrappedrB   rB   rC   rß   O  s&    




  ÿÿrß   c              	   C  sH   d}t | ƒ} t| tƒs|S ztj | ¡}W n ttfk
rB   Y nX |S )zTest whether file exists.F)rt   rL   r7   rd   re   Úexistsrp   rl   )r6   r  rB   rB   rC   Úfile_existsq  s    
r  )rE   r9   rK   c                 C  sV   d|ksd|krd|kS t jt jt jf}tt| ƒ|ƒr:dS t| tƒ ƒpTdt| d|ƒkS )z+Whether the handle is opened in binary moder‹   r…   Fr9   )	rÜ   ÚStreamWriterÚStreamReaderÚStreamReaderWriterÚ
issubclassr£   rL   Ú_get_binary_io_classesr  )rE   r9   Ztext_classesrB   rB   rC   rÛ     s    ü  ÿrÛ   ztuple[type, ...]rJ   c               	   C  sH   t tf} tddd�}|dk	rD| ¡  d¡�}| t|ƒf7 } W 5 Q R X | S )z!IO classes that that expect bytesrÕ   Úignore)rË   Nr  )r   r   r'   rë   Ústream_readerr£   )Zbinary_classesr¯   r¨   rB   rB   rC   r#  ”  s    r#  zSequence[Hashable] | MultiIndexzbool | Sequence[int] | None)ÚcolumnsÚ	index_colrK   c                   sD   ˆ dkst ˆ tƒrg ‰ tt| ƒo@t | tƒ o@t‡ fdd„| D ƒƒƒS )a¥  
    Check whether or not the `columns` parameter
    could be converted into a MultiIndex.

    Parameters
    ----------
    columns : array-like
        Object which may or may not be convertible into a MultiIndex
    index_col : None, bool or list, optional
        Column or columns to use as the (possibly hierarchical) index

    Returns
    -------
    bool : Whether or not columns could become a MultiIndex
    Nc                 3  s$   | ]}|t ˆ ƒkrt|tƒV  qd S rS   )rZ   rL   r    )rh   Úc©r'  rB   rC   rj   ¿  s      z+is_potential_multi_index.<locals>.<genexpr>)rL   r;   ræ   r/   rm   )r&  r'  rB   r)  rC   Úis_potential_multi_index¦  s    
ÿýr*  zSequence[Hashable])ÚnamesÚis_potential_multiindexrK   c                 C  s¢   t | ƒ} ttƒ}t| ƒD ]„\}}|| }|dkrˆ|d ||< |rpt|tƒsNt‚|dd… |d › d|› �f }n|› d|› �}|| }q(|| |< |d ||< q| S )a:  
    Rename column names if duplicates exist.

    Currently the renaming is done by appending a period and an autonumeric,
    but a custom pattern may be supported in the future.

    Examples
    --------
    >>> dedup_names(["x", "y", "x", "x"], is_potential_multiindex=False)
    ['x', 'y', 'x.1', 'x.2']
    r   rÓ   Nr  Ú.)rZ   r   rk   Ú	enumeraterL   r    rM   )r+  r,  Úcountsri   ÚcolZ	cur_countrB   rB   rC   Údedup_namesÃ  s    "
r1  ).).)F)r‚   Nrƒ   N)N)pr@   Ú
__future__r   Úabcr   r   rÜ   Úcollectionsr   rX   Ú	functoolsr�   Úior   r   r   r	   r
   r   r¢   rd   Úpathlibr   Úrerý   Útypingr   r   r   r   r   r   r   r   r   r   r   r   Úurllib.parser   r   r]   r   r   r   r•   r
  Zpandas._typingr   r   r    r!   r"   r#   r$   r%   Zpandas.compatr&   Zpandas.compat._optionalr'   Zpandas.compat.compressorsr(   rá   Zpandas.util._decoratorsr)   Zpandas.util._exceptionsr*   Zpandas.core.dtypes.commonr+   r,   r-   r.   Zpandas.core.indexes.apir/   Zpandas.core.shared_docsr0   Úsetr_   ÚdiscardÚcompiler|   r2   Ú	dataclassr4   rD   ra   rc   rq   rt   ry   r   rª   r¬   r¾   ÚvaluesrÂ   r’   r“   rÉ   rÏ   rò   rè   râ   rí   rì   rß   r  rÛ   Ú	lru_cacher#  r*  r1  rB   rB   rB   rC   Ú<module>   sô    8(


, ÿ þ"

þ    û 3÷#6÷$÷$÷$÷$  7$" þ