Ë
    \Rðià  ã                  ó|   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 erddl
mZ  G d„ deedf   «      Z G d	„ d«      Zy
)zRelationship-related objects.é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚDictÚcast)ÚCT_Relationships)ÚPartc                  ó°   ‡ — e Zd ZdZdˆ fd„Z	 d	 	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Zdd„Ze	d„ «       Z
e	dd„«       Z	 d	 	 	 	 	 	 	 dd	„Zdd
„Ze	dd„«       Zˆ xZS )ÚRelationshipszGCollection object for |_Relationship| instances, having list semantics.c                óF   •— t         t        | �  «        || _        i | _        y ©N)Úsuperr   Ú__init__Ú_baseURIÚ_target_parts_by_rId)ÚselfÚbaseURIÚ	__class__s     €úG/var/www/html/Extract/venv/lib/python3.12/site-packages/docx/opc/rel.pyr   zRelationships.__init__   s   ø€ ÜŒm˜TÑ+Ô-ØˆŒØ46ˆÕ!ó    c                ód   — t        |||| j                  |«      }|| |<   |s|| j                  |<   |S )z.Return a newly added |_Relationship| instance.)Ú_Relationshipr   r   )r   ÚreltypeÚtargetÚrIdÚis_externalÚrels         r   Úadd_relationshipzRelationships.add_relationship   s;   € ô ˜C ¨&°$·-±-ÀÓMˆØˆˆS‰	ÙØ-3ˆD×%Ñ% cÑ*Øˆ
r   c                ól   — | j                  ||«      }|€| j                  }| j                  |||«      }|S )zlReturn relationship of `reltype` to `target_part`, newly added if not already
        present in collection.)Ú_get_matchingÚ	_next_rIdr   )r   r   Útarget_partr   r   s        r   Ú
get_or_addzRelationships.get_or_add   s=   € ð × Ñ  ¨+Ó6ˆØˆ;Ø—.‘.ˆCØ×'Ñ'¨°¸cÓBˆCØˆ
r   c                óˆ   — | j                  ||d¬«      }|€!| j                  }| j                  |||d¬«      }|j                  S )z{Return rId of external relationship of `reltype` to `target_ref`, newly added
        if not already present in collection.T)r   )r    r!   r   r   )r   r   Ú
target_refr   r   s        r   Úget_or_add_ext_relz Relationships.get_or_add_ext_rel(   sK   € ð × Ñ  ¨*À$Ð ÓGˆØˆ;Ø—.‘.ˆCØ×'Ñ'¨°¸SÈdÐ'ÓSˆCØ�w‰wˆr   c                ó<   — | j                  |«      }|j                  S )zœReturn target part of rel with matching `reltype`, raising |KeyError| if not
        found and |ValueError| if more than one matching relationship is found.)Ú_get_rel_of_typer"   )r   r   r   s      r   Úpart_with_reltypezRelationships.part_with_reltype1   s   € ð ×#Ñ# GÓ,ˆØ�‰Ðr   c                ó   — | j                   S )z_Dict mapping rIds to target parts for all the internal relationships in the
        collection.)r   ©r   s    r   Úrelated_partszRelationships.related_parts7   s   € ð ×(Ñ(Ð(r   c                óä   — t        j                  «       }| j                  «       D ]>  }|j                  |j                  |j
                  |j                  |j                  «       Œ@ |j                  S )zoSerialize this relationship collection into XML suitable for storage as a
        .rels file in an OPC package.)	r   ÚnewÚvaluesÚadd_relr   r   r%   r   Úxml)r   Úrels_elmr   s      r   r1   zRelationships.xml=   sW   € ô $×'Ñ'Ó)ˆØ—;‘;“=ò 	TˆCØ×Ñ˜SŸW™W c§k¡k°3·>±>À3Ç?Á?ÕSð	Tà�|‰|Ðr   c                óT   — dd„}| j                  «       D ]  } |||||«      sŒ|c S  y)zuReturn relationship of matching `reltype`, `target`, and `is_external` from
        collection, or None if not found.c                ó”   — | j                   |k7  ry| j                  |k7  ry| j                  r| j                  n| j                  }||k(  S )NF)r   r   r%   r"   )r   r   r   r   Ú
rel_targets        r   Úmatchesz,Relationships._get_matching.<locals>.matchesL   s@   € Ø�{‰{˜gÒ%ØØ�‰ +Ò-ØØ+.¯?ª?˜ŸšÀÇÁˆJØ Ñ'Ð'r   N)r   r   r   Ústrr   ú
Part | strr   Úbool)r/   )r   r   r   r   r6   r   s         r   r    zRelationships._get_matchingF   s6   € ó	(ð —;‘;“=ò 	ˆCÙ�s˜G V¨[Õ9Ø’
ð	ð r   c                óè   — | j                  «       D �cg c]  }|j                  |k(  sŒ|‘Œ }}t        |«      dk(  rd}t        ||z  «      ‚t        |«      dkD  rd}t	        ||z  «      ‚|d   S c c}w )zØReturn single relationship of type `reltype` from the collection.

        Raises |KeyError| if no matching relationship is found. Raises |ValueError| if
        more than one matching relationship is found.
        r   z*no relationship of type '%s' in collectioné   z1multiple relationships of type '%s' in collection)r/   r   ÚlenÚKeyErrorÚ
ValueError)r   r   r   ÚmatchingÚtmpls        r   r(   zRelationships._get_rel_of_typeY   sx   € ð $(§;¡;£=ÖK˜C°C·K±KÀ7Ó4J’CÐKˆÐKÜˆx‹=˜AÒØ?ˆDÜ˜4 '™>Ó*Ð*Üˆx‹=˜1ÒØFˆDÜ˜T G™^Ó,Ð,Ø˜‰{Ðùò Ls
   “A/¨A/c                óX   — t        dt        | «      dz   «      D ]  }d|z  }|| vsŒ|c S  y)zŽNext available rId in collection, starting from 'rId1' and making use of any
        gaps in numbering, e.g. 'rId2' for rIds ['rId1', 'rId3'].r;   é   zrId%dN)Úranger<   )r   ÚnÚrId_candidates      r   r!   zRelationships._next_rIdh   s9   € ô �qœ#˜d›) a™-Ó(ò 	%ˆAØ# a™KˆMØ DÒ(Ø$Ò$ñ	%r   )r   r7   ©F)
r   r7   r   r8   r   r7   r   r9   Úreturnz'_Relationship')r   r7   r"   r	   rG   r   )r   r7   r%   r7   rG   r7   )r   r7   rG   r	   ©rG   r7   )r   r7   r   r8   r   r9   rG   z_Relationship | None)r   r7   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   r&   r)   Úpropertyr,   r1   r    r(   r!   Ú__classcell__©r   s   @r   r   r      s»   ø„ ÙQõ7ð OTðØðØ$.ðØ58ðØGKðà	óóóóð ñ)ó ð)ð
 òó ðð EJðØðØ$.ðØ=Aðà	óó&ð ò%ó ô%r   r   r   c                  ó”   ‡ — e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 d	ˆ fd„Zed
d„«       Zedd„«       Zedd„«       Zedd„«       Z	edd„«       Z
ˆ xZS )r   z&Value object for relationship to part.c                ó‚   •— t         t        | �  «        || _        || _        || _        || _        t        |«      | _        y r   )	r   r   r   Ú_rIdÚ_reltypeÚ_targetr   r9   Ú_is_external)r   r   r   r   r   Úexternalr   s         €r   r   z_Relationship.__init__u   s:   ø€ ô 	Œm˜TÑ+Ô-ØˆŒ	ØˆŒØˆŒØˆŒÜ  ›NˆÕr   c                ó   — | j                   S r   )rU   r+   s    r   r   z_Relationship.is_external   s   € à× Ñ Ð r   c                ó   — | j                   S r   )rS   r+   s    r   r   z_Relationship.reltypeƒ   s   € à�}‰}Ðr   c                ó   — | j                   S r   )rR   r+   s    r   r   z_Relationship.rId‡   s   € à�y‰yÐr   c                ó\   — | j                   rt        d«      ‚t        d| j                  «      S )NzOtarget_part property on _Relationship is undefined when target mode is Externalr	   )rU   r>   r   rT   r+   s    r   r"   z_Relationship.target_part‹   s.   € à×ÒÜØaóð ô �F˜DŸL™LÓ)Ð)r   c                óÄ   — | j                   rt        t        | j                  «      S t        d| j                  «      }|j                  j                  | j                  «      S )Nr	   )rU   r   r7   rT   ÚpartnameÚrelative_refr   )r   r   s     r   r%   z_Relationship.target_ref“   sE   € à×ÒÜœ˜TŸ\™\Ó*Ð*ä˜& $§,¡,Ó/ˆFØ—?‘?×/Ñ/°·±Ó>Ð>r   rF   )
r   r7   r   r7   r   r8   r   r7   rV   r9   )rG   r9   rH   )rG   r	   )rI   rJ   rK   rL   r   rM   r   r   r   r"   r%   rN   rO   s   @r   r   r   r   sž   ø„ Ù0ð Z_ð+Øð+Ø!$ð+Ø.8ð+ØCFð+ØRVõ+ð ò!ó ð!ð òó ðð òó ðð ò*ó ð*ð ò?ó ô?r   N)rL   Ú
__future__r   Útypingr   r   r   r   Údocx.opc.oxmlr   Údocx.opc.partr	   r7   r   r   © r   r   ú<module>rc      s=   ðÙ #å "ç 1Ó 1å *áÝ"ôb%�D˜˜oÐ-Ñ.ô b%÷J'?ò '?r   