XjdZddlmZddlmZmZddlmZddlm Z ddl m Z ddl mZddlmZdd lmZGd d e ZGd d Zy)z3WordprocessingML Package class and related objects.) annotations)IOcast)Image)RELATIONSHIP_TYPE) OpcPackagePackURI) ImagePart) lazypropertyc6eZdZdZdZddZeddZdZy) Packagez6Customizations specific to a WordprocessingML package.c$|jy)zCalled by loading code after all parts and relationships have been loaded. This method affords the opportunity for any required post-processing. N)_gather_image_partsselfs `/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/package.pyafter_unmarshalzPackage.after_unmarshals   "c8|jj|S)zReturn |ImagePart| containing image specified by `image_descriptor`. The image-part is newly created if a matching one is not already present in the collection. ) image_partsget_or_add_image_part)rimage_descriptors rrzPackage.get_or_add_image_parts 556FGGrctS)z0|ImageParts| collection object for this package.) ImagePartsrs rrzPackage.image_parts!s |rc|jD]u}|jr|jtjk7r.|j |j vrG|j jtd|j wy)zCLoad the image part collection with all the image parts in package.r N) iter_rels is_externalreltypeRTIMAGE target_partrappendr)rrels rrzPackage._gather_image_parts&sk>># HC{{bhh&$"2"22    # #Dcoo$F G HrNrzstr | IO[bytes]returnr )r&r) __name__ __module__ __qualname____doc__rrr rrrrrrs*@#H HrrcReZdZdZdZd dZdZdZd dZddZ ddZ dd Z dd Z y )rzICollection of |ImagePart| objects corresponding to images in the package.cg|_yN) _image_partsrs r__init__zImageParts.__init__5s -/rc8|jj|Sr.)r/ __contains__ritems rr2zImageParts.__contains__8s  --d33rc6|jjSr.)r/__iter__rs rr6zImageParts.__iter__;s  ))++rc6|jjSr.)r/__len__rs rr8zImageParts.__len__>s  ((**rc:|jj|yr.)r/r#r3s rr#zImageParts.appendAs   &rctj|}|j|j}||S|j |S)zReturn |ImagePart| object containing image identified by `image_descriptor`. The image-part is newly created if a matching one is not present in the collection. )r from_file _get_by_sha1sha1_add_image_part)rrimagematching_image_parts rrz ImageParts.get_or_add_image_partDsE  01"// ;  *& &##E**rc|j|j}tj||}|j ||S)zVReturn |ImagePart| instance newly created from `image` and appended to the collection.)_next_image_partnameextr from_imager#)rr?partname image_parts rr>zImageParts._add_image_partPs:,,UYY7))%:  JrcL|jD]}|j|k(s|cSy)zlReturn the image part in this collection having a SHA1 hash matching `sha1`, or |None| if not found.N)r/r=)rr=rFs rr<zImageParts._get_by_sha1Ws0++ "J$&!! "rcdfd }|Dcgc]}|jj}}tdt|dzD]}||vs||cS|t|dzScc}w)zThe next available image partname, starting from ``/word/media/image1.{ext}`` where unused numbers are reused. The partname is unique by number, without regard to the extension. `ext` does not include the leading period. c$td|fzS)Nz/word/media/image%d.%sr )nrCs rimage_partnamez7ImageParts._next_image_partname..image_partnamegs3q#h>? ?r)rJintr&r )rEidxrangelen)rrCrKrF used_numbersrJs ` rrBzImageParts._next_image_partname_sx @CGGJ ++//G Gq#d)a-( )A $%a(( )c$i!m,, HsA*N)r4object)r4r r%)r?r)r=strr&zImagePart | None)rCrSr&r ) r'r(r)r*r0r2r6r8r#rr>r<rBr+rrrr2s2S04,+' +-rrN)r* __future__rtypingrrdocx.image.imagerdocx.opc.constantsrr docx.opc.packagerdocx.opc.packurir docx.parts.imager docx.sharedr rrr+rrr\s99""6'$&$ Hj HF<-<-r