U
    ±[Öe›  ã                   @   s@   d Z ddlmZ ddlmZ G dd„ deƒZG dd„ deƒZdS )	zÈ
    pyexcel.internal.generators
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Defintion for the sheet and book generators.

    :copyright: (c) 2015-2022 by Onni Software Ltd.
    :license: New BSD License
é    )ÚOrderedDict©ÚSheetIteratorc                   @   s4   e Zd ZdZdd„ Zdd„ Zedd„ ƒZdd	„ Zd
S )ÚSheetStreamað  
    Memory efficient sheet representation

    This class wraps around the data read from pyexcel-io.
    Comparing with :class:`pyexcel.Sheet`, the instance of
    this class does not load all data into memory. Hence
    it performs better when dealing with big data.

    If you would like to do custom rendering for each row
    of the two dimensional data, you would need to
    pass a row formatting/rendering function to the parameter
    "renderer" of pyexcel's signature functions.

    c                 C   s   || _ || _g | _d S ©N)ÚnameÚpayloadZcolnames)Úselfr   r   © r
   ú]/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pyexcel/internal/generators.pyÚ__init__   s    zSheetStream.__init__c                 C   s   | j S )z-
        Simply return the generator
        ©r   ©r	   r
   r
   r   Úto_array#   s    zSheetStream.to_arrayc                 C   s
   t | jƒS )zarray attribute)Úlistr   r   r
   r
   r   Úarray)   s    zSheetStream.arrayc                 C   s   | j S r   r   r   r
   r
   r   Úget_internal_array.   s    zSheetStream.get_internal_arrayN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   r   r
   r
   r
   r   r      s   
r   c                   @   sJ   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dS )Ú
BookStreama*  
    Memory efficient book representation

    Comparing with :class:`pyexcel.Book`, the instace of
    this class uses :class:`pyexcel.generators.SheetStream` as
    its internal repesentation of sheet objects. Because `SheetStream`
    does not read data into memory, it is memory efficient.
    NÚmemoryc                 C   s,   || _ || _g | _|r"|  |¡ ni | _dS )aG  Book constructor

        Selecting a specific book according to filename extension
        :param OrderedDict/dict sheets: a dictionary of data
        :param str filename: the physical file
        :param str path: the relative path or absolute path
        :param set keywords: additional parameters to be passed on
        N)ÚpathÚfilenameÚ
name_arrayÚload_from_sheetsÚsheets)r	   r   r   r   r
   r
   r   r   <   s    	zBookStream.__init__c                 C   st   |dkrdS t ƒ | _| ¡ }t|t ƒs.t|ƒ}|D ],}t||| ƒ}| j ||i¡ || j|< q2t| j ¡ ƒ| _	dS )z…Load content from existing sheets

        :param dict sheets: a dictionary of sheets. Each sheet is
        a list of lists
        N)
r   r   ÚkeysÚ
isinstanceÚsortedr   ÚupdateÚ__dict__r   r   )r	   r   r   r   Úsheetr
   r
   r   r   M   s    
zBookStream.load_from_sheetsc                 C   s   | j S r   )r   r   r
   r
   r   Úsheet_namesc   s    zBookStream.sheet_namesc                 C   s&   t ƒ }| D ]}| |j|ji¡ q
|S )z9
        Get book data structure as a dictionary
        )r   r"   r   r   )r	   Zthe_dictr$   r
   r
   r   Úto_dictf   s    zBookStream.to_dictc                 C   s   t | ƒS r   r   r   r
   r
   r   Ú__iter__o   s    zBookStream.__iter__c                 C   s
   t | jƒS )zReturn the number of sheets)Úlenr   r   r
   r
   r   Únumber_of_sheetsr   s    zBookStream.number_of_sheetsc                 C   s@   t |tƒr.|t| jƒk r<| j| }| j| S n|}| j| S d S r   )r    Úintr(   r   r   )r	   ÚindexZ
sheet_namer
   r
   r   Ú__getitem__v   s    

zBookStream.__getitem__)Nr   N)r   r   r   r   r   r   r%   r&   r'   r)   r,   r
   r
   r
   r   r   2   s   	
	r   N)r   Zpyexcel._compactr   Zpyexcel.internal.commonr   Úobjectr   r   r
   r
   r
   r   Ú<module>   s   	$