U
    .R”i  ã                   @   sÈ   d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ edd	d
ddddgƒZd e¡Ze d e¡¡ZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )é    )ÚdefaultdictN)ÚSerialisable)ÚAliasÚStringÚIntegerÚBoolÚSequenceÚ
Descriptor)Úsafe_string)Ú	Tokenizer)ÚSHEETRANGE_REZ
Print_AreaZPrint_TitlesZCriteriaZ_FilterDatabaseZExtractZConsolidate_AreaZSheet_Titleú|z^_xlnm\.(?P<name>{0})c                   @   sò   e Zd ZdZeƒ Zedd�Zedd�Zedd�Zedd�Z	edd�Z
edd�Zedd�Zedd�Zedd�Zedd�Zedd�Zedd�Zedd�Zedd�Zeƒ ZedƒZddd„Zedd	„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZdd„ Z dS )ÚDefinedNameÚdefinedNameT)Ú
allow_noneÚ	attr_textNc                 C   sd   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _|| _|| _|| _|| _d S ©N)ÚnameÚcommentÚ
customMenuÚdescriptionÚhelpÚ	statusBarÚlocalSheetIdÚhiddenÚfunctionÚvbProcedureÚxlmÚfunctionGroupIdÚshortcutKeyÚpublishToServerÚworkbookParameterr   )Úselfr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   © r#   úB/tmp/pip-unpacked-wheel-r0v169r1/openpyxl/workbook/defined_name.pyÚ__init__2   s     zDefinedName.__init__c                 C   s.   t d| j ƒ}|jd }|jdkr(|jS |jS )Nú=r   ZOPERAND)r   ÚvalueÚitemsÚtypeÚsubtype)r"   ÚtokÚparsedr#   r#   r$   r)   V   s
    

zDefinedName.typec                 c   sb   | j dkr^td| j ƒ}|jD ]>}|jdkrt |j¡}| d¡pJ| d¡}|| d¡fV  qd S )NÚRANGEr&   Z	notquotedÚquotedÚcells)r)   r   r'   r(   r*   r   ÚmatchÚgroup)r"   r+   ÚpartÚmZ	sheetnamer#   r#   r$   Údestinations_   s    


zDefinedName.destinationsc                 C   s   t  | j¡}|r| d¡S d S )Nr   )ÚRESERVED_REGEXr0   r   r1   )r"   r3   r#   r#   r$   Úis_reservedj   s    zDefinedName.is_reservedc                 C   s   t  d¡ | j¡d k	S )Nz
^\[\d+\].*)ÚreÚcompiler0   r'   ©r"   r#   r#   r$   Úis_externalq   s    zDefinedName.is_externalc                 c   sJ   | j D ]>}|dkrqt| |ƒ}|d k	r|tkr6d| }|t|ƒfV  qd S )Nr   z_xlnm.)Ú	__attrs__ÚgetattrÚRESERVEDr
   )r"   ÚkeyÚvr#   r#   r$   Ú__iter__v   s    

zDefinedName.__iter__)NNNNNNNNNNNNNNNN)!Ú__name__Ú
__module__Ú__qualname__Útagnamer   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r	   r   r   r'   r%   Úpropertyr)   r4   r6   r:   r@   r#   r#   r#   r$   r      sX   













                ð
$




r   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚDefinedNameDictzv
    Utility class for storing defined names.
    Allows access by name and separation of global and scoped names
    c                    s8   t |tƒstdƒ‚n|j|kr&tdƒ‚tƒ  ||¡ d S )Nz*Value must be a an instance of DefinedNamez Key must be the same as the name)Ú
isinstancer   Ú	TypeErrorr   Ú
ValueErrorÚsuperÚ__setitem__)r"   r>   r'   ©Ú	__class__r#   r$   rK   ˆ   s
    


zDefinedNameDict.__setitem__c                 C   s   || |j < dS )zI
        Add names without worrying about key and name matching.
        N)r   )r"   r'   r#   r#   r$   Úadd�   s    zDefinedNameDict.add)rA   rB   rC   Ú__doc__rK   rN   Ú__classcell__r#   r#   rL   r$   rF   �   s   rF   c                   @   s<   e Zd ZdZeed�Zddd„Zdd„ Zdd	„ Z	d
d„ Z
dS )ÚDefinedNameListZdefinedNames)Zexpected_typer#   c                 C   s
   || _ d S r   )r   )r"   r   r#   r#   r$   r%   ž   s    zDefinedNameList.__init__c                 C   sV   t tƒ}| jD ]B}|jdkr8|jdkr(q||d |j< qt|jƒ}||| |j< q|S )z@
        Break names down into sheet locals and globals
        N)z_xlnm.Print_Titlesz_xlnm.Print_Areaz_xlnm._FilterDatabaseÚglobal)r   rF   r   r   r   Úint)r"   ÚnamesÚdefnZsheetr#   r#   r$   Úby_sheet¢   s    



zDefinedNameList.by_sheetc                 C   s.   | j D ]"}|j|jkr|j|jkr dS qdS )zc
        Check for whether DefinedName with the same name and scope already
        exists
        TN)r   r   r   )r"   rU   Údr#   r#   r$   Ú
_duplicate²   s    
zDefinedNameList._duplicatec                 C   s
   t | jƒS r   )Úlenr   r9   r#   r#   r$   Ú__len__¼   s    zDefinedNameList.__len__N)r#   )rA   rB   rC   rD   r   r   r   r%   rV   rX   rZ   r#   r#   r#   r$   rQ   —   s   


rQ   )Úcollectionsr   r7   Z!openpyxl.descriptors.serialisabler   Zopenpyxl.descriptorsr   r   r   r   r   r	   Zopenpyxl.compatr
   Zopenpyxl.formular   Zopenpyxl.utils.cellr   Ú	frozensetr=   ÚjoinZ_namesr8   Úformatr5   r   ÚdictrF   rQ   r#   r#   r#   r$   Ú<module>   s"      þ
f