3
®ybñ  ã               @   sL   d 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„Z	dd
d„Z
dS )z io on the clipboard é    )ÚStringION)ÚABCDataFrame)Ú
get_optionÚoption_contextú\s+c             K   sZ  |j ddƒ}|dk	r0|jƒ jddƒdkr0tdƒ‚dd	lm} dd
lm} |ƒ }y|j|j	dƒpdt
dƒƒ}W n tk
r~   Y nX |dd… jdƒdd… dd… }dd„ |D ƒ}t|ƒdkrØt|ƒdkrØ|j ƒ dkrØd} | dkrò|j	dƒdkròd} t| ƒdk�r|j	dƒdk�rd|d< n(t| ƒdk�rB|j	dƒdk�rBtj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.
    Úencodingzutf-8Nú-Ú Úutf8z3reading from clipboard only supports utf-8 encodingr   )Úclipboard_get)Úread_csvzdisplay.encodingi'  Ú
é   é
   c             S   s   h | ]}|j ƒ jd ƒ’qS )ú	)ÚlstripÚcount)Ú.0Úx© r   ú8/tmp/pip-install-4cy230dp/pandas/pandas/io/clipboards.pyú	<setcomp>:   s    z!read_clipboard.<locals>.<setcomp>r   Zdelim_whitespacez\s+ZengineÚpythonÚczHread_clipboard with regex separator does not work properly with c engineÚsepéÿÿÿÿ)ÚpopÚlowerÚreplaceÚNotImplementedErrorÚpandas.io.clipboardr   Zpandas.io.parsersr   ÚdecodeÚgetr   ÚAttributeErrorÚsplitÚlenÚwarningsÚwarnr   )r   Úkwargsr   r   r   ÚtextÚlinesÚcountsr   r   r   Úread_clipboard
   s,    "$
r,   Tc       	      K   s   |j ddƒ}|dk	r0|jƒ jddƒdkr0tdƒ‚dd	lm} |dkrHd
}|r¬y>|dkrZd}tƒ }| j|f|ddœ|—Ž |jƒ }||ƒ dS  t	k
r¨   t
jdƒ Y q¾X n|dk	r¾t
jdƒ t| tƒrìtddƒ� | jf |Ž}W dQ R X 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 : boolean, 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   zutf-8Nr   r	   r
   z&clipboard only supports utf-8 encodingr   )Úclipboard_setTr   )r   r   zAto_clipboard in excel mode requires a single character separator.z6to_clipboard with excel=False ignores the sep argumentzdisplay.max_colwidth)r   r   r   Ú
ValueErrorr    r-   r   Zto_csvÚgetvalueÚ	TypeErrorr&   r'   Ú
isinstancer   r   Z	to_stringÚstr)	ÚobjÚexcelr   r(   r   r-   Úbufr)   Zobjstrr   r   r   Úto_clipboardN   s2    

r6   )r   )TN)Ú__doc__Úior   r&   Zpandas.core.dtypes.genericr   Zpandasr   r   r,   r6   r   r   r   r   Ú<module>   s   
D