o
    w¨Êh�  ã                   @   sl   d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZmZ G dd	„ d	eƒZG d
d„ deƒZdS )zà
    pyexcel_io.fileformat.csvz
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    The lower level csvz file format handler.

    :copyright: (c) 2014-2017 by Onni Software Ltd.
    :license: New BSD License, see LICENSE for more details
é    N)ÚStringIOÚPY2)Ú
BookWriter)ÚDEFAULT_SHEET_NAMEÚFILE_FORMAT_CSVZé   )ÚCSVSheetWriterÚUnicodeWriterc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚCSVZipSheetWriterz handle the zipfile interface c                 K   s(   || _ d|d< tj| ||fi |¤Ž d S )NFÚsingle_sheet_in_book)Úfile_extensionr   Ú__init__)ÚselfÚzipfileÚ	sheetnamer   Úkeywords© r   úI/var/www/html/env/lib/python3.10/site-packages/pyexcel_io/writers/csvz.pyr      s   zCSVZipSheetWriter.__init__c                 C   sP   t ƒ | _trt| jfd| ji| j¤Ž| _d S dd l}|j| jfi | j¤Ž| _d S )NÚencodingr   )r   Úcontentr   r	   Ú	_encodingÚ	_keywordsÚwriterÚcsv)r   Únamer   r   r   r   Úset_sheet_name   s   ÿÿÿz CSVZipSheetWriter.set_sheet_namec                 C   s>   d| j | jf }| j d¡ | j || j ¡ ¡ | j ¡  d S )Nz%s.%sr   )Ú_native_sheetr   r   ÚseekÚ_native_bookÚwritestrÚreadÚclose)r   Ú	file_namer   r   r   r!   &   s   zCSVZipSheetWriter.closeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r!   r   r   r   r   r
      s
    r
   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚCSVZipBookWriterzÄ
    csvz writer

    It is better to store csv files as a csvz as it saves your disk space.
    Pyexcel-io had the facility to unzip it for you or you could use
    any other unzip software.
    c                 C   s   t  | ¡ t| _d | _d S ©N)r   r   r   Ú
_file_typer   ©r   r   r   r   r   6   s   

zCSVZipBookWriter.__init__c                 K   s*   t j| |fi |¤Ž t |dtj¡| _d S )NÚw)r   Úopenr   ÚZipFileÚZIP_DEFLATED)r   r"   r   r   r   r   r,   ;   s   zCSVZipBookWriter.openc                 C   s6   |}|d u rt }t| j|| jd d… fi | j¤Ž}|S )Né   )r   r
   r   r)   r   )r   r   Ú
given_namer   r   r   r   Úcreate_sheet?   s   ÿÿzCSVZipBookWriter.create_sheetc                 C   s   | j  ¡  d S r(   )r   r!   r*   r   r   r   r!   H   s   zCSVZipBookWriter.closeN)r#   r$   r%   r&   r   r,   r1   r!   r   r   r   r   r'   -   s    	r'   )r&   r   Úpyexcel_io._compactr   r   Úpyexcel_io.bookr   Úpyexcel_io.constantsr   r   Úcsvwr   r	   r
   r'   r   r   r   r   Ú<module>   s    	