
    ,hA#                        d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ erdd
lmZ ddlmZ  G d d      Z G d d      Z G d de      Zy)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                      e Zd ZdZ	 	 d	 	 	 	 	 	 	 d fdZd Zd Zedd       Zed        Z	ddZ
edd       Zddd	Zed
        Zed        Zej                   dd       ZddZdddZed        Zed        ZddZddZ xZS )PartzBase class for package parts.

    Provides common properties and methods, but intended to be subclassed in client code
    to implement specific part behaviors.
    c                b    t         t        |           || _        || _        || _        || _        y N)superr   __init__	_partname_content_type_blob_package)selfpartnamecontent_typeblobpackage	__class__s        O/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/opc/part.pyr   zPart.__init__   s/     	dD"$!)
    c                     y)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_unmarshalzPart.after_unmarshal)        	r"   c                     y)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_marshalzPart.before_marshal3   r'   r"   c                "    | j                   xs 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   z	Part.blob=   s     zz S r"   c                    | j                   S )zContent type of this part.)r   r%   s    r!   r   zPart.content_typeF   s     !!!r"   c                H    | j                  |      dk  r| j                  |= yy)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_relzPart.drop_relK   s'     s#a'		# (r"   c                     | ||||      S r   r$   )clsr   r   r   r   s        r!   loadz	Part.loadT   s    8\499r"   c                >    | j                   j                  ||||      S )a  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.
        )r/   add_relationship)r   reltypetargetr1   is_externals        r!   load_relzPart.load_relX   s     yy))'63LLr"   c                    | j                   S )z+|OpcPackage| instance this part belongs to.)r   r%   s    r!   r   zPart.packagec        }}r"   c                    | j                   S )zX|PackURI| instance holding partname of this part, e.g.
        '/ppt/slides/slide1.xml'.)r   r%   s    r!   r   zPart.partnameh   s     ~~r"   c                x    t        |t              s#d}t        |t        |      j                  z        || _        y )Nz.partname must be instance of PackURI, got '%s')
isinstancer	   	TypeErrortype__name__r   )r   r   tmpls      r!   r   zPart.partnamen   s2    (G,CDD4>#:#::;;!r"   c                8    | j                   j                  |      S )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.
        )r/   part_with_reltype)r   r8   s     r!   part_related_byzPart.part_related_byu   s     yy**733r"   c                    |r*| j                   j                  |t        t        |            S | j                   j	                  |t        t
        |            }|j                  S )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.
        )r/   get_or_add_ext_relr   str
get_or_addr   r1   )r   r9   r8   r:   rels        r!   	relate_tozPart.relate_to~   sK     99//c69JKK))&&wT60BCC77Nr"   c                .    | j                   j                  S )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.)r/   related_partsr%   s    r!   rO   zPart.related_parts   s    
 yy&&&r"   c                b    t        | j                  j                        | _        | j                  S )zA|Relationships| instance holding the relationships for this part.)r
   r   baseURI_relsr%   s    r!   r/   z	Part.rels   s$     #4>>#9#9:
zzr"   c                8    | j                   |   }|j                  S )zGReturn URL contained in target ref of relationship identified by `rId`.)r/   
target_ref)r   r1   rL   s      r!   rT   zPart.target_ref   s    iin~~r"   c                     y)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$   r0   s     r!   r.   zPart._rel_ref_count   s    
 r"   )NN)r   r	   r   rJ   r   zbytes | Noner   zPackage | None)returnbytes)r1   rJ   r   r	   r   rJ   r   rW   r   r   )F)r8   rJ   r9   
Part | strr1   rJ   r:   bool)r   rJ   )r8   rJ   rV   r   )r9   rY   r8   rJ   r:   rZ   rV   rJ   )r1   rJ   rV   rJ   r1   rJ   rV   int)rC   
__module____qualname____doc__r   r&   r)   propertyr   r   r2   classmethodr5   r;   r   r   setterrG   rM   rO   r   r/   rT   r.   __classcell__r    s   @r!   r   r      s    ""&     	 
    ! ! " " : :	M    
 __" "4
 ' '  
r"   r   c                  \    e Zd ZU dZded<   i Zded<   eZ	 	 	 	 	 	 	 	 	 	 d	dZe	d
d       Z
y)PartFactorya  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                    d }| j                   t        | d      } |||      }|| j                  |      }|j                  ||||      S )Nrg   )rg   r   _part_cls_forr5   )r4   r   r   r8   r   r   	PartClassrg   s           r!   __new__zPartFactory.__new__   sZ     (,	""."/5J"K+L'BI)),7I~~hdGDDr"   c                T    || j                   v r| j                   |   S | j                  S )zReturn the custom part class registered for `content_type`, or the default
        part class if no custom class is registered for `content_type`.)rh   default_part_type)r4   r   s     r!   rj   zPartFactory._part_cls_for   s/     3,,,$$\22$$$r"   N)
r   r	   r   rJ   r8   rJ   r   rW   r   r   )r   rJ   )rC   r]   r^   r_   __annotations__rh   r   rn   rl   ra   rj   r$   r"   r!   rf   rf      sp    
 HG+-M(-EE E 	E
 E E  % %r"   rf   c                  ~     e Zd ZdZ	 	 	 	 	 	 	 	 d fdZed        Zed        Zed	d       Z	ed        Z
d
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 )N)r   )r   rq   r   _element)r   r   r   elementr   r    s        r!   r   zXmlPart.__init__   s"     	gt%hg%Nr"   c                ,    t        | j                        S r   )r   rs   r%   s    r!   r   zXmlPart.blob   s    !$--00r"   c                    | j                   S )z&The root XML element of this XML part.)rs   r%   s    r!   rt   zXmlPart.element   r=   r"   c                .    t        |      } | ||||      S r   r   )r4   r   r   r   r   rt   s         r!   r5   zXmlPart.load   s    D/8\7G<<r"   c                    | S )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!   partzXmlPart.part   s	     r"   c                    t        d| j                  j                  d            }t        |D cg c]
  }||k(  s	| c}      S c c}w )zbReturn the count of references in this part's XML to the relationship
        identified by `rId`.z	list[str]z//@r:id)r   rs   xpathlen)r   r1   rIds_rIds       r!   r.   zXmlPart._rel_ref_count   s>     K!4!4Y!?@T9TTS[D9::9s
   
AA)r   r	   r   rJ   rt   r   r   r   rX   r[   )rC   r]   r^   r_   r   r`   r   rt   ra   r5   ry   r.   rc   rd   s   @r!   rq   rq      s      /2 =L W^  1 1   = =  ;r"   rq   N)r_   
__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   rf   rq   r$   r"   r!   <module>r      sS    H " 6 6 , $ & ) & $2$M M`'% '%T(;d (;r"   