HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/__pycache__/rel.cpython-310.pyc
o

$weu�@sVdZddlmZddlmZmZddlmZGdd�deedf�Z	Gdd�d�Z
d	S)
zRelationship-related objects.�)�annotations)�Any�Dict)�CT_Relationshipscs~eZdZdZd!�fdd�Z	d"d#dd�Zdd�Zdd�Zdd�Ze	dd��Z
e	dd��Zd"dd�Zdd�Z
e	dd ��Z�ZS)$�
RelationshipszGCollection object for |_Relationship| instances, having list semantics.�baseURI�strcstt|���||_i|_dS�N)�superr�__init__�_baseURI�_target_parts_by_rId)�selfr��	__class__��E/home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/rel.pyr
s
zRelationships.__init__F�reltype�target�	str | Any�rId�is_external�bool�return�'_Relationship'cCs,t||||j|�}|||<|s||j|<|S)z.Return a newly added |_Relationship| instance.)�
_Relationshiprr
)rrrrr�relrrr�add_relationships

zRelationships.add_relationshipcCs,|�||�}|dur|j}|�|||�}|S)zlReturn relationship of `reltype` to `target_part`, newly added if not already
        present in collection.N)�
_get_matching�	_next_rIdr)rr�target_partrrrrr�
get_or_adds
zRelationships.get_or_addcCs6|j||dd�}|dur|j}|j|||dd�}|jS)z{Return rId of external relationship of `reltype` to `target_ref`, newly added
        if not already present in collection.T)rN)rrrr)rr�
target_refrrrrr�get_or_add_ext_rel%s
z Relationships.get_or_add_ext_relcCs|�|�}|jS)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 )rrrrrr�part_with_reltype.s
zRelationships.part_with_reltypecC�|jS)z_Dict mapping rIds to target parts for all the internal relationships in the
        collection.)r
�rrrr�
related_parts4szRelationships.related_partscCs4t��}|��D]}|�|j|j|j|j�q|jS)zoSerialize this relationship collection into XML suitable for storage as a
        .rels file in an OPC package.)	r�new�values�add_relrrr"r�xml)r�rels_elmrrrrr,:szRelationships.xmlcCs0dd�}|��D]
}|||||�r|SqdS)zuReturn relationship of matching `reltype`, `target`, and `is_external` from
        collection, or None if not found.cSs>|j|krdS|j|krdS|jr|jn|j}||krdSdS)NFT)rrr"r )rrrr�
rel_targetrrr�matchesGs

z,Relationships._get_matching.<locals>.matchesN)r*)rrrrr/rrrrrCs
�zRelationships._get_matchingcsV�fdd�|��D�}t|�dkrd}t|���t|�dkr'd}t|���|dS)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.
        csg|]	}|j�kr|�qSr�r)�.0rr0rr�
<listcomp>\sz2Relationships._get_rel_of_type.<locals>.<listcomp>rz*no relationship of type '%s' in collection�z1multiple relationships of type '%s' in collection)r*�len�KeyError�
ValueError)rr�matching�tmplrr0rr$VszRelationships._get_rel_of_typecCs4tdt|�d�D]}d|}||vr|Sq	dS)z�Next available rId in collection, starting from 'rId1' and making use of any
        gaps in numbering, e.g. 'rId2' for rIds ['rId1', 'rId3'].r3�zrId%dN)�ranger4)r�n�
rId_candidaterrrres��zRelationships._next_rId)rr�F)
rrrrrrrrrr)�__name__�
__module__�__qualname__�__doc__rrr!r#r%�propertyr(r,rr$r�
__classcell__rrrrr
s �
		


rrcsbeZdZdZdd�fdd�
Zedd��Zed	d
��Zedd��Zed
d��Z	eddd��Z
�ZS)rz&Value object for relationship to part.Frrcs4tt|���||_||_||_||_t|�|_dSr	)	r
rr�_rId�_reltype�_targetrr�_is_external)rrrrr�externalrrrrrsz_Relationship.__init__cCr&r	)rGr'rrrrz�z_Relationship.is_externalcCr&r	)rEr'rrrr~rIz_Relationship.reltypecCr&r	)rDr'rrrr�rIz_Relationship.rIdcCs|jrtd��|jS)NzOtarget_part property on _Relationship is undefined when target mode is External)rGr6rFr'rrrr �s
�z_Relationship.target_partrcCs|jr|jS|jj�|j�Sr	)rGrF�partname�relative_refrr'rrrr"�sz_Relationship.target_refr=)rr)rr)r>r?r@rArrBrrrr r"rCrrrrros



N)rA�
__future__r�typingrr�
docx.opc.oxmlrrrrrrrr�<module>se