o
    i5                     @  sj   d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZmZ ddddZ	ddddZdS )z io on the clipboard     )annotations)StringION)find_stack_level)ABCDataFrame)
get_optionoption_context\s+sepstrc           	      K  s  | dd}|dur| dddkrtddd	lm} dd
lm} | }z||	dp2t
d}W n	 ty>   Y nw |dd ddd dd }dd |D }t|dkrt|dkr|  dkrd} t|d t|d d }|dkr|dtt| | du r|	ddu rd} t| dkr|	ddu rd|d< nt| dkr|	ddkrtjdt d |t|fd| i|S )aj  
    Read text from clipboard and pass to read_csv.

    Parameters
    ----------
    sep : str, default '\s+'
        A string or regex delimiter. The default of '\s+' denotes
        one or more whitespace characters.

    **kwargs
        See read_csv for the full argument list.

    Returns
    -------
    DataFrame
        A parsed DataFrame object.
    encodingutf-8N- utf8z3reading from clipboard only supports utf-8 encodingr   )clipboard_get)read_csvzdisplay.encodingi'  

   c                 S  s   h | ]
}| d dqS ) 	)lstripcount).0x r   O/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/pandas/io/clipboards.py	<setcomp>A   s    z!read_clipboard.<locals>.<setcomp>   r   z 		index_coldelim_whitespacer   enginepythonczIread_clipboard with regex separator does not work properly with c engine.
stacklevelr	   )poplowerreplaceNotImplementedErrorpandas.io.clipboardr   pandas.io.parsersr   decodegetr   AttributeErrorsplitlenr   
setdefaultlistrangewarningswarnr   r   )	r	   kwargsr   r   r   textlinescountsindex_lengthr   r   r   read_clipboard   s8   "$
r;   Texcelbool | None
str | NonereturnNonec           	      K  s"  | dd}|dur| dddkrtddd	lm} |du r$d
}|rXz |du r-d}t }| j|f|dd| | }|| W dS  t	yW   t
jdt d Y nw |durdt
jdt d t| trtdd | jdi |}W d   n1 sw   Y  nt| }|| dS )a  
    Attempt to write text representation of object to the system clipboard
    The clipboard can be then pasted into Excel for example.

    Parameters
    ----------
    obj : the object to write to the clipboard
    excel : bool, defaults to True
            if True, use the provided separator, writing in a csv
            format for allowing easy pasting into excel.
            if False, write a string representation of the object
            to the clipboard
    sep : optional, defaults to tab
    other keywords are passed to to_csv

    Notes
    -----
    Requirements for your platform
      - Linux: xclip, or xsel (with PyQt4 modules)
      - Windows:
      - OS X:
    r   r   Nr   r   r   z&clipboard only supports utf-8 encodingr   )clipboard_setTr   )r	   r   zAto_clipboard in excel mode requires a single character separator.r$   z7to_clipboard with excel=False ignores the sep argument.zdisplay.max_colwidthr   )r&   r'   r(   
ValueErrorr*   rA   r   to_csvgetvalue	TypeErrorr4   r5   r   
isinstancer   r   	to_stringr
   )	objr<   r	   r6   r   rA   bufr7   objstrr   r   r   to_clipboard[   sB   

rK   )r   )r	   r
   )TN)r<   r=   r	   r>   r?   r@   )__doc__
__future__r   ior   r4   pandas.util._exceptionsr   pandas.core.dtypes.genericr   pandasr   r   r;   rK   r   r   r   r   <module>   s    K