a
    Sic                     @  s  U d dl mZ d dl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 d dlmZmZ erd dlmZ ee Zedeegef dZi Zded	< d
ddddZdFddddddZdd
dddZdddddZdddddZed dd!d"d#Zed$d$d!d%d#Zeddd!d&d#Zeddd!d'd#Zd(d)d!d*d#Zed+d,d-d.d/Z edd0d-d1d/Z d2d3d-d4d/Z d5d6d7d8d9d:Z!d5d;d<d=d>d?Z"d@dAdAdBdCdDZ#dES )G    )annotations)
TYPE_CHECKINGAnyCallableHashableIterableLiteralMutableMappingSequenceTypeVaroverloadimport_optional_dependency)
is_integeris_list_like)ExcelWriterusecols_func)boundz"MutableMapping[str, ExcelWriter_t]_writersExcelWriter_tNone)klassreturnc                 C  s"   t | std| j}| t|< dS )z
    Add engine to the excel writer registry.io.excel.

    You must use this method to integrate with ``to_excel``.

    Parameters
    ----------
    klass : ExcelWriter
    z&Can only register callables as enginesN)callable
ValueError_enginer   )r   engine_name r   Q/var/www/html/django/DPS/env/lib/python3.9/site-packages/pandas/io/excel/_util.pyregister_writer    s    
r   readerstrzLiteral['reader', 'writer'])extmoder   c                 C  s`   dddddd}dddddd}|dv s,J |dkrTt d	d
d}|rLd	|d< ||  S ||  S dS )a  
    Return the default reader/writer for the given extension.

    Parameters
    ----------
    ext : str
        The excel file extension for which to get the default engine.
    mode : str {'reader', 'writer'}
        Whether to get the default engine for reading or writing.
        Either 'reader' or 'writer'

    Returns
    -------
    str
        The default engine for the extension.
    openpyxlpyxlsbxlrdodf)xlsxZxlsmxlsbxlsodsxlwt)r    writerr-   
xlsxwriterwarn)errorsr(   Nr   )r"   r#   Z_default_readersZ_default_writersr.   r   r   r   get_default_engine0   s&    r1   )r   r   c              
   C  sF   z
t |  W S  ty@ } ztd|  d|W Y d }~n
d }~0 0 d S )NzNo Excel writer '')r   KeyErrorr   )r   errr   r   r   
get_writerZ   s    
r5   int)xr   c                 C  sd   d}|    D ]J}t|}|tdk s4|tdkrBtd|  |d | td d }q|d S )ai  
    Convert Excel column name like 'AB' to 0-based column index.

    Parameters
    ----------
    x : str
        The Excel column name to convert to a 0-based column index.

    Returns
    -------
    num : int
        The column index corresponding to the name.

    Raises
    ------
    ValueError
        Part of the Excel column name was invalid.
    r   AZzInvalid column name:       )upperstripordr   )r7   indexccpr   r   r   
_excel2numa   s    rB   z	list[int])areasr   c                 C  s^   g }|  dD ]J}d|v rJ| d}|tt|d t|d d  q|t| q|S )a  
    Convert comma separated list of column names and ranges to indices.

    Parameters
    ----------
    areas : str
        A string containing a sequence of column ranges (or areas).

    Returns
    -------
    cols : list
        A list of 0-based column indices.

    Examples
    --------
    >>> _range2cols('A:E')
    [0, 1, 2, 3, 4]
    >>> _range2cols('A,C,Z:AB')
    [0, 2, 25, 26, 27]
    ,:r   r;   )splitextendrangerB   append)rC   colsrngZrngsr   r   r   _range2cols   s    
&rL   zstr | list[int])usecolsr   c                 C  s   d S Nr   rM   r   r   r   maybe_convert_usecols   s    rP   z	list[str]c                 C  s   d S rN   r   rO   r   r   r   rP      s    c                 C  s   d S rN   r   rO   r   r   r   rP      s    c                 C  s   d S rN   r   rO   r   r   r   rP      s    z1str | list[int] | list[str] | usecols_func | Nonez+None | list[int] | list[str] | usecols_funcc                 C  s2   | du r| S t | rtdt| tr.t| S | S )a  
    Convert `usecols` into a compatible format for parsing in `parsers.py`.

    Parameters
    ----------
    usecols : object
        The use-columns object to potentially convert.

    Returns
    -------
    converted : object
        The compatible format of `usecols`.
    Nz}Passing an integer for `usecols` is no longer supported.  Please pass in a list of int from 0 to `usecols` inclusive instead.)r   r   
isinstancer!   rL   rO   r   r   r   rP      s    
ztuple[int, int]zLiteral[True])freeze_panesr   c                 C  s   d S rN   r   rR   r   r   r   validate_freeze_panes   s    rT   zLiteral[False]c                 C  s   d S rN   r   rS   r   r   r   rT      s    ztuple[int, int] | Noneboolc                 C  s6   | d ur2t | dkr*tdd | D r*dS tddS )N   c                 s  s   | ]}t |tV  qd S rN   )rQ   r6   ).0itemr   r   r   	<genexpr>   s   z(validate_freeze_panes.<locals>.<genexpr>TzLfreeze_panes must be of form (row, column) where row and column are integersF)lenallr   rS   r   r   r   rT      s    zlist[Hashable]z
list[bool]z!tuple[list[Hashable], list[bool]])rowcontrol_rowr   c                 C  sf   | d }t dt| D ]F}|| s*| | }| | dksB| | du rL|| |< qd||< | | }q| |fS )a  
    Forward fill blank entries in row but only inside the same parent index.

    Used for creating headers in Multiindex.

    Parameters
    ----------
    row : list
        List of items in a single row.
    control_row : list of bool
        Helps to determine if particular column is in same parent index as the
        previous value. Used to stop propagation of empty cells between
        different indexes.

    Returns
    -------
    Returns changed row and control_row
    r   r;    NF)rH   rZ   )r\   r]   lastir   r   r   fill_mi_header   s    

ra   zint | Sequence[int]z&tuple[Hashable | None, list[Hashable]])r\   	index_colr   c                 C  sp   t |r t|tsJ t|}nt|tr.J |}| | }|dkrFdn|}|| d| dg | |d d  fS )a  
    Pop the header name for MultiIndex parsing.

    Parameters
    ----------
    row : list
        The data row to parse for the header name.
    index_col : int, list
        The index columns for our data. Assumed to be non-null.

    Returns
    -------
    header_name : str
        The extracted header name.
    trimmed_row : list
        The original data row with the header name removed.
    r^   Nr;   )r   rQ   r   max)r\   rb   r`   header_namer   r   r   pop_header_name  s    
re   zdict[str, Any] | Nonedict)engine_kwargskwargsr   c                 C  s$   | du ri }n|   }|| |S )a  
    Used to combine two sources of kwargs for the backend engine.

    Use of kwargs is deprecated, this function is solely for use in 1.3 and should
    be removed in 1.4/2.0. Also _base.ExcelWriter.__new__ ensures either engine_kwargs
    or kwargs must be None or empty respectively.

    Parameters
    ----------
    engine_kwargs: dict
        kwargs to be passed through to the engine.
    kwargs: dict
        kwargs to be psased through to the engine (deprecated)

    Returns
    -------
    engine_kwargs combined with kwargs
    N)copyupdate)rg   rh   resultr   r   r   combine_kwargs5  s
    
rl   N)r    )$
__future__r   typingr   r   r   r   r   r   r	   r
   r   r   pandas.compat._optionalr   pandas.core.dtypes.commonr   r   pandas.io.excel._baser   typer   objectr   r   __annotations__r   r1   r5   rB   rL   rP   rT   ra   re   rl   r   r   r   r   <module>   s<   0* !#"