o
    �?ƒZ  ã                   @   sž   d dl mZ d dlZd dlmZmZmZmZmZ d dl	m
Z
 d dlmZmZ d dlmZmZmZ G dd„ de
ƒZG d	d
„ d
e
ƒZdd„ Zdd„ Zddd„ZdS )é    )Úabsolute_importN)ÚStringÚSetÚNoneSetÚAliasÚSequence)ÚSerialisable)ÚREL_NSÚ
PKG_REL_NS)ÚElementÚ
fromstringÚtostringc                   @   sX   e Zd ZdZd Zeƒ Zeƒ ZedƒZ	edd�Z
edd�ZedƒZ					d	dd„ZdS )
ÚRelationshipz'Represents many kinds of relationships.ÚTargetT)Ú
allow_noneÚIdNc                 C   s0   |dur
d  t|¡}|| _|| _|| _|| _dS )z—
        `type` can be used as a shorthand with the default relationships namespace
        otherwise the `Type` must be a fully qualified URL
        Nz{0}/{1})Úformatr	   ÚTyper   Ú
TargetModer   )Úselfr   r   Útyper   r   © r   úQ/var/www/html/env/lib/python3.10/site-packages/openpyxl/packaging/relationship.pyÚ__init__$   s   
zRelationship.__init__)NNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Útagnamer   r   r   r   Útargetr   r   Úidr   r   r   r   r   r      s    

ûr   c                   @   sT   e Zd ZdZee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 )ÚRelationshipListÚRelationships)Úexpected_typer   c                 C   s
   || _ d S ©N)r   )r   r   r   r   r   r   >   ó   
zRelationshipList.__init__c                 C   s8   | j d d … }| |¡ |jsd t|ƒ¡|_|| _ d S )NúrId{0})r   Úappendr   r   Úlen)r   ÚvalueÚvaluesr   r   r   r'   B   s
   

zRelationshipList.appendc                 C   ó
   t | jƒS r$   )r(   r   ©r   r   r   r   Ú__len__J   r%   zRelationshipList.__len__c                 C   r+   r$   )Úboolr   r,   r   r   r   Ú__bool__N   r%   zRelationshipList.__bool__c                 c   s"   � | j D ]
}|j|kr|V  qdS )z«
        Find relationships by content-type
        NB. these content-types namespaced objects and different to the MIME-types
        in the package manifest :-(
        N)r   r   )r   Úcontent_typeÚrr   r   r   ÚfindR   s   €

€þzRelationshipList.findc                 C   s,   | j D ]}|j|kr|  S qtd |¡ƒ‚)NzUnknown relationship: {0})r   r   ÚKeyErrorr   )r   Úkeyr1   r   r   r   Ú__getitem__]   s
   

ÿzRelationshipList.__getitem__c                 C   sF   t dtd�}t| jdƒD ]\}}|jsd |¡|_| | ¡ ¡ q|S )Nr"   )Úxmlnsé   r&   )r   r
   Ú	enumerater   r   r   r'   Úto_tree)r   ÚtreeÚidxÚrelr   r   r   r9   d   s   zRelationshipList.to_treeN)r   )r   r   r   r   r   r   r   r'   r-   r/   r2   r5   r9   r   r   r   r   r!   7   s    

r!   c                 C   s&   t  | ¡\}}t  |dd |¡¡}|S )z±
    Convert relative path to absolutes that can be loaded from a zip
    archive.
    The path to be passed in is that of containing object (workbook,
    worksheet, etc.)
    Ú_relsz{0}.rels)Ú	posixpathÚsplitÚjoinr   )ÚpathÚfolderÚobjÚfilenamer   r   r   Úget_rels_pathn   s   rE   c           	      C   sˆ   |   |¡}t|ƒ}t |¡}t |¡}t |¡d }|jD ]$}|jdkr%q|j	 
d¡r4|j	dd… |_	qt ||j	¡}t |¡|_	q|S )zl
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    r   ÚExternalú/r7   N)Úreadr   r!   Ú	from_treer>   Údirnamer?   r   r   r   Ú
startswithr@   Únormpath)	ÚarchiverD   ÚsrcÚnodeÚrelsrB   Úparentr1   Úpthr   r   r   Úget_dependentsz   s   




rS   c           
      C   sŽ   t ||gƒs
tdƒ‚|dur|| }nt| |j¡ƒ}|j}|  |¡}t|ƒ}| |¡}t	|ƒ}	z	t
| |	ƒ|_W |S  tyF   g |_Y |S w )z4
    Get related object based on id or rel_type
    z.Either the id or the content type are requiredN)ÚanyÚ
ValueErrorÚnextr2   Úrel_typer   rH   r   rI   rE   rS   Údepsr3   )
rM   rX   r    Úclsr<   rA   rN   r:   rC   Ú	rels_pathr   r   r   Úget_rel�   s"   


ýýr[   )NN)Ú
__future__r   r>   Úopenpyxl.descriptorsr   r   r   r   r   Ú!openpyxl.descriptors.serialisabler   Úopenpyxl.xml.constantsr	   r
   Úopenpyxl.xml.functionsr   r   r   r   r!   rE   rS   r[   r   r   r   r   Ú<module>   s     7