XjA#dZddlmZddlmZmZmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZdd lmZer dd lmZdd lmZGd d ZGddZGddeZy)zAOpen Packaging Convention (OPC) objects related to package parts.) annotations) TYPE_CHECKINGCallableTypecast)serialize_part_xml)PackURI) Relationships) cls_method_fn parse_xml) lazyproperty)BaseOxmlElement)PackageceZdZdZ d dfd ZdZdZeddZedZ ddZ e ddZ ddd Z ed Zed Zej dd Zdd ZdddZedZedZddZddZxZS)PartzBase class for package parts. Provides common properties and methods, but intended to be subclassed in client code to implement specific part behaviors. cbtt| ||_||_||_||_yN)superr__init__ _partname _content_type_blob_package)selfpartname content_typeblobpackage __class__s a/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/opc/part.pyrz Part.__init__s/ dD"$!)  cy)zEntry point for post-unmarshaling processing, for example to parse the part XML. May be overridden by subclasses without forwarding call to super. Nrs r!after_unmarshalzPart.after_unmarshal) r"cy)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_marshalzPart.before_marshal3r'r"c"|jxsdS)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")rr%s r!rz Part.blob=szz S r"c|jS)zContent type of this part.)rr%s r!rzPart.content_typeFs!!!r"cH|j|dkr|j|=yy)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_countrelsrrIds r!drop_relz Part.drop_relKs'   s #a ' # (r"c|||||Srr$)clsrrrrs r!loadz Part.loadTs8\499r"c>|jj||||S)aReturn 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)rreltypetargetr1 is_externals r!load_relz Part.load_relXsyy))'63 LLr"c|jS)z+|OpcPackage| instance this part belongs to.)rr%s r!rz Part.packagec}}r"c|jS)zX|PackURI| instance holding partname of this part, e.g. '/ppt/slides/slide1.xml'.)rr%s r!rz Part.partnamehs~~r"cxt|ts#d}t|t|jz||_y)Nz.partname must be instance of PackURI, got '%s') isinstancer TypeErrortype__name__r)rrtmpls r!rz Part.partnamens2(G,CDD4>#:#::; ;!r"c8|jj|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)rr8s r!part_related_byzPart.part_related_byusyy**733r"c|r*|jj|tt|S|jj |tt |}|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_relrstr get_or_addrr1)rr9r8r:rels r! relate_tozPart.relate_to~sK 99//c69JK K))&&wT60BCC77Nr"c.|jjS)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!rOzPart.related_partss yy&&&r"cbt|jj|_|jS)zA|Relationships| instance holding the relationships for this part.)r rbaseURI_relsr%s r!r/z Part.relss$#4>>#9#9: zzr"c8|j|}|jS)zGReturn URL contained in target ref of relationship identified by `rId`.)r/ target_ref)rr1rLs r!rTzPart.target_refsiin~~r"cy)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`. rr$r0s r!r.zPart._rel_ref_counts r")NN)rr rrJrz bytes | NonerzPackage | None)returnbytes)r1rJrr rrJrrWrr)F)r8rJr9 Part | strr1rJr:bool)rrJ)r8rJrVr)r9rYr8rJr:rZrVrJ)r1rJrVrJr1rJrVint)rC __module__ __qualname____doc__rr&r)propertyrrr2 classmethodr5r;rrsetterrGrMrOrr/rTr. __classcell__r s@r!rrs""&            !!"":: M __"" 4 ''   r"rc\eZdZUdZded<iZded<eZ d dZe d dZ y) PartFactoryaProvides 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] | Nonepart_class_selectorzdict[str, Type[Part]] part_type_forcd}|jt|d}|||}||j|}|j||||S)Nrg)rgr _part_cls_forr5)r4rrr8rr PartClassrgs r!__new__zPartFactory.__new__sZ(,  " " ."/5J"K +L'BI  )),7I~~h dGDDr"cT||jvr|j|S|jS)zReturn the custom part class registered for `content_type`, or the default part class if no custom class is registered for `content_type`.)rhdefault_part_type)r4rs r!rjzPartFactory._part_cls_fors/ 3,, ,$$\2 2$$$r"N) rr rrJr8rJrrWrr)rrJ) rCr]r^r___annotations__rhrrnrlrarjr$r"r!rfrfsp HG+-M(-EEE E  E  E %%r"rfc~eZdZdZ dfd ZedZedZed dZ edZ d dZ xZ 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@tt| |||||_y)N)r)rrqr_element)rrrelementrr s r!rzXmlPart.__init__s" gt%h g%N r"c,t|jSr)rrsr%s r!rz XmlPart.blobs!$--00r"c|jS)z&The root XML element of this XML part.)rsr%s r!rtzXmlPart.elementr=r"c.t|}|||||Srr )r4rrrrrts r!r5z XmlPart.loadsD/8\7G<K!4!4Y!?@T9TTS[D9::9s AA)rr rrJrtrrrrXr[) rCr]r^r_rr`rrtrar5ryr.rcrds@r!rqrqs   /2 =L W^ 11==;r"rqN)r_ __future__rtypingrrrr docx.opc.oxmlrdocx.opc.packurir docx.opc.relr docx.opc.sharedr docx.oxml.parserr docx.sharedrdocx.oxml.xmlchemyr docx.packagerrrfrqr$r"r!rsSH"66,$&)&$2$MM`'%'%T(;d(;r"