
    ,hk                     N   d Z ddlZddlmZmZ ddlmZmZ	 ddl
mZmZ ddlmZmZmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z#y)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.
    N)	is_stringMapping)RELATIONSHIP_TARGET_MODERELATIONSHIP_TYPE)CT_Relationshipsserialize_part_xml)CONTENT_TYPES_URIPACKAGE_URIPackURI)PackageReaderPackageWriter)CaseInsensitiveDict	parse_xml)lazypropertyc                   :    e Zd ZdZd ZddZd Zd Zed        Z	y)	_RelatableMixinzHProvide relationship methods required by both the package and each part.c                 8    | j                   j                  |      S )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     R/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/opc/package.pypart_related_byz_RelatableMixin.part_related_by   s     zz++G44    c                 v    |r| j                   j                  ||      S | j                   j                  ||      S )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.
        )r   get_or_add_ext_rel
get_or_add)r   targetr   is_externals       r   	relate_toz_RelatableMixin.relate_to    s=      JJ))'6:	
 &&w7	
r   c                 4    | j                   |   j                  S )z2Return related |Part| subtype identified by `rId`.)r   target_partr   rIds     r   related_partz_RelatableMixin.related_part,   s    zz#***r   c                 4    | j                   |   j                  S )zGReturn URL contained in target ref of relationship identified by `rId`.)r   
target_refr$   s     r   r(   z_RelatableMixin.target_ref0   s    zz#)))r   c                 D    t        dt        |       j                  z        )I|Relationships| object containing relationships from this part to others.z`%s` must implement `.rels`)NotImplementedErrortype__name__r   s    r   r   z_RelatableMixin._rels4   s#     ")DJ,?,??
 	
r   NF)
r-   
__module____qualname____doc__r   r!   r&   r(   r   r    r   r   r   r      s-    R5

+* 
 
r   r   c                   j    e Zd ZdZd Zed        Zd Zd Zd Z	e
d        Zd Zd	 Zd
 Zed        Zy)
OpcPackagezMain 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                     || _         y N)	_pkg_filer   pkg_files     r   __init__zOpcPackage.__init__C   	    !r   c                 .     | |      j                         S )zGReturn an |OpcPackage| instance loaded with the contents of `pkg_file`._load)clsr:   s     r   openzOpcPackage.openF   s     8}""$$r   c                 :    | j                   j                  |       y)z(Remove relationship identified by `rId`.Nr   popr$   s     r   drop_relzOpcPackage.drop_relK   s    

sr   c              #      K   t               }| j                         D ]5  }|j                  r|j                  }||v r!| |j	                  |       7 yw)z;Generate exactly one reference to each part in the package.N)set	iter_relsr    r#   add)r   visitedrelparts       r   
iter_partszOpcPackage.iter_partsO   sQ     %>># 	C??DwJKK	s   AAc              #   f   K   t               fd | j                        D ]  }|  yw)zGenerate exactly one reference to each relationship in package.

        Performs a depth-first traversal of the rels graph.
        c              3      K   | j                         D ]P  }| |j                  r|j                  }|v r%j                  |        |j                        D ]  }|  R y wr7   )valuesr    r#   rI   rels)rQ   rK   rL   rJ   	walk_relss      r   rR   z'OpcPackage.iter_rels.<locals>.walk_relsb   si     {{} 	?? 7?D!$TYY/ CIs   A%A(N)rG   r   )r   rK   rJ   rR   s     @@r   rH   zOpcPackage.iter_rels[   s4     
 %	" TZZ( 	CI	s   -1c                 @    | j                  t        j                        S )zReturn |Part| subtype serving as the main document part for this package.

        In this case it will be a |Presentation| part.
        )r   RTOFFICE_DOCUMENTr.   s    r   main_document_partzOpcPackage.main_document_partv   s     ##B$6$677r   c                     |d|dz  j                  d       t        fd| j                         D              }t        t	        |      dz   dd      D ]  }||z  }||vst        |      c S  t        d      )	a  Return |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*   42c              3   n   K   | ],  }|j                   j                        s|j                    . y wr7   )partname
startswith).0pprefixs     r   	<genexpr>z+OpcPackage.next_partname.<locals>.<genexpr>   s+      
QZZ5J5J65RAJJ
s    55   r   z0ProgrammingError: ran out of candidate_partnames)findrG   rM   rangelenr   	Exception)r   tmpl	partnamesncandidate_partnamer_   s        @r   next_partnamezOpcPackage.next_partname~   s     .((./ 
 $ 1
 
	 s9~)1b1 	3A!%!2122	3 >
 	
r   c                 t    t        j                  || j                  t        | j	                                      y)zzSave 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   r9   s     r   savezOpcPackage.save   s&    
 	Hdjj%8I2JKr   c                     t         j                  | j                  |       \  }}| j                  j	                  t
        ||       | S )z=Return the package after loading all parts and relationships.)_PackageLoaderloadr8   r   load_from_xmlr
   )r   pkg_xml_relspartss      r   r?   zOpcPackage._load   s8    ,11$..$Ge

  lEBr   c                 4    t        t        j                        S )z@|Relationships| object containing relationships of this package.)_Relationshipsr
   baseURIr.   s    r   r   zOpcPackage._rels   s     k1122r   N)r-   r0   r1   r2   r;   classmethodrA   rE   rM   rH   propertyrV   rk   ro   r?   r   r   r3   r   r   r5   r5   <   sg    " % %
6 8 8
,L 3 3r   r5   c                   r    e Zd ZdZd Zed        Zd Zed        Z	ed        Z
ed        Zed        Zd	 Zy
)rq   z@Function-object that loads a package from disk (or other store).c                      || _         || _        y r7   )r8   _package)r   r:   packages      r   r;   z_PackageLoader.__init__   s    !r   c                 0     | ||      j                         S )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@   r:   r~   s      r   rr   z_PackageLoader.load   s     8W%++--r   c                     | j                   | j                  }}|j                         D ]  \  }}|j                  ||   |        |d   |fS )zBReturn (pkg_xml_rels, parts) pair resulting from loading pkg_file./)_parts	_xml_relsitemsload_rels_from_xml)r   ru   xml_relsr[   rL   s        r   r?   z_PackageLoader._load   sR    ++t~~x#kkm 	?NHd##HX$6>	? }e##r   c                 N    t         j                  | j                  t                 S )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_typesz_PackageLoader._content_types   s!     ''(<(<=N(OPPr   c                 ,    t        | j                        S )zE|PackageReader| object providing access to package-items in pkg_file.)r   r8   r.   s    r   r   z_PackageLoader._package_reader   s     T^^,,r   c                     | j                   }| j                  }| j                  }d | j                  j	                         D        D ci c]  }||v r|t        |||   |||          c}S c c}w )a]  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   ,   K   | ]  }|d k7  s	|  yw)r   Nr3   )r]   r^   s     r   r`   z(_PackageLoader._parts.<locals>.<genexpr>   s     J1cQJs   
)blob)r   r}   r   r   keysPartFactory)r   content_typesr~   package_readerr[   s        r   r   z_PackageLoader._parts   s     ++---- K(;(;(=J
  >) kh'#H-	 
 	
 
s   !A,c                 v     i t                fd t         j                  t                     S )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                    || <   j                  |        | j                  }|D ]]  }|j                  t        j                  k(  r!t        j                  ||j                        }|v rF |j                  |             _ y)zAPopulate `xml_rels` dict by traversing relationships depth-first.N)	rI   rx   
targetModeRTMEXTERNALr   from_rel_refr(   _xml_rels_for)	source_partnamerQ   base_urirK   target_partname	load_relsr   visited_partnamesr   s	        r   r   z+_PackageLoader._xml_rels.<locals>.load_rels   s    (,H_%!!/2&..H  P>>S\\1")"6"6x"P"&77/4+=+=o+NOPr   )rG   r
   r   )r   r   r   r   s   `@@@r   r   z_PackageLoader._xml_rels   s4     E	P 	+t11+>?r   c                 z    | j                   j                  |      }|t        j                         S t	        |      S )a  Return 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[   rels_xmls      r   r   z_PackageLoader._xml_rels_for  s9     ''44X>)1)9##%Ry?RRr   N)r-   r0   r1   r2   r;   ry   rr   r?   r   r   r   r   r   r   r3   r   r   rq   rq      s{    J  . .$ Q Q - - 
 
2  6Sr   rq   c                       e Zd ZdZddZed        Zed        Zej                  d        Ze
d        Zd Zd	 Ze
d
        Zed        Zej                  d        Ze
d        Zd Zd Ze
d        Zy)Parta   Base 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                 <    || _         || _        || _        || _        y r7   )	_partname_content_typer}   _blob)r   r[   content_typer~   r   s        r   r;   zPart.__init__  s    !)
r   c                      | ||||      S )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.
        r3   r@   r[   r   r~   r   s        r   rr   z	Part.load"  s     8\7D99r   c                     | j                   S )a   Contents of this package part as a sequence of bytes.

        May be text (XML generally) or binary. Intended to be overridden by subclasses.
        Default behavior is to return the blob initial loaded during `Package.open()`
        operation.
        r   r.   s    r   r   z	Part.blob+  s     zzr   c                     || _         y)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   bytes_s     r   r   z	Part.blob5  s     
r   c                     | j                   S )z&Content-type (MIME-type) of this part.)r   r.   s    r   r   zPart.content_type>  s     !!!r   c                 d    | j                  |      dk  r| j                  j                  |       yy)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   rD   r$   s     r   rE   zPart.drop_relC  s,     s#a'JJNN3 (r   c                 f    | j                   j                  | j                  j                  ||       y)a\  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   rs   r   rx   )r   r   ru   s      r   r   zPart.load_rels_from_xmlL  s$     	

  !7!75Ir   c                     | j                   S )z+|OpcPackage| instance this part belongs to.)r}   r.   s    r   r~   zPart.packageV       }}r   c                     | j                   S )z@|PackURI| partname for this part, e.g. "/ppt/slides/slide1.xml".)r   r.   s    r   r[   zPart.partname[  s     ~~r   c                 t    t        |t              s!t        dt        |      j                  z        || _        y )Nz.partname must be instance of PackURI, got '%s')
isinstancer   	TypeErrorr,   r-   r   r   r[   s     r   r[   zPart.partname`  s7    (G,@x.))*  "r   c                     | j                   S )zJ|Relationships| collection of relationships from this part to other parts.r   r.   s    r   rQ   z	Part.relsi  s     zzr   c                     t        |      r&t        |d      5 }|j                         cddd       S t        t	        |d            r|j                  d       |j                         S # 1 sw Y   ?xY w)zIReturn bytes of `file`, which is either a str path or a file-like object.rbNseekr   )r   rA   readcallablegetattrr   )r   filefs      r   _blob_from_filezPart._blob_from_fileo  sb     T?dD!  Qvvx   
 GD&)*IIaLyy{   s   A((A1c                 |    t        | j                  j                  d      D cg c]
  }||k(  s	| c}      S c c}w )z;Return int count of references in this part's XML to `rId`.z//@r:id)re   _elementxpath)r   r%   rs      r   r   zPart._rel_ref_count|  s0    t}}229=J!cAJKKJs   
99c                 @    t        | j                  j                        S )r*   )rw   r   rx   r.   s    r   r   z
Part._rels  s     dnn4455r   r7   )r-   r0   r1   r2   r;   ry   rr   rz   r   setterr   r   rE   r   r~   r[   rQ   r   r   r   r3   r   r   r   r     s     : :   
[[  " " J     __" "  
L 6 6r   r   c                   R     e Zd ZdZ fdZed        Zed        Zed        Z	 xZ
S )XmlPartzBase 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                 >    t         t        |   |||       || _        y r7   )superr   r;   r   )r   r[   r   r~   element	__class__s        r   r;   zXmlPart.__init__  s    gt%hgFr   c                 ,     | |||t        |            S )z<Return instance of `cls` loaded with parsed XML from `blob`.)r   r   r   s        r   rr   zXmlPart.load  s     8\7IdOLLr   c                 ,    t        | j                        S )z%bytes XML serialization of this part.)r   r   r.   s    r   r   zXmlPart.blob  s     "$--00r   c                     | S )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.
        r3   r.   s    r   rL   zXmlPart.part  s	     r   )r-   r0   r1   r2   r;   ry   rr   rz   r   rL   __classcell__)r   s   @r   r   r     sK      M M 1 1  r   r   c                   *    e Zd ZdZi Zd Zed        Zy)r   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.
    c                 L    | j                  |      }|j                  ||||      S r7   )_part_cls_forrr   )r@   r[   r   r~   r   	PartClasss         r   __new__zPartFactory.__new__  s'    %%l3	~~hgtDDr   c                 H    || j                   v r| j                   |   S t        S )zReturn the custom part class registered for `content_type`.

        Returns |Part| if no custom class is registered for `content_type`.
        )part_type_forr   )r@   r   s     r   r   zPartFactory._part_cls_for  s(     3,,,$$\22r   N)r-   r0   r1   r2   r   r   ry   r   r3   r   r   r   r     s(     ME  r   r   c                   ,    e Zd ZdZd Zd Zed        Zy)r   zLValue type providing dict semantics for looking up content type by partname.c                      || _         || _        y r7   )
_overrides	_defaults)r   	overridesdefaultss      r   r;   z_ContentTypeMap.__init__  s    #!r   c                    t        |t              s!t        dt        |      j                  z        || j
                  v r| j
                  |   S |j                  | j                  v r| j                  |j                     S t        d|z        )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__z_ContentTypeMap.__getitem__  s    (G,Fx.))* 
 t&??8,,<<4>>)>>(,,//FQ
 	
r   c                     t        |      }t        d |j                  D              }t        d |j                  D              } | ||      S )zEReturn |_ContentTypeMap| instance populated from `content_types_xml`.c              3   h   K   | ]*  }|j                   j                         |j                  f , y wr7   )partNamelowercontentType)r]   os     r   r`   z+_ContentTypeMap.from_xml.<locals>.<genexpr>  s+      (
45QZZ/(
   02c              3   h   K   | ]*  }|j                   j                         |j                  f , y wr7   )	extensionr   r   )r]   ds     r   r`   z+_ContentTypeMap.from_xml.<locals>.<genexpr>  s+      '
56Q[[ !--0'
r   )r   r   override_lstdefault_lst)r@   content_types_xml	types_elmr   r   s        r   r   z_ContentTypeMap.from_xml  sZ     /0	' (
9B9O9O(
 
	 ' '
:C:O:O'
 
 9h''r   N)r-   r0   r1   r2   r;   r   ry   r   r3   r   r   r   r     s#    V"
$ 	( 	(r   r   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zed        ZddZddZed        Zed        Zed        Zy)rw   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                     || _         y r7   )	_base_uri)r   r   s     r   r;   z_Relationships.__init__  r<   r   c                     || j                   v S )z9Implement 'in' operation, like `"rId7" in relationships`.r   r$   s     r   __contains__z_Relationships.__contains__  s    djj  r   c                 X    	 | j                   |   S # t        $ r t        d|z        w xY w)zJImplement relationship lookup by rId using indexed access, like rels[rId].zno relationship with key '%s')r   r   r$   s     r   r   z_Relationships.__getitem__  s8    	B::c?" 	B:S@AA	Bs    )c                 ,    t        | j                        S )zDImplement iteration of rIds (iterating a mapping produces its keys).)iterr   r.   s    r   __iter__z_Relationships.__iter__  s    DJJr   c                 ,    t        | j                        S )z,Return count of relationships in collection.)re   r   r.   s    r   __len__z_Relationships.__len__  s    4::r   c                 R    | j                  ||      }|| j                  ||      S |S )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   r#   existing_rIds       r   r   z_Relationships.get_or_add  s?     ))';? # ""7K8	
 	
r   c                 Z    | j                  ||d      }|| j                  ||d      S |S )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    r  )r   r   r(   r  s       r   r   z!_Relationships.get_or_add_ext_rel  sI     ))':4)P # ""7JD"I	
 	
r   c                     fd}| j                   j                          | j                   j                  d  |       D               y)zHReplace any relationships in this collection with those from `xml_rels`.c               3      K   j                   D ]]  } | j                  t        j                  k(  r%t	        j
                  | j                        }|vrEt        j                  |        _ yw)z?Filter out broken relationships such as those pointing to NULL.N)	relationship_lstr   r   INTERNALr   r   r(   _Relationshipr   )rel_elmr[   r   ru   r   s     r   iter_valid_relsz5_Relationships.load_from_xml.<locals>.iter_valid_rels"  sj     #44 	G
 %%5&33Hg>P>PQHu, #,,XwFF	Gs   A.A1c              3   8   K   | ]  }|j                   |f  y wr7   )r%   )r]   rK   s     r   r`   z/_Relationships.load_from_xml.<locals>.<genexpr>0  s     FS377C.Fs   N)r   clearupdate)r   r   r   ru   r  s    ``` r   rs   z_Relationships.load_from_xml  s6    	G 	



FO4EFFr   c                     | j                   |   }t        |      dk(  rt        d|z        t        |      dkD  rt        d|z        |d   j                  S )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 collectionra   z1multiple relationships of type '%s' in collection)_rels_by_reltypere   r   
ValueErrorr#   )r   r   rels_of_reltypes      r   r   z _Relationships.part_with_reltype2  sg     //81$G'QRR!#CgM  q!---r   c                 8    | j                   j                  |      S )zReturn |Relationship| identified by `rId` after removing it from collection.

        The caller is responsible for ensuring it is no longer required.
        rC   r$   s     r   rD   z_Relationships.popD  s    
 zz~~c""r   c                      t        j                         } fd} |       D ]>  }|j                  |j                  |j                  |j
                  |j                         @ |j                  S )zbytes XML serialization of this relationship collection.

        This value is suitable for storage as a .rels file in an OPC package. Includes
        a `<?xml` header with encoding as UTF-8.
        c                  Z    t        d j                         D              } fd| D        S )Nc              3      K   | ]:  }|j                  d       r!|dd j                         rt        |dd       nd|f < yw)r%      Nr   )r\   isdigitint)r]   r%   s     r   r`   zK_Relationships.xml.<locals>.iter_rels_in_numerical_order.<locals>.<genexpr>W  sI      *
  %(NN5$9c!"goo>OCABLUV*s   A Ac              3   .   K   | ]  \  }}|     y wr7   r3   )r]   _r%   r   s      r   r`   zK_Relationships.xml.<locals>.iter_rels_in_numerical_order.<locals>.<genexpr>^  s     A&!SDIAs   )sortedr   )sorted_num_rId_pairsr   s    r   iter_rels_in_numerical_orderz8_Relationships.xml.<locals>.iter_rels_in_numerical_orderV  s2    #) *
  99;* $  B,@AAr   )r   r   add_relr%   r   r(   r    xml)r   rels_elmr!  rK   s   `   r   r#  z_Relationships.xmlK  s_     $'')	B 01 	TCSWWckk3>>3??S	T ||r   c                     | j                   }t        | j                  |||rt        j                  nt        j
                  |      | j                  |<   |S )z6Return str rId of |_Relationship| newly added to spec.)target_moder   )	_next_rIdr  r   r   r   r  r   )r   r   r   r    r%   s        r   r  z _Relationships._add_relationshipe  sC    nn'NN(3


3 
r   c                     | j                   |   D ]I  }|j                  |k7  r|j                  r|j                  n|j                  }||k7  r=|j                  c S  y)zReturn optional str rId of rel of `reltype`, `target`, and `is_external`.

        Returns `None` on no matching relationship
        N)r  r    r(   r#   r%   )r   r   r   r    rK   
rel_targets         r   r  z_Relationships._get_matchingq  s[    
 ((1 	C+-+.??JV#77N	 r   c                 n    t        t        |       dz   dd      D ]  }d|z  }|| j                  vs|c S  y)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'].
        ra   r   rb   zrId%dN)rd   re   r   )r   ri   rId_candidates      r   r'  z_Relationships._next_rId  s?     s4y1}a, 	%A#aKMDJJ.$$	%r   c                     t               S )zFdict {rId: _Relationship} containing relationships of this collection.)dictr.   s    r   r   z_Relationships._rels  s     vr   c                     t        j                  t              }| j                         D ]   }||j                     j                  |       " |S )zBdefaultdict {reltype: [rels]} for all relationships in collection.)collectionsdefaultdictlistrP   r   append)r   DrK   s      r   r  z_Relationships._rels_by_reltype  sD     ##D);;= 	'CckkN!!#&	'r   Nr/   )r-   r0   r1   r2   r;   r   r   r   r  r   r   rs   r   rD   rz   r#  r  r  r'  r   r   r  r3   r   r   rw   rw     s    "!B 

G&.$#  2
 % %    r   rw   c                       e Zd ZdZd Zed        Zed        Zed        Z	ed        Z
ed        Zed        Zed	        Zy
)r  zDValue object describing link from a part or package to another part.c                 J    || _         || _        || _        || _        || _        y r7   )r   _rId_reltype_target_mode_target)r   r   r%   r   r&  r   s         r   r;   z_Relationship.__init__  s&    !	'r   c                     |j                   t        j                  k(  r|j                  n"|t	        j
                  ||j                           } | ||j                  |j                  |j                   |      S )zEReturn |_Relationship| object based on CT_Relationship element `rel`.)r   r   r   r(   r   r   r%   r   )r@   r   rK   ru   r   s        r   r   z_Relationship.from_xml  s\    
 ~~- NNw++HcnnEF 	
 8SWWckk3>>6JJr   c                 <    | j                   t        j                  k(  S )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).
        )r8  r   r   r.   s    r   r    z_Relationship.is_external  s       CLL00r   c                     | j                   S )zHMember of RELATIONSHIP_TYPE describing relationship of target to source.)r7  r.   s    r   r   z_Relationship.reltype  r   r   c                     | j                   S )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.
        )r6  r.   s    r   r%   z_Relationship.rId  s     yyr   c                 H    | j                   rt        d      | j                  S )z3|Part| or subtype referred to by this relationship.zR`.target_part` property on _Relationship is undefined when target-mode is external)r    r  r9  r.   s    r   r#   z_Relationship.target_part  s+     *  ||r   c                 \    | j                   rt        d      | j                  j                  S )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    r  r9  r[   r.   s    r   r   z_Relationship.target_partname  s1     *  ||$$$r   c                 |    | j                   r| j                  S | j                  j                  | j                        S )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    r9  r   relative_refr   r.   s    r   r(   z_Relationship.target_ref  s:      LL	
 %%224>>B	
r   N)r-   r0   r1   r2   r;   ry   r   r   r    r   r%   r#   r   r(   r3   r   r   r  r    s    N K K 1 1       % % 

 

r   r  )$r2   r/  pptx.compatr   r   pptx.opc.constantsr   r   r   rT   pptx.opc.oxmlr   r   pptx.opc.packurir	   r
   r   pptx.opc.serializedr   r   pptx.opc.sharedr   	pptx.oxmlr   	pptx.utilr   objectr   r5   rq   r   r   r   r   rw   r  r3   r   r   <module>rK     s     * W > D D < /  "$
f $
Nh3 h3ViSV iSXp6? p6fd @& 0#(f #(LvW vrO
F O
r   