o
    ðäj†  ã                   @   sž   d dl Z d dlmZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ d dl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 )é    N)Úwarn)ÚStringÚAliasÚSequence)ÚSerialisable)ÚElementList)ÚREL_NSÚ
PKG_REL_NS)ÚElementÚ
fromstringc                   @   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   úc/var/www/ticemtrilhas/avaliacao_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                       sH   e Zd ZdZeZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z	‡ fd
d„Z
‡  ZS )ÚRelationshipListÚRelationshipsc                    s*   t ƒ  |¡ |jsdt| ƒ› �|_d S d S )NÚrId)ÚsuperÚappendr   Úlen)r   Úvalue©Ú	__class__r   r   r#   ;   s   ÿzRelationshipList.appendc                 c   s    � | 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   Úcontent_typeÚrr   r   r   ÚfindA   s   €
€þzRelationshipList.findc                 C   s*   | D ]}|j |kr|  S qtd |¡ƒ‚)NzUnknown relationship: {0})r   ÚKeyErrorr   )r   Úkeyr)   r   r   r   ÚgetL   s
   
ÿzRelationshipList.getc                 C   s   dd„ | D ƒS )z,Return a dictionary of relations keyed by idc                 S   s   i | ]}|j |“qS r   )r   )Ú.0r)   r   r   r   Ú
<dictcomp>U   s    z,RelationshipList.to_dict.<locals>.<dictcomp>r   )r   r   r   r   Úto_dictS   s   zRelationshipList.to_dictc                    s   t ƒ  ¡ }| dt¡ |S )NÚxmlns)r"   Úto_treeÚsetr	   )r   Útreer&   r   r   r2   X   s   
zRelationshipList.to_tree)r   r   r   r   r   Úexpected_typer#   r*   r-   r0   r2   Ú__classcell__r   r   r&   r   r   5   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_path^   s   r?   c           
      C   s¶   |   |¡}t|ƒ}zt |¡}W n ty%   d |¡}t|ƒ tƒ }Y nw t |¡}t 	|¡d }|D ]$}|j
dkr<q4|j d¡rK|jdd… |_q4t ||j¡}	t |	¡|_q4|S )zl
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    z+{0} contains invalid dependency definitionsr   ÚExternalú/é   N)Úreadr   r   Ú	from_treeÚ	TypeErrorr   r   r8   Údirnamer9   r   r   Ú
startswithr:   Únormpath)
Úarchiver>   ÚsrcÚnodeÚrelsÚmsgr<   Úparentr)   Úpthr   r   r   Úget_dependentsj   s&   


ý

rP   c           
      C   sª   t ||gƒs
tdƒ‚|dur| |¡}nz
t| |j¡ƒ}W n
 ty(   Y dS w |j}|  |¡}t	|ƒ}| 
|¡}t|ƒ}	z	t| |	ƒ|_W |S  tyT   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Ú
ValueErrorr-   Únextr*   Úrel_typeÚStopIterationr   rC   r   rD   r?   rP   Údepsr+   )
rI   rV   r   ÚclsÚrelr;   rJ   r4   r=   Ú	rels_pathr   r   r   Úget_rel…   s*   ÿ

ýýrZ   )NN)r8   Úwarningsr   Úopenpyxl.descriptorsr   r   r   Ú!openpyxl.descriptors.serialisabler   Úopenpyxl.descriptors.containerr   Úopenpyxl.xml.constantsr   r	   Úopenpyxl.xml.functionsr
   r   r   r   r?   rP   rZ   r   r   r   r   Ú<module>   s    )