o
    w¨Êh’  ã                   @   s`   d Z ddlZddlmZmZ ddlmZ ddlmZ ddl	m
Z
mZ G dd	„ d	eƒZd
d„ 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)Ú
BookReader)ÚFILE_FORMAT_CSVZé   )ÚCSVinMemoryReaderÚNamedContentc                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚCSVZipBookReaderzƒcsvz reader

    Read zipped csv file that was zipped up by pyexcel-io. It support
    single csv file and multiple csv files.
    c                 C   s   t  | ¡ t| _d | _d S ©N)r   Ú__init__r   Ú
_file_typeÚzipfile©Úself© r   úI/var/www/html/env/lib/python3.10/site-packages/pyexcel_io/readers/csvz.pyr      s   

zCSVZipBookReader.__init__c                 K   ó&   t j| |fi |¤Ž |  | j¡| _d S r
   )r   ÚopenÚ_load_from_file_alike_objectÚ
_file_nameÚ_native_book)r   Ú	file_nameÚkeywordsr   r   r   r      s   zCSVZipBookReader.openc                 K   r   r
   )r   Úopen_streamr   Ú_file_streamr   )r   Úfile_streamr   r   r   r   r   #   s   
ÿzCSVZipBookReader.open_streamc                 C   sL   | j  |j¡}trt|ƒ}nt| d¡ƒ}tt|j|ƒfi | j	¤Ž}| 
¡ S )Nzutf-8)r   ÚreadÚpayloadr   r   Údecoder   r   ÚnameÚ	_keywordsÚto_array)r   Únative_sheetÚcontentÚsheetÚreaderr   r   r   Ú
read_sheet)   s   

ÿÿzCSVZipBookReader.read_sheetc                 C   s   | j r
| j  ¡  d S d S r
   )r   Úcloser   r   r   r   r'   5   s   ÿzCSVZipBookReader.closec                 C   sD   zt  |d¡| _ dd„ | j  ¡ D ƒ}|W S  t jy!   tdƒ ‚ w )NÚrc                 S   s   g | ]	}t t|ƒ|ƒ‘qS r   )r   Ú_get_sheet_name)Ú.0r   r   r   r   Ú
<listcomp><   s    ÿÿzACSVZipBookReader._load_from_file_alike_object.<locals>.<listcomp>z+StringIO instance was passed by any chance?)r   ÚZipFileÚnamelistÚ
BadZipfileÚprint)r   Úfile_alike_objectÚsheetsr   r   r   r   9   s   þþz-CSVZipBookReader._load_from_file_alike_objectN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r'   r   r   r   r   r   r	      s    r	   c                 C   s$   d}d}t | ƒ| | }| d |… S )Nr   é   )Úlen)ÚfilenameÚlen_of_a_dotÚlen_of_csv_wordÚname_lenr   r   r   r)   G   s   r)   )r5   r   Úpyexcel_io._compactr   r   Úpyexcel_io.bookr   Úpyexcel_io.constantsr   Úcsvrr   r   r	   r)   r   r   r   r   Ú<module>   s    	4