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

$we^ �@s�dZddlmZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZmZddlmZer<dd	lmZGd
d�d�ZGdd
�d
�ZGdd�de�ZdS)zAOpen Packaging Convention (OPC) objects related to package parts.�)�annotations)�
TYPE_CHECKING�Callable�Dict�Type)�serialize_part_xml)�PackURI)�
Relationships)�
cls_method_fn�lazyproperty��	parse_xml)�Packagecs�eZdZdZ		d4d5�fd
d�
Zdd
�Zdd�Zedd��Zedd��Z	d6dd�Z
ed7dd��Zd8dd�Z
edd��Zed d!��Zejd"d!��Zd9d%d&�Zd8d:d*d+�Zed,d-��Zed.d/��Zd0d1�Zd2d3�Z�ZS);�Partz�Base class for package parts.

    Provides common properties and methods, but intended to be subclassed in client code
    to implement specific part behaviors.
    N�partname�str�content_type�blob�bytes | None�package�Package | Nonecs*tt|���||_||_||_||_dS�N)�superr�__init__�	_partname�
_content_type�_blob�_package)�selfrrrr��	__class__��F/home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/part.pyrs

z
Part.__init__cC�dS)z�Entry point for post-unmarshaling processing, for example to parse the part
        XML.

        May be overridden by subclasses without forwarding call to super.
        Nr!�rr!r!r"�after_unmarshal%�zPart.after_unmarshalcCr#)z�Entry 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$r!r!r"�before_marshal/r&zPart.before_marshalcC�|jS)z�Contents 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.
        )rr$r!r!r"r9sz	Part.blobcCr()zContent type of this part.)rr$r!r!r"rB�zPart.content_type�rIdcCs|�|�dkr
|j|=dSdS)z�Remove 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)rr*r!r!r"�drop_relGs�z
Part.drop_rel�bytesrcCs|||||�Srr!)�clsrrrrr!r!r"�loadPsz	Part.loadFcCs|j�||||�S)aReturn newly added |_Relationship| instance of `reltype` between this part
        and `target` 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�targetr*�is_externalr!r!r"�load_relTsz
Part.load_relcCr()z+|OpcPackage| instance this part belongs to.)rr$r!r!r"r^r)zPart.packagecCr()zX|PackURI| instance holding partname of this part, e.g.
        '/ppt/slides/slide1.xml'.)rr$r!r!r"rcsz
Part.partnamecCs*t|t�sd}t|t|�j��||_dS)Nz.partname must be instance of PackURI, got '%s')�
isinstancer�	TypeError�type�__name__r)rr�tmplr!r!r"ris

r3�returncCs|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)rr3r!r!r"�part_related_bypszPart.part_related_byr4r5�boolcCs&|r	|j�||�S|j�||�}|jS)z�Return 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_rel�
get_or_addr*)rr4r3r5�relr!r!r"�	relate_toyszPart.relate_tocCs|jjS)z�Dictionary 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$r!r!r"rD�szPart.related_partscCst|jj�S)zA|Relationships| instance holding the relationships for this part.)r	r�baseURIr$r!r!r"r-�sz	Part.relscCs|j|}|jS)zGReturn URL contained in target ref of relationship identified by `rId`.)r-�
target_ref)rr*rBr!r!r"rF�s
zPart.target_refcs"|j�d�}t�fdd�|D��S)zbReturn the count of references in this part's XML to the relationship
        identified by `rId`.z//@r:idcsg|]}|�kr|�qSr!r!)�.0�_rId�r*r!r"�
<listcomp>�sz'Part._rel_ref_count.<locals>.<listcomp>)�_element�xpath�len)rr*�rIdsr!rIr"r,�szPart._rel_ref_count)NN)rrrrrrrr)r*r)rrrrrr/rr)F)r3rr<r)r4rr3rr5r?r<r)r:�
__module__�__qualname__�__doc__rr%r'�propertyrrr.�classmethodr1r6rr�setterr>rCrDrr-rFr,�
__classcell__r!r!rr"rs:
�





	





	

rc@sBeZdZUdZded<iZded<eZddd�Ze	ddd��Z
dS)�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_selectorzDict[str, Type[Part]]�
part_type_forrrrr3rr/rrcCsDd}|jdurt|d�}|||�}|dur|�|�}|�||||�S)NrW)rWr
�
_part_cls_forr1)r0rrr3rr�	PartClassrWr!r!r"�__new__�s



zPartFactory.__new__cCs||jvr
|j|S|jS)z�Return the custom part class registered for `content_type`, or the default
        part class if no custom class is registered for `content_type`.)rX�default_part_type)r0rr!r!r"rY�s

zPartFactory._part_cls_forN)
rrrrr3rrr/rr)rr)r:rOrPrQ�__annotations__rXrr\r[rSrYr!r!r!r"rV�s

rVcsPeZdZdZ�fdd�Zedd��Zedd��Zedd	��Z	ed
d��Z
�ZS)�XmlPartz�Base 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.
    cs tt|�j|||d�||_dS)N)r)rr^rrK)rrr�elementrrr!r"r�s
zXmlPart.__init__cCs
t|j�Sr)rrKr$r!r!r"r�s
zXmlPart.blobcCr()z&The root XML element of this XML part.)rKr$r!r!r"r_�r)zXmlPart.elementcCst|�}|||||�Srr)r0rrrrr_r!r!r"r1�szXmlPart.loadcCs|S)z�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.
        r!r$r!r!r"�part�szXmlPart.part)r:rOrPrQrrRrr_rSr1r`rUr!r!rr"r^�s


r^N)rQ�
__future__r�typingrrrr�
docx.opc.oxmlr�docx.opc.packurir�docx.opc.relr	�docx.opc.sharedr
r�docx.oxml.parserr
�docx.packagerrrVr^r!r!r!r"�<module>s
*