
    ~Zinu                       S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
Jr  SSKJr  SSKJr  SSKJrJr  SSKJrJrJr  SS	KJrJr  SS
KJr  SSKJr  SSKJ r   \(       a   SSK!J"r"  SSKJ#r#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*   " S S5      r+ " S S\+5      r, " S S5      r- " S S\+5      r. " S S\.5      r/ " S S5      r0 " S S5      r1 " S  S!\	\2S"4   5      r3 " S# S"5      r4g)$zFundamental Open Packaging Convention (OPC) objects.

The :mod:`pptx.packaging` module coheres around the concerns of reading and writing
presentations to and from a .pptx file.
    )annotationsN)IOTYPE_CHECKINGDefaultDictIteratorMappingSetcast)RELATIONSHIP_TARGET_MODE)RELATIONSHIP_TYPE)CT_Relationshipsserialize_part_xml)CONTENT_TYPES_URIPACKAGE_URIPackURI)PackageReaderPackageWriter)CaseInsensitiveDict)	parse_xml)lazyproperty)Self)CT_RelationshipCT_Types)BaseOxmlElement)Package)PresentationPartc                  X    \ rS rSrSrS
S jrSSS jjrSS jrSS jr\	SS j5       r
Srg	)_RelatableMixin   zHProvide relationship methods required by both the package and each part.c                8    U R                   R                  U5      $ )zReturn (single) part having relationship to this package of `reltype`.

Raises |KeyError| if no such relationship is found and |ValueError| if more than one such
relationship is found.
)_relspart_with_reltype)selfreltypes     j/var/www/eduai.edurigo.com/question_generate/ques_gen_env/lib/python3.13/site-packages/pptx/opc/package.pypart_related_by_RelatableMixin.part_related_by!   s     zz++G44    c                    [        U[        5      (       a$  U(       d   eU R                  R                  X!5      $ U R                  R	                  X!5      $ )zReturn rId key of relationship of `reltype` to `target`.

If such a relationship already exists, its rId is returned. Otherwise the relationship is
added and its new rId returned.
)
isinstancestrr!   get_or_add_ext_rel
get_or_add)r#   targetr$   is_externals       r%   	relate_to_RelatableMixin.relate_to)   sC     fc"";::00AAzz$$W55r(   c                4    U R                   U   R                  $ )z2Return related |Part| subtype identified by `rId`.)r!   target_partr#   rIds     r%   related_part_RelatableMixin.related_part5   s    zz#***r(   c                4    U R                   U   R                  $ )zGReturn URL contained in target ref of relationship identified by `rId`.)r!   
target_refr4   s     r%   r9   _RelatableMixin.target_ref9   s    zz#)))r(   c                D    [        S[        U 5      R                  -  5      e)zJ|_Relationships| object containing relationships from this part to others.z`%s` must implement `.rels`)NotImplementedErrortype__name__r#   s    r%   r!   _RelatableMixin._rels=   s#     ")DJ,?,??
 	
r(    Nr$   r+   returnPartF)r.   
Part | strr$   r+   r/   boolrC   r+   )r5   r+   rC   rD   )r5   r+   rC   r+   rC   _Relationships)r>   
__module____qualname____firstlineno____doc__r&   r0   r6   r9   r   r!   __static_attributes__rA   r(   r%   r   r      s-    R5
6+* 
 
r(   r   c                      \ rS rSrSrSS jr\SS j5       rSS jrSS jr	SS jr
\SS j5       rSS	 jrSS
 jrSS jr\SS j5       rSrg)
OpcPackageE   zMain API class for |python-opc|.

A new instance is constructed by calling the :meth:`open` classmethod with a path to a package
file or file-like object containing a package (.pptx file).
c                    Xl         g N	_pkg_filer#   pkg_files     r%   __init__OpcPackage.__init__L       !r(   c                .    U " U5      R                  5       $ )zGReturn an |OpcPackage| instance loaded with the contents of `pkg_file`._load)clsrW   s     r%   openOpcPackage.openO   s     8}""$$r(   c                :    U R                   R                  U5        g)z(Remove relationship identified by `rId`.Nr!   popr4   s     r%   drop_relOpcPackage.drop_relT   s    

sr(   c              #     #    [        5       nU R                  5        H>  nUR                  (       a  M  UR                  nX1;   a  M)  Uv   UR	                  U5        M@     g7f)z;Generate exactly one reference to each part in the package.N)set	iter_relsr/   r3   add)r#   visitedrelparts       r%   
iter_partsOpcPackage.iter_partsX   sI      U>>#C??DJKK $s   AA c              #  n   ^^#    [        5       mSUU4S jjmT" U R                  5       Sh  vN   g N7f)zuGenerate exactly one reference to each relationship in package.

Performs a depth-first traversal of the rels graph.
c              3     >#    U R                  5        HY  nUv   UR                  (       a  M  UR                  nUT;   a  M.  TR                  U5        T" UR                  5       S h  vN   M[     g  N	7frS   )valuesr/   r3   ri   rels)rr   rk   rl   rj   	walk_relss      r%   rs   'OpcPackage.iter_rels.<locals>.walk_relsk   s]     {{}	?? 7?D!$TYY/// % 0s   A%A4(A2)
A4N)rr   rI   rC   Iterator[_Relationship])rg   r!   )r#   rj   rs   s    @@r%   rh   OpcPackage.iter_relsd   s-     
 !U	0 	0  TZZ(((s   )535c                T    [        SU R                  [        R                  5      5      $ )zzReturn |Part| subtype serving as the main document part for this package.

In this case it will be a |Presentation| part.
r   )r
   r&   RTOFFICE_DOCUMENTr?   s    r%   main_document_partOpcPackage.main_document_part}   s#     &(<(<R=O=O(PQQr(   c                R   USUS-  R                  S5       nU R                  5        Vs1 s H0  o3R                  R                  U5      (       d  M$  UR                  iM2     nn[	        [        U5      S-   SS5       H  nX-  nXd;  d  M  [        U5      s  $    [        S5      es  snf )zReturn |PackURI| next available partname matching `tmpl`.

`tmpl` is a printf (%)-style template string containing a single replacement item, a '%d'
to be used to insert the integer portion of the partname. Example:
'/ppt/slides/slide%d.xml'
N*   42   r   z0ProgrammingError: ran out of candidate_partnames)findrm   partname
startswithrangelenr   	Exception)r#   tmplprefixp	partnamesncandidate_partnames          r%   next_partnameOpcPackage.next_partname   s     .((./)-):\):Ajj>S>STZ>[ZQZZ):	\s9~)1b1A!%!2122 2 JKK ]s   #B$B$c                t    [         R                  " XR                  [        U R	                  5       5      5        g)zjSave this package to `pkg_file`.

`file` can be either a path to a file (a string) or a file-like object.
N)r   writer!   tuplerm   rV   s     r%   saveOpcPackage.save   s$    
 	Hjj%8I2JKr(   c                    [         R                  U R                  [        SU 5      5      u  pU R                  R                  [        X5        U $ )z=Return the package after loading all parts and relationships.r   )_PackageLoaderloadrU   r
   r!   load_from_xmlr   )r#   pkg_xml_relspartss      r%   r]   OpcPackage._load   s<    ,11$..$yRVBWX

  lBr(   c                4    [        [        R                  5      $ )z@|Relationships| object containing relationships of this package.)rI   r   baseURIr?   s    r%   r!   OpcPackage._rels   s     k1122r(   rT   N)rW   str | IO[bytes])rW   r   rC   r   r5   r+   rC   None)rC   zIterator[Part])rC   ru   )rC   r   )r   r+   rC   r   )rW   r   rC   r   )rC   r   rH   )r>   rJ   rK   rL   rM   rX   classmethodr_   rd   rm   rh   propertyrz   r   r   r]   r   r!   rN   rA   r(   r%   rP   rP   E   sj    " % %
)2 R RL$L 3 3r(   rP   c                      \ rS rSrSrSS jr\      SS j5       rSS jr\	SS j5       r
\	SS j5       r\	SS j5       r\	SS	 j5       rSS
 jrSrg)r      z@Function-object that loads a package from disk (or other store).c                    Xl         X l        g rS   )rU   _package)r#   rW   packages      r%   rX   _PackageLoader.__init__   s    !r(   c                .    U " X5      R                  5       $ )a  Return (pkg_xml_rels, parts) pair resulting from loading `pkg_file`.

The returned `parts` value is a {partname: part} mapping with each part in the package
included and constructed complete with its relationships to other parts in the package.

The returned `pkg_xml_rels` value is a `CT_Relationships` object containing the parsed
package relationships. It is the caller's responsibility (the package object) to load
those relationships into its |_Relationships| object.
r\   )r^   rW   r   s      r%   r   _PackageLoader.load   s     8%++--r(   c                    U R                   U R                  p!UR                  5        H  u  p4UR                  X#   U5        M     U[           U4$ )zBReturn (pkg_xml_rels, parts) pair resulting from loading pkg_file.)_parts	_xml_relsitemsload_rels_from_xmlr   )r#   r   xml_relsr   rl   s        r%   r]   _PackageLoader._load   sH    ++t~~x#kkmNH##H$6> , $e++r(   c                N    [         R                  U R                  [           5      $ )z|_ContentTypeMap| object providing content-types for items of this package.

Provides a content-type (MIME-type) for any given partname.
)_ContentTypeMapfrom_xml_package_readerr   r?   s    r%   _content_types_PackageLoader._content_types   s!     ''(<(<=N(OPPr(   c                ,    [        U R                  5      $ )zE|PackageReader| object providing access to package-items in pkg_file.)r   rU   r?   s    r%   r   _PackageLoader._package_reader   s     T^^,,r(   c                    U R                   nU R                  nU R                  nS U R                   5        Vs0 s H  nXC;   d  M
  U[	        UX   UX4   S9_M     sn$ s  snf )a5  dict {partname: Part} populated with parts loading from package.

Among other duties, this collection is passed to each relationships collection so each
relationship can resolve a reference to its target part when required. This reference can
only be reliably carried out once the all parts have been loaded.
c              3  4   #    U  H  oS :w  d  M
  Uv   M     g7f)/NrA   ).0r   s     r%   	<genexpr>(_PackageLoader._parts.<locals>.<genexpr>   s     C1s(QQs   		)blob)r   r   r   r   PartFactory)r#   content_typesr   package_readerr   s        r%   r   _PackageLoader._parts   s     ++---- DC
 D )Hk'#-	  D
 	
 
s   	AAc                |   ^ ^^^ 0 m[        5       mSUU UU4S jjmT" [        T R                  [        5      5        T$ )zdict {partname: xml_rels} for package and all package parts.

This is used as the basis for other loading operations such as loading parts and
populating their relationships.
c                0  > UTU '   TR                  U 5        U R                  nUR                   Hc  nUR                  [        R
                  :X  a  M#  [        R                  " X#R                  5      nUT;   a  MK  T" UTR                  U5      5        Me     g)zAPopulate `xml_rels` dict by traversing relationships depth-first.N)
ri   r   relationship_lst
targetModeRTMEXTERNALr   from_rel_refr9   _xml_rels_for)	source_partnamerr   base_urirk   target_partname	load_relsr#   visited_partnamesr   s	        r%   r   +_PackageLoader._xml_rels.<locals>.load_rels   s    (,H_%!!/2&..H ,,>>S\\1")"6"6x"P"&77/4+=+=o+NO -r(   )r   r   rr   r   )rg   r   r   )r#   r   r   r   s   `@@@r%   r   _PackageLoader._xml_rels   s:     57*-%	P 	P 	+t11+>?r(   c                    U R                   R                  U5      nUc  [        R                  " 5       $ [	        [        [        U5      5      $ )zReturn CT_Relationships object formed by parsing rels XML for `partname`.

A CT_Relationships object is returned in all cases. A part that has no relationships
receives an "empty" CT_Relationships object, i.e. containing no `CT_Relationship` objects.
)r   rels_xml_forr   newr
   r   )r#   r   rels_xmls      r%   r   _PackageLoader._xml_rels_for  sL     ''44X>    "	
 &	((;<	
r(   )r   rU   N)rW   r   r   r   )rW   r   r   r   rC   ,tuple[CT_Relationships, dict[PackURI, Part]])rC   r   )rC   r   )rC   r   )rC   dict[PackURI, Part])rC   zdict[PackURI, CT_Relationships])r   r   rC   r   )r>   rJ   rK   rL   rM   rX   r   r   r]   r   r   r   r   r   r   rN   rA   r(   r%   r   r      s    J  .&.18.	5. ., Q Q - - 
 
0  6
r(   r   c                  &   \ rS rSrSr S       SS jjr\SS j5       r\SS j5       r	\	R                  SS j5       r	\SS j5       rSS	 jr\SS
 j5       r\SS j5       r\R                  SS j5       r\SS j5       rSS jr\SS j5       rSrg)rD   i  zBase class for package parts.

Provides common properties and methods, but intended to be subclassed in client code to
implement specific part behaviors. Also serves as the default class for parts that are not yet
given specific behaviors.
Nc                4    Xl         X l        X0l        X@l        g rS   )	_partname_content_typer   _blob)r#   r   content_typer   r   s        r%   rX   Part.__init__!  s     ")
r(   c                    U " XX45      $ )zReturn `cls` instance loaded from arguments.

This one is a straight pass-through, but subtypes may do some pre-processing, see XmlPart
for an example.
rA   r^   r   r   r   r   s        r%   r   	Part.load*  s     8799r(   c                ,    U R                   =(       d    S$ )zContents of this package part as a sequence of bytes.

Intended to be overridden by subclasses. Default behavior is to return the blob initial
loaded during `Package.open()` operation.
r(   r   r?   s    r%   r   	Part.blob3  s     zz S r(   c                    Xl         g)zNote that not all subclasses use the part blob as their blob source.

In particular, the |XmlPart| subclass uses its `self._element` to serialize a blob on
demand. This works fine for binary parts though.
Nr   )r#   r   s     r%   r   r   <  s	     
r(   c                    U R                   $ )z&Content-type (MIME-type) of this part.)r   r?   s    r%   r   Part.content_typeE  s     !!!r(   c                d    U R                   R                  U R                  R                  X5        g)a4  load _Relationships for this part from `xml_rels`.

Part references are resolved using the `parts` dict that maps each partname to the loaded
part with that partname. These relationships are loaded from a serialized package and so
already have assigned rIds. This method is only used during package loading.
N)r!   r   r   r   )r#   r   r   s      r%   r   Part.load_rels_from_xmlJ  s"     	

  !7!7Ir(   c                    U R                   $ )zPackage this part belongs to.)r   r?   s    r%   r   Part.packageS       }}r(   c                    U R                   $ )z@|PackURI| partname for this part, e.g. "/ppt/slides/slide1.xml".)r   r?   s    r%   r   Part.partnameX  s     ~~r(   c                |    [        U[        5      (       d!  [        S[        U5      R                  -  5      eXl        g )Nz.partname must be instance of PackURI, got '%s')r*   r   	TypeErrorr=   r>   r   r#   r   s     r%   r   r   ]  s5    (G,,@4>CZCZZ  "r(   c                    U R                   $ )z:Collection of relationships from this part to other parts.r!   r?   s    r%   rr   	Part.relse  s     zzr(   c                   [        U[        5      (       a&  [        US5       nUR                  5       sSSS5        $ [	        [        US5      5      (       a  UR                  S5        UR                  5       $ ! , (       d  f       NI= f)zIReturn bytes of `file`, which is either a str path or a file-like object.rbNseekr   )r*   r+   r_   readcallablegetattrr   )r#   filefs      r%   _blob_from_filePart._blob_from_filek  sb     dC  dD!Qvvx "!
 GD&)**IIaLyy{ "!s   A77
Bc                @    [        U R                  R                  5      $ )z'Relationships from this part to others.)rI   r   r   r?   s    r%   r!   
Part._relsx  s     dnn4455r(   )r   r   r   r   rS   )r   r   r   r+   r   r   r   zbytes | None)
r   r   r   r+   r   r   r   bytesrC   r   rC   r  )r   r  rC   r+   )r   r   r   r   rC   r   )rC   r   rC   r   )r   r   rH   )r   r   rC   r  )r>   rJ   rK   rL   rM   rX   r   r   r   r   setterr   r   r   r   r   rr   r   r!   rN   rA   r(   r%   rD   rD     s     \`/2=DLX : : ! ! 
[[  " "J     __" "  
 6 6r(   rD   c                     ^  \ rS rSrSr        S
U 4S jjr\SS j5       r\SS j5       r	SS jr
\S 5       rSS jrS	rU =r$ )XmlParti~  zBase class for package parts containing an XML payload, which is most of them.

Provides additional methods to the |Part| base class that take care of parsing and
reserializing the XML payload and managing relationships to other parts.
c                :   > [         [        U ]  XU5        X@l        g rS   )superr
  rX   _element)r#   r   r   r   element	__class__s        r%   rX   XmlPart.__init__  s     	gt%hgFr(   c                8    U " XU[        S[        U5      5      S9$ )z<Return instance of `cls` loaded with parsed XML from `blob`.r   )r  )r
   r   r   s        r%   r   XmlPart.load  s%     GT:KYW[_5]
 	
r(   c                ,    [        U R                  5      $ )z%bytes XML serialization of this part.)r   r  r?   s    r%   r   XmlPart.blob  s     "$--00r(   c                f    U R                  U5      S:  a  U R                  R                  U5        gg)zRemove relationship identified by `rId` if its reference count is under 2.

Relationships with a reference count of 0 are implicit relationships. Note that only XML
parts can drop relationships.
   N)_rel_ref_countr!   rc   r4   s     r%   rd   XmlPart.drop_rel  s,     s#a'JJNN3 (r(   c                    U $ )zThis part.

This is part of the parent protocol, "children" of the document will not know the part
that contains them so must ask their parent object. That chain of delegation ends here for
child objects.
rA   r?   s    r%   rl   XmlPart.part  s	     r(   c                    [        [        SU R                  R                  S5      5       Vs/ s H  o"U:X  d  M
  UPM     sn5      $ s  snf )z;Return int count of references in this part's XML to `rId`.z	list[str]z//@r:id)r   r
   r  xpath)r#   r5   rs      r%   r  XmlPart._rel_ref_count  s=    tK1D1DY1OP]P!Y\T\AP]^^]s
   	AA)r  )r   r   r   r+   r   r   r  r   )r   r   r   r+   r   r   r   r  r  r   )r5   r+   rC   int)r>   rJ   rK   rL   rM   rX   r   r   r   r   rd   rl   r  rN   __classcell__)r  s   @r%   r
  r
  ~  sz      /2 =D O^  
 
 1 1   _ _r(   r
  c                  F    \ rS rSr% Sr0 rS\S'   S	S jr\S
S j5       r	Sr
g)r   i  zConstructs a registered subtype of |Part|.

Client code can register a subclass of |Part| to be used for a package blob based on its
content type.
zdict[str, type[Part]]part_type_forc                H    U R                  U5      nUR                  XX45      $ rS   )_part_cls_forr   )r^   r   r   r   r   	PartClasss         r%   __new__PartFactory.__new__  s#    %%l3	~~hgDDr(   c                J    XR                   ;   a  U R                   U   $ [        $ )zReturn the custom part class registered for `content_type`.

Returns |Part| if no custom class is registered for `content_type`.
)r"  rD   )r^   r   s     r%   r$  PartFactory._part_cls_for  s&     ,,,$$\22r(   rA   N)
r   r   r   r+   r   r   r   r  rC   rD   )r   r+   rC   z
type[Part])r>   rJ   rK   rL   rM   r"  __annotations__r&  r   r$  rN   rA   r(   r%   r   r     s.     ,.M(-E  r(   r   c                  @    \ rS rSrSrSS jrS	S jr\S
S j5       rSr	g)r   i  zLValue type providing dict semantics for looking up content type by partname.c                    Xl         X l        g rS   )
_overrides	_defaults)r#   	overridesdefaultss      r%   rX   _ContentTypeMap.__init__  s    #!r(   c                ,   [        U[        5      (       d!  [        S[        U5      R                  -  5      eXR
                  ;   a  U R
                  U   $ UR                  U R                  ;   a  U R                  UR                     $ [        SU-  5      e)zBReturn content-type (MIME-type) for part identified by *partname*.z4_ContentTypeMap key must be <type 'PackURI'>, got %sz8no content-type for partname '%s' in [Content_Types].xml)	r*   r   r   r=   r>   r-  extr.  KeyErrorr   s     r%   __getitem___ContentTypeMap.__getitem__  s~    (G,,FhI`I``  &??8,,<<4>>)>>(,,//QT\\]]r(   c                    [        S[        U5      5      n[        S UR                   5       5      n[        S UR                   5       5      nU " X45      $ )zEReturn |_ContentTypeMap| instance populated from `content_types_xml`.r   c              3  l   #    U  H*  oR                   R                  5       UR                  4v   M,     g 7frS   )partNamelowercontentType)r   os     r%   r   +_ContentTypeMap.from_xml.<locals>.<genexpr>  s(      (
9OAZZ/9O   24c              3  l   #    U  H*  oR                   R                  5       UR                  4v   M,     g 7frS   )	extensionr:  r;  )r   ds     r%   r   r=    s(      '
:OQ[[ !--0:Or>  )r
   r   r   override_lstdefault_lst)r^   content_types_xml	types_elmr/  r0  s        r%   r   _ContentTypeMap.from_xml  s_     Y/@%AB	' (
9B9O9O(
 
	 ' '
:C:O:O'
 
 9''r(   )r.  r-  N)r/  dict[str, str]r0  rG  )r   r   rC   r+   )rD  r  rC   r   )
r>   rJ   rK   rL   rM   rX   r5  r   r   rN   rA   r(   r%   r   r     s$    V"^ 
( 
(r(   r   c                     \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jr        SS
 jrSS jrSS jr\S 5       rSSS jjr S       S S jjr\S!S j5       r\S"S j5       r\S#S j5       rSrg)$rI   i  a  Collection of |_Relationship| instances having `dict` semantics.

Relationships are keyed by their rId, but may also be found in other ways, such as by their
relationship type. |Relationship| objects are keyed by their rId.

Iterating this collection has normal mapping semantics, generating the keys (rIds) of the
mapping. `rels.keys()`, `rels.values()`, and `rels.items() can be used as they would be for a
`dict`.
c                    Xl         g rS   	_base_uri)r#   r   s     r%   rX   _Relationships.__init__  rZ   r(   c                    XR                   ;   $ )z9Implement 'in' operation, like `"rId7" in relationships`.r   r4   s     r%   __contains___Relationships.__contains__  s    jj  r(   c                Z     U R                   U   $ ! [         a    [        SU-  5      ef = f)zJImplement relationship lookup by rId using indexed access, like rels[rId].zno relationship with key '%s')r!   r4  r4   s     r%   r5  _Relationships.__getitem__  s8    	B::c?" 	B:S@AA	Bs    *c                ,    [        U R                  5      $ )zDImplement iteration of rIds (iterating a mapping produces its keys).)iterr!   r?   s    r%   __iter___Relationships.__iter__  s    DJJr(   c                ,    [        U R                  5      $ )z,Return count of relationships in collection.)r   r!   r?   s    r%   __len___Relationships.__len__
  s    4::r(   c                P    U R                  X5      nUc  U R                  X5      $ U$ )zReturn str rId of `reltype` to `target_part`.

The rId of an existing matching relationship is used if present. Otherwise, a new
relationship is added and that rId is returned.
_get_matching_add_relationship)r#   r$   r3   existing_rIds       r%   r-   _Relationships.get_or_add  s4     ))'?<H<PD""78	
Vb	
r(   c                L    U R                  XSS9nUc  U R                  XSS9$ U$ )zReturn str rId of external relationship of `reltype` to `target_ref`.

The rId of an existing matching relationship is used if present. Otherwise, a new
relationship is added and that rId is returned.
T)r/   rZ  )r#   r$   r9   r]  s       r%   r,   !_Relationships.get_or_add_ext_rel  sE     ))'4)P # ""7D"I	
 	
r(   c                   ^^^ UUU4S jnU R                   R                  5         U R                   R                  S U" 5        5       5        g)zHReplace any relationships in this collection with those from `xml_rels`.c               3     >#    TR                    Hc  n U R                  [        R                  :X  a)  [        R
                  " TU R                  5      nUT;  a  MJ  [        R                  TU T5      v   Me     g7f)z?Filter out broken relationships such as those pointing to NULL.N)	r   r   r   INTERNALr   r   r9   _Relationshipr   )rel_elmr   r   r   r   s     r%   iter_valid_rels5_Relationships.load_from_xml.<locals>.iter_valid_rels+  sb     #44
 %%5&33Hg>P>PQHu, #,,XwFF 5s   A5A8c              3  <   #    U  H  oR                   U4v   M     g 7frS   )r5   )r   rk   s     r%   r   /_Relationships.load_from_xml.<locals>.<genexpr>9  s     F4ES77C.4Es   N)r!   clearupdate)r#   r   r   r   rf  s    ``` r%   r   _Relationships.load_from_xml&  s6    
	G 	



FO4EFFr(   c                    U R                   U   n[        U5      S:X  a  [        SU-  5      e[        U5      S:  a  [        SU-  5      eUS   R                  $ )zReturn target part of relationship with matching `reltype`.

Raises |KeyError| if not found and |ValueError| if more than one matching relationship is
found.
r   z*no relationship of type '%s' in collectionr   z1multiple relationships of type '%s' in collection)_rels_by_reltyper   r4  
ValueErrorr3   )r#   r$   rels_of_reltypes      r%   r"    _Relationships.part_with_reltype;  sb     //81$G'QRR!#PSZZ[[q!---r(   c                8    U R                   R                  U5      $ )zReturn |_Relationship| identified by `rId` after removing it from collection.

The caller is responsible for ensuring it is no longer required.
rb   r4   s     r%   rc   _Relationships.popK  s    
 zz~~c""r(   c                   ^  [         R                  " 5       nU 4S jnU" 5        H?  nUR                  UR                  UR                  UR
                  UR                  5        MA     UR                  $ )zbytes XML serialization of this relationship collection.

This value is suitable for storage as a .rels file in an OPC package. Includes a `<?xml..`
declaration header with encoding as UTF-8.
c                 \   > [        S TR                  5        5       5      n U4S jU  5       $ )Nc              3     #    U  HE  nUR                  S 5      (       a&  USS R                  5       (       a  [        USS 5      OSU4v   MG     g7f)r5      Nr   )r   isdigitr  )r   r5   s     r%   r   K_Relationships.xml.<locals>.iter_rels_in_numerical_order.<locals>.<genexpr>^  sP      *
 'C %(NN5$9$9c!"goo>O>OCABLUV 's   AAc              3  2   >#    U  H  u  pTU   v   M     g 7frS   rA   )r   _r5   r#   s      r%   r   ry  e  s     A,@&!DI,@s   )sortedkeys)sorted_num_rId_pairsr#   s    r%   iter_rels_in_numerical_order8_Relationships.xml.<locals>.iter_rels_in_numerical_order]  s2    #) *
  99;* $  B,@AAr(   )r   r   add_relr5   r$   r9   r/   xml_file_bytes)r#   rels_elmr  rk   s   `   r%   xml_Relationships.xmlR  sZ     $'')	B 01CSWWckk3>>3??S 2 &&&r(   c                    U R                   n[        U R                  UUU(       a  [        R                  O[        R
                  US9U R                  U'   U$ )z6Return str rId of |_Relationship| newly added to spec.)target_moder.   )	_next_rIdrd  rK  r   r   rc  r!   )r#   r$   r.   r/   r5   s        r%   r\   _Relationships._add_relationshipl  sC    nn'NN(3


3 
r(   c                    U R                   U    HQ  nUR                  U:w  a  M  UR                  (       a  UR                  OUR                  nXR:X  d  ME  UR                  s  $    g)zvReturn optional str rId of rel of `reltype`, `target`, and `is_external`.

Returns `None` on no matching relationship
N)rn  r/   r9   r3   r5   )r#   r$   r.   r/   rk   
rel_targets         r%   r[  _Relationships._get_matchingx  sQ     ((1C+-+.??J#ww 2 r(   c                    [        [        U 5      S-   SS5       H  nSU-  nX R                  ;  d  M  Us  $    [        S5      e)zNext str rId available in collection.

The next rId is the first unused key starting from "rId1" and making use of any gaps in
numbering, e.g. 'rId2' for rIds ['rId1', 'rId3'].
r   r   r   zrId%dzJProgrammingError: Impossible to have more distinct rIds than relationships)r   r   r!   r   )r#   r   rId_candidates      r%   r  _Relationships._next_rId  sJ     s4y1}a,A#aKMJJ.$$ - X
 	
r(   c                    0 $ )zFdict {rId: _Relationship} containing relationships of this collection.rA   r?   s    r%   r!   _Relationships._rels  s	     	r(   c                    [         R                  " [        5      nU R                  5        H   nXR                     R                  U5        M"     U$ )zBdefaultdict {reltype: [rels]} for all relationships in collection.)collectionsdefaultdictlistrq   r$   append)r#   Drk   s      r%   rn  _Relationships._rels_by_reltype  s=     4?3J3J43P;;=CkkN!!#& !r(   rJ  N)r   r+   )r5   objectrC   rG   )r5   r+   rC   rd  )rC   zIterator[str])rC   r  )r$   r+   r3   rD   rC   r+   )r$   r+   r9   r+   rC   r+   )r   r+   r   r   r   r   rC   r   rB   rE   )r$   r+   r.   rF   r/   rG   rC   r+   )r$   r+   r.   rF   r/   rG   rC   z
str | Noner  )rC   zdict[str, _Relationship])rC   zdict[str, list[_Relationship]])r>   rJ   rK   rL   rM   rX   rN  r5  rT  rW  r-   r,   r   r"   rc   r   r  r\  r[  r  r   r!   rn  rN   rA   r(   r%   rI   rI     s    "!B 	

GG'7G@SG	G*. # ' '2
 EJ$.=A	  
 
"    r(   rI   rd  c                      \ rS rSrSrSS jr\        SS j5       r\SS j5       r	\SS j5       r
\SS j5       r\SS j5       r\SS	 j5       r\SS
 j5       rSrg)rd  i  zDValue object describing link from a part or package to another part.c                @    Xl         X l        X0l        X@l        XPl        g rS   )rK  _rId_reltype_target_mode_target)r#   r   r5   r$   r  r.   s         r%   rX   _Relationship.__init__  s    !	'r(   c                    UR                   [        R                  :X  a  UR                  O"U[        R
                  " XR                  5         nU " XR                  UR                  UR                   U5      $ )zEReturn |_Relationship| object based on CT_Relationship element `rel`.)r   r   r   r9   r   r   r5   r$   )r^   r   rk   r   r.   s        r%   r   _Relationship.from_xml  sX     ~~- NNw++HnnEF 	
 8WWckk3>>6JJr(   c                <    U R                   [        R                  :H  $ )zTrue if target_mode is `RTM.EXTERNAL`.

An external relationship is a link to a resource outside the package, such as a
web-resource (URL).
)r  r   r   r?   s    r%   r/   _Relationship.is_external  s       CLL00r(   c                    U R                   $ )zHMember of RELATIONSHIP_TYPE describing relationship of target to source.)r  r?   s    r%   r$   _Relationship.reltype  r   r(   c                    U R                   $ )zstr relationship-id, like 'rId9'.

Corresponds to the `Id` attribute on the `CT_Relationship` element and uniquely identifies
this relationship within its peers for the source-part or package.
)r  r?   s    r%   r5   _Relationship.rId  s     yyr(   c                    U R                   (       a  [        S5      e[        U R                  [        5      (       d   eU R                  $ )z3|Part| or subtype referred to by this relationship.zR`.target_part` property on _Relationship is undefined when target-mode is external)r/   ro  r*   r  rD   r?   s    r%   r3   _Relationship.target_part  sB     *  $,,----||r(   c                    U R                   (       a  [        S5      e[        U R                  [        5      (       d   eU R                  R
                  $ )z|PackURI| instance containing partname targeted by this relationship.

Raises `ValueError` on reference if target_mode is external. Use :attr:`target_mode` to
check before referencing.
zV`.target_partname` property on _Relationship is undefined when target-mode is external)r/   ro  r*   r  rD   r   r?   s    r%   r   _Relationship.target_partname  sH     *  $,,----||$$$r(   c                    U R                   (       a-  [        U R                  [        5      (       d   eU R                  $ U R                  R                  U R                  5      $ )zstr reference to relationship target.

For internal relationships this is the relative partname, suitable for serialization
purposes. For an external relationship it is typically a URL.
)r/   r*   r  r+   r   relative_refrK  r?   s    r%   r9   _Relationship.target_ref  sI     dllC0000<<##00@@r(   )rK  r  r  r  r  N)
r   r+   r5   r+   r$   r+   r  r+   r.   rF   )r   r+   rk   r   r   r   rC   rd  )rC   rG   r  )rC   rD   r  )r>   rJ   rK   rL   rM   rX   r   r   r   r/   r$   r5   r3   r   r9   rN   rA   r(   r%   rd  rd    s    N 	K	K!0	K9L	K		K 	K 1 1       % % 
A 
Ar(   )5rM   
__future__r   r  typingr   r   r   r   r   r	   r
   pptx.opc.constantsr   r   r   rx   pptx.opc.oxmlr   r   pptx.opc.packurir   r   r   pptx.opc.serializedr   r   pptx.opc.sharedr   	pptx.oxmlr   	pptx.utilr   typing_extensionsr   r   r   pptx.oxml.xmlchemyr   pptx.packager   pptx.parts.presentationr   r   rP   r   rD   r
  r   r   r+   rI   rd  rA   r(   r%   <module>r     s    #  O O O > 6 > D D < /  "&72$8$
 $
Nb3 b3Jl
 l
^b6? b6J0_d 0_f 0!( !(HxWS/12 xvRA RAr(   