a
    <ba                     @  sh   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	m
Z
 ddd	d
dZdddddddZdS )z io on the clipboard     )annotations)StringION)ABCDataFrame)
get_optionoption_context\s+str)sepc           	      K  s  | dd}|dur0| dddkr0tddd	lm} dd
lm} | }z||	dpdt
d}W n ty|   Y n0 |dd ddd dd }dd |D }t|dkrt|dkr|  dkrd} t|d t|d d }|dkr|dtt| | du r6|	ddu r6d} t| dkr^|	ddu r^d|d< n(t| dkr|	ddkrt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   d/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/pandas/io/clipboards.py	<setcomp>?       z!read_clipboard.<locals>.<setcomp>   r   z 	Z	index_colZdelim_whitespacer   ZenginepythonczIread_clipboard with regex separator does not work properly with c engine.r	   )poplowerreplaceNotImplementedErrorpandas.io.clipboardr   Zpandas.io.parsersr   decodegetr   AttributeErrorsplitlenr   
setdefaultlistrangewarningswarnr   )	r	   kwargsr
   r   r   textlinescountsZindex_lengthr   r   r   read_clipboard   s4    "*

r4   Tzbool | Nonez
str | NoneNone)excelr	   returnc           	      K  s  | dd}|dur0| dddkr0tddd	lm} |du rHd
}|rz@|du rZd}t }| j|f|dd| | }|| W dS  t	y   t
d Y q0 n|durt
d t| trtdd  | jf i |}W d   n1 s0    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.z7to_clipboard with excel=False ignores the sep argument.zdisplay.max_colwidth)r!   r"   r#   
ValueErrorr%   r8   r   Zto_csvgetvalue	TypeErrorr.   r/   
isinstancer   r   Z	to_stringr   )	objr6   r	   r0   r
   r8   bufr1   Zobjstrr   r   r   to_clipboardX   s4    
0r?   )r   )TN)__doc__
__future__r   ior   r.   Zpandas.core.dtypes.genericr   Zpandasr   r   r4   r?   r   r   r   r   <module>   s   J 