U
    d                     @   s&   d Z ddlZddlZG dd dZdS )z Tablib - YAML Support.
    Nc                   @   sP   e Zd ZdZdZedd Zedd Zedd Zed	d
 Z	edd Z
dS )
YAMLFormatyaml)r   Zymlc                 C   s   t j|jdddddS )z'Returns YAML representation of Dataset.FZorderedNTZdefault_flow_styleZallow_unicoder   Z	safe_dumpZ_package)clsZdataset r   8/tmp/pip-unpacked-wheel-_3ph8cfy/tablib/formats/_yaml.py
export_set   s
    
  zYAMLFormat.export_setc                 C   s   t j|jdddddS )z(Returns YAML representation of Databook.Fr   NTr   r   )r   Zdatabookr   r   r	   export_book   s
    
  zYAMLFormat.export_bookc                 C   s   |   t||_dS )z!Returns dataset from YAML stream.N)wiper   	safe_loaddict)r   Zdset	in_streamr   r   r	   
import_set   s    zYAMLFormat.import_setc                 C   sB   |   t|D ]*}t }|d |_|d |_|| qdS )z"Returns databook from YAML stream.titledataN)r   r   r   tablibZDatasetr   r   Z	add_sheet)r   Zdbookr   Zsheetr   r   r   r	   import_book"   s    

zYAMLFormat.import_bookc              
   C   sX   z*t |}t|tttfr"W dS W dS W n( t jjt jj	t j
jfk
rR   Y dS X dS )z+Returns True if given stream is valid YAML.TFN)r   r   
isinstancelisttupler   parserZParserErrorreaderZReaderErrorscannerZScannerError)r   streamZ_yamlr   r   r	   detect.   s    

zYAMLFormat.detectN)__name__
__module____qualname__r   
extensionsclassmethodr
   r   r   r   r   r   r   r   r	   r   	   s   



r   )__doc__r   r   r   r   r   r   r	   <module>   s   