o
    Q+ iR                     @   sd  d Z ddlmZ ddlmZ ddlm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mZmZ d	d
lmZ G dd deeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ eded ed!ed"ed#e d$iZ!d%d& e!" D Z#G d'd( d(eZ$d)S )*uD   Implementation of custom properties see § 22.3 in the specification    )warn)Strict)Serialisable)Sequence)AliasStringIntegerFloatDateTimeBool)
NestedText)CUSTPROPS_NS	VTYPES_NSCPROPS_FMTID   )NestedDateTimec                   @   s   e Zd ZdZdS )NestedBoolTextzX
    Descriptor for handling nested elements with the value stored in the text part
    N)__name__
__module____qualname____doc__ r   r   e/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/openpyxl/packaging/custom.pyr       s    r   c                       s   e Zd ZdZdZdZeddZee	de
dZeede
dZeede
dZede
dZeede
dZee	ddZe Ze Zdd	edfd
dZedd Zd fdd	Z  ZS )_CustomDocumentPropertyz
    Low-level representation of a Custom Document Property.
    Not used directly
    Must always contain a child element, even if this is empty
    propertyNT
allow_none)expected_typer   	namespace)r   r   )r   r   r   c           	      K   sl   || _ || _|| _d | _|| _| D ]\}}t| || t| d| q| jD ]}||vr3t| |d  q'd S )N_typ)fmtidpidnamer   
linkTargetitemssetattr__elements__)	selfr"   r!   r    r#   kwkver   r   r   __init__=   s   
z _CustomDocumentProperty.__init__c                 C   sD   | j d ur| j S | jD ]}t| |d ur|  S q| jd ur dS d S )Nr#   )r   r&   getattrr#   )r'   ar   r   r   typeQ   s   


z_CustomDocumentProperty.typec                    s6   t | | jd }|d u rt| | jd t jd d d dS )N )tagnameidxr   )r-   r   r%   superto_tree)r'   r1   r2   r   child	__class__r   r   r4   \   s   z_CustomDocumentProperty.to_treeNNN)r   r   r   r   r1   r   r   r"   r   strr   lpwstrinti4floatr8r   filetimer   boolr#   r    r   r!   r   r,   r   r/   r4   __classcell__r   r   r6   r   r   (   s*    



r   c                       sL   e Zd ZdZdZeeedZe	dZ
dddZdd	 Zd fdd	Z  ZS )_CustomDocumentPropertyListzG
    Parses and seriliases property lists but is not used directly
    
Properties)r   r   r   r   c                 C   s
   || _ d S Nr   )r'   r   r   r   r   r,   p      
z$_CustomDocumentPropertyList.__init__c                 C   
   t | jS rD   )lenr   r'   r   r   r   __len__t   rF   z#_CustomDocumentPropertyList.__len__Nc                    s<   t | jdD ]\}}||_qt |||}|dt |S )N   xmlns)	enumerater   r!   r3   r4   setr   )r'   r1   r2   r   ptreer6   r   r   r4   x   s
   z#_CustomDocumentPropertyList.to_tree)r   r8   )r   r   r   r   r1   r   r   r   r   r   ZcustomPropsr,   rJ   r4   rA   r   r   r6   r   rB   d   s    
rB   c                   @   s*   e Zd Ze Zdd Zdd Zdd ZdS )_TypedPropertyc                 C   s   || _ || _d S rD   r"   value)r'   r"   rS   r   r   r   r,      s   
z_TypedProperty.__init__c                 C   s   | j |j ko| j|jkS rD   rR   )r'   otherr   r   r   __eq__   s   z_TypedProperty.__eq__c                 C   s   | j j d| j d| j S )Nz, name=z, value=)r7   r   r"   rS   rI   r   r   r   __repr__   s   z_TypedProperty.__repr__N)r   r   r   r   r"   r,   rU   rV   r   r   r   r   rQ      s
    rQ   c                   @      e Zd Ze ZdS )IntPropertyN)r   r   r   r   rS   r   r   r   r   rX          
rX   c                   @   rW   )FloatPropertyN)r   r   r   r	   rS   r   r   r   r   rZ      rY   rZ   c                   @   s   e Zd ZeddZdS )StringPropertyTr   Nr   r   r   r   rS   r   r   r   r   r[      s    r[   c                   @   rW   )DateTimePropertyN)r   r   r   r
   rS   r   r   r   r   r]      rY   r]   c                   @   rW   )BoolPropertyN)r   r   r   r   rS   r   r   r   r   r^      rY   r^   c                   @   rW   )LinkPropertyNr\   r   r   r   r   r_      rY   r_   r:   r<   r>   r?   r@   r#   c                 C   s   i | ]\}}||qS r   r   ).0r)   r*   r   r   r   
<dictcomp>   s    ra   c                   @   sn   e Zd ZeedZdd Zedd Zdd Z	dd	 Z
d
d Zedd Zdd Zdd Zdd Zdd ZdS )CustomPropertyList)r   c                 C   s
   g | _ d S rD   propsrI   r   r   r   r,      rF   zCustomPropertyList.__init__c                 C   s   t |}g }|jD ]3}|j}t|d}|s td|j  q
t||}|j	}|dur1t
}|j	}||j|d}	||	 q
|  }
||
_|
S )z0
        Create list from OOXML element
        NzUnknown type for rR   )rB   	from_treer   r/   XML_MAPPINGgetr   r"   r-   r#   r_   appendrd   )clsrP   	prop_listrd   propattrtyprS   linkZnew_propZnew_prop_listr   r   r   re      s$   


zCustomPropertyList.from_treec                 C   s.   |j | jv rtd|j  d| j| d S )NProperty with name z already exists)r"   names
ValueErrorrd   rh   )r'   rk   r   r   r   rh      s   zCustomPropertyList.appendc                 C   sp   g }| j D ])}t|jd }|stdtdd|ji||ji}t|t	r)d|_
|| qt|d}| S )NzUnknown adapter for {p}r"   r:   rE   r   )rd   CLASS_MAPPINGrg   r7   	TypeErrorr   r"   rS   
isinstancer_   r   rh   rB   r4   )r'   rd   rO   rl   nprj   r   r   r   r4      s   


zCustomPropertyList.to_treec                 C   rG   rD   )rH   rd   rI   r   r   r   rJ      rF   zCustomPropertyList.__len__c                 C   s   dd | j D S )zList of property namesc                 S   s   g | ]}|j qS r   )r"   )r`   rO   r   r   r   
<listcomp>  s    z,CustomPropertyList.names.<locals>.<listcomp>rc   rI   r   r   r   rp     s   zCustomPropertyList.namesc                 C   s.   | j D ]}|j|kr|  S qtd| d)z&
        Get property by name
        ro   
 not found)rd   r"   KeyError)r'   r"   rO   r   r   r   __getitem__  s
   

zCustomPropertyList.__getitem__c                 C   s@   t | jD ]\}}|j|kr| j|  dS qtd| d)z*
        Delete a propery by name
        Nro   rw   )rM   rd   r"   poprx   )r'   r"   r2   rO   r   r   r   __delitem__  s   
zCustomPropertyList.__delitem__c                 C   s   | j j d| j S )Nz containing )r7   r   rd   rI   r   r   r   rV     s   zCustomPropertyList.__repr__c                 C   rG   rD   )iterrd   rI   r   r   r   __iter__   rF   zCustomPropertyList.__iter__N)r   r   r   r   rQ   rd   r,   classmethodre   rh   r4   rJ   r   rp   ry   r{   rV   r}   r   r   r   r   rb      s    



rb   N)%r   warningsr   Zopenpyxl.descriptorsr   Z!openpyxl.descriptors.serialisabler   Zopenpyxl.descriptors.sequencer   r   r   r   r	   r
   r   Zopenpyxl.descriptors.nestedr   Zopenpyxl.xml.constantsr   r   r   corer   r   r   rB   rQ   rX   rZ   r[   r]   r^   r_   rr   r$   rf   rb   r   r   r   r   <module>   s8    <	