
    hA#                        S r SSKJr  SSKJrJrJrJr  SSKJ	r	  SSK
Jr  SSK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   " S S5      r " S S5      r " S S\5      rg)zAOpen Packaging Convention (OPC) objects related to package parts.    )annotations)TYPE_CHECKINGCallableTypecast)serialize_part_xml)PackURI)Relationships)cls_method_fn	parse_xml)lazyproperty)BaseOxmlElement)Packagec                  6  ^  \ rS rSrSr  S       SU 4S jjjrS rS r\SS j5       r	\S 5       r
SS jr\SS	 j5       rSSS
 jjr\S 5       r\S 5       r\R"                  SS j5       rSS jrSSS jjr\S 5       r\S 5       rSS jrS S jrSrU =r$ )!Part   zBase class for package parts.

Provides common properties and methods, but intended to be subclassed in client code
to implement specific part behaviors.
c                Z   > [         [        U ]  5         Xl        X l        X0l        X@l        g N)superr   __init__	_partname_content_type_blob_package)selfpartnamecontent_typeblobpackage	__class__s        ?/var/www/html/env/lib/python3.13/site-packages/docx/opc/part.pyr   Part.__init__   s'     	dD"$!)
    c                    g)zEntry point for post-unmarshaling processing, for example to parse the part
XML.

May be overridden by subclasses without forwarding call to super.
N r   s    r"   after_unmarshalPart.after_unmarshal)        	r$   c                    g)zEntry point for pre-serialization processing, for example to finalize part
naming if necessary.

May be overridden by subclasses without forwarding call to super.
Nr&   r'   s    r"   before_marshalPart.before_marshal3   r*   r$   c                ,    U R                   =(       d    S$ )zContents of this package part as a sequence of bytes.

May be text or binary. Intended to be overridden by subclasses. Default behavior
is to return load blob.
r$   )r   r'   s    r"   r   	Part.blob=   s     zz S r$   c                    U R                   $ )zContent type of this part.)r   r'   s    r"   r   Part.content_typeF   s     !!!r$   c                J    U R                  U5      S:  a  U R                  U	 gg)zRemove the relationship identified by `rId` if its reference count is less
than 2.

Relationships with a reference count of 0 are implicit relationships.
   N)_rel_ref_countrelsr   rIds     r"   drop_relPart.drop_relK   s'     s#a'		# (r$   c                    U " XX45      $ r   r&   )clsr   r   r   r    s        r"   load	Part.loadT   s    8499r$   c                :    U R                   R                  XX45      $ )av  Return newly added |_Relationship| instance of `reltype`.

The new relationship relates the `target` part to this part with key `rId`.

Target mode is set to ``RTM.EXTERNAL`` if `is_external` is |True|. Intended for
use during load from a serialized package, where the rId is well-known. Other
methods exist for adding a new relationship to a part when manipulating a part.
)r5   add_relationship)r   reltypetargetr7   is_externals        r"   load_relPart.load_relX   s     yy))'3LLr$   c                    U R                   $ )z+|OpcPackage| instance this part belongs to.)r   r'   s    r"   r    Part.packagec        }}r$   c                    U R                   $ )zP|PackURI| instance holding partname of this part, e.g.
'/ppt/slides/slide1.xml'.)r   r'   s    r"   r   Part.partnameh   s     ~~r$   c                    [        U[        5      (       d#  Sn[        U[        U5      R                  -  5      eXl        g )Nz.partname must be instance of PackURI, got '%s')
isinstancer	   	TypeErrortype__name__r   )r   r   tmpls      r"   r   rI   n   s3    (G,,CDD4>#:#::;;!r$   c                8    U R                   R                  U5      $ )a  Return part to which this part has a relationship of `reltype`.

Raises |KeyError| if no such relationship is found and |ValueError| if more than
one such relationship is found. Provides ability to resolve implicitly related
part, such as Slide -> SlideLayout.
)r5   part_with_reltype)r   r@   s     r"   part_related_byPart.part_related_byu   s     yy**733r$   c                    U(       a*  U R                   R                  U[        [        U5      5      $ U R                   R	                  U[        [
        U5      5      nUR                  $ )zReturn rId key of relationship of `reltype` to `target`.

The returned `rId` is from an existing relationship if there is one, otherwise a
new relationship is created.
)r5   get_or_add_ext_relr   str
get_or_addr   r7   )r   rA   r@   rB   rels        r"   	relate_toPart.relate_to~   sK     99//c69JKK))&&wT60BCC77Nr$   c                .    U R                   R                  $ )zDictionary mapping related parts by rId, so child objects can resolve
explicit relationships present in the part XML, e.g. sldIdLst to a specific
|Slide| instance.)r5   related_partsr'   s    r"   r\   Part.related_parts   s    
 yy&&&r$   c                b    [        U R                  R                  5      U l        U R                  $ )zA|Relationships| instance holding the relationships for this part.)r
   r   baseURI_relsr'   s    r"   r5   	Part.rels   s$     #4>>#9#9:
zzr$   c                8    U R                   U   nUR                  $ )zGReturn URL contained in target ref of relationship identified by `rId`.)r5   
target_ref)r   r7   rX   s      r"   rc   Part.target_ref   s    iin~~r$   c                    g)zReturn the count of references in this part to the relationship identified by `rId`.

Only an XML part can contain references, so this is 0 for `Part`.
r   r&   r6   s     r"   r4   Part._rel_ref_count   s    
 r$   )r   r   r   r   r`   )NN)r   r	   r   rV   r   zbytes | Noner    zPackage | None)returnbytes)r7   rV   r   r	   r   rV   r   rh   r    r   )F)r@   rV   rA   
Part | strr7   rV   rB   bool)r   rV   )r@   rV   rg   r   )rA   rj   r@   rV   rB   rk   rg   rV   )r7   rV   rg   rV   r7   rV   rg   int)rN   
__module____qualname____firstlineno____doc__r   r(   r,   propertyr   r   r8   classmethodr<   rC   r    r   setterrR   rY   r\   r   r5   rc   r4   __static_attributes____classcell__r!   s   @r"   r   r      s    ""&     	 
      ! ! " " : :	M    
 __" "4
 ' '  
 r$   r   c                  h    \ rS rSr% SrS\S'   0 rS\S'   \r          SS jr	\
SS j5       rS	rg
)PartFactory   a  Provides a way for client code to specify a subclass of |Part| to be constructed
by |Unmarshaller| based on its content type and/or a custom callable.

Setting ``PartFactory.part_class_selector`` to a callable object will cause that
object to be called with the parameters ``content_type, reltype``, once for each
part in the package. If the callable returns an object, it is used as the class for
that part. If it returns |None|, part class selection falls back to the content type
map defined in ``PartFactory.part_type_for``. If no class is returned from either of
these, the class contained in ``PartFactory.default_part_type`` is used to construct
the part, which is by default ``opc.package.Part``.
z.Callable[[str, str], Type[Part] | None] | Nonepart_class_selectorzdict[str, Type[Part]]part_type_forc                    S nU R                   b  [        U S5      nU" X#5      nUc  U R                  U5      nUR                  XXE5      $ )Nr{   )r{   r   _part_cls_forr<   )r;   r   r   r@   r   r    	PartClassr{   s           r"   __new__PartFactory.__new__   sT     (,	""."/5J"K+LBI)),7I~~hdDDr$   c                V    XR                   ;   a  U R                   U   $ U R                  $ )zReturn the custom part class registered for `content_type`, or the default
part class if no custom class is registered for `content_type`.)r|   default_part_type)r;   r   s     r"   r~   PartFactory._part_cls_for   s-     ,,,$$\22$$$r$   r&   N)
r   r	   r   rV   r@   rV   r   rh   r    r   )r   rV   )rN   rn   ro   rp   rq   __annotations__r|   r   r   r   rs   r~   ru   r&   r$   r"   ry   ry      sp    
 HG+-M(-EE E 	E
 E E  % %r$   ry   c                     ^  \ rS rSrSr        S
U 4S jjr\S 5       r\S 5       r\	SS j5       r
\S 5       rSS jrS	rU =r$ )XmlPart   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                6   > [         [        U ]  XUS9  X0l        g )N)r    )r   r   r   _element)r   r   r   elementr    r!   s        r"   r   XmlPart.__init__   s     	gt%hg%Nr$   c                ,    [        U R                  5      $ r   )r   r   r'   s    r"   r   XmlPart.blob   s    !$--00r$   c                    U R                   $ )z&The root XML element of this XML part.r   r'   s    r"   r   XmlPart.element   rG   r$   c                *    [        U5      nU " XXT5      $ r   r   )r;   r   r   r   r    r   s         r"   r<   XmlPart.load   s    D/87<<r$   c                    U $ )zPart 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.
r&   r'   s    r"   partXmlPart.part   s	     r$   c                    [        SU R                  R                  S5      5      n[        U Vs/ s H  o3U:X  d  M
  UPM     sn5      $ s  snf )zZReturn the count of references in this part's XML to the relationship
identified by `rId`.z	list[str]z//@r:id)r   r   xpathlen)r   r7   rIds_rIds       r"   r4   XmlPart._rel_ref_count   s@     K!4!4Y!?@T9TTS[DT9::9s
   	A	A	r   )r   r	   r   rV   r   r   r    r   ri   rl   )rN   rn   ro   rp   rq   r   rr   r   r   rs   r<   r   r4   ru   rv   rw   s   @r"   r   r      s      /2 =L W^  1 1   = =  ; ;r$   r   N)rq   
__future__r   typingr   r   r   r   docx.opc.oxmlr   docx.opc.packurir	   docx.opc.relr
   docx.opc.sharedr   docx.oxml.parserr   docx.sharedr   docx.oxml.xmlchemyr   docx.packager   r   ry   r   r&   r$   r"   <module>r      sS    H " 6 6 , $ & ) & $2$M M`'% '%T(;d (;r$   