;idZddlmZddlmZmZddlmZddlm Z ddl m Z ddl mZddlmZdd lmZGd d e ZGd d ZdS)z3WordprocessingML Package class and related objects.) annotations)IOcast)Image)RELATIONSHIP_TYPE) OpcPackagePackURI) ImagePart) lazypropertyc>eZdZdZdZd dZed d Zd Zd S)Packagez6Customizations specific to a WordprocessingML package.c.|dS)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 @C:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\docx/package.pyafter_unmarshalzPackage.after_unmarshals   """""image_descriptorstr | IO[bytes]returnr c6|j|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)rrs rrzPackage.get_or_add_image_parts 556FGGGr ImagePartsctS)z0|ImageParts| collection object for this package.)rrs rrzPackage.image_parts!s||rc|D]\}|jr |jtjkr |j|jvr/|jtd|j]dS)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&s>>## H HC {bh&&$"222   # #Dco$F$F G G G G H HrNrrrr )rr) __name__ __module__ __qualname____doc__rrr rrrrrrsu@@###HHHH\ H H H H HrrcTeZdZdZdZddZdZdZdd Zdd Z ddZ ddZ ddZ dS)rzICollection of |ImagePart| objects corresponding to images in the package.cg|_dSN) _image_partsrs r__init__zImageParts.__init__5s-/ritemobjectc6|j|Sr/)r0 __contains__rr2s rr5zImageParts.__contains__8s --d333rc4|jSr/)r0__iter__rs rr8zImageParts.__iter__;s ))+++rc4|jSr/)r0__len__rs rr:zImageParts.__len__>s ((***rr c:|j|dSr/)r0r%r6s rr%zImageParts.appendAs   &&&&&rrrrctj|}||j}||S||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_partDsJ  011"// ;;  *& &##E***rrArc||j}tj||}|||S)zVReturn |ImagePart| instance newly created from `image` and appended to the collection.)_next_image_partnameextr from_imager%)rrApartname image_parts rr@zImageParts._add_image_partPsA,,UY77)%::  Jrr?strImagePart | Nonec8|jD]}|j|kr|cSdS)zlReturn the image part in this collection having a SHA1 hash matching `sha1`, or |None| if not found.N)r0r?)rr?rHs rr>zImageParts._get_by_sha1Ws9+ " "J$&&!!!!'trrEr cdfd }d|D}tdt|dzD]}||vr ||cS|t|dzS) 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. nintrr c,td|fzS)Nz/word/media/image%d.%sr )rMrEs rimage_partnamez7ImageParts._next_image_partname..image_partnamegs3q#h>?? ?rc&g|]}|jjSr,)rGidx).0rHs r z3ImageParts._next_image_partname..jsGGGJ +/GGGr)rMrNrr )rangelen)rrErP used_numbersrMs ` rrDzImageParts._next_image_partname_s @ @ @ @ @ @HG$GGG q#d))a-(( ) )A $$%~a(((((%~c$ii!m,,,rN)r2r3)r2r r')rAr)r?rIrrJ)rErIrr ) r(r)r*r+r1r5r8r:r%rr@r>rDr,rrrr2sSS0004444,,,+++'''' + + + +------rrN)r+ __future__rtypingrrdocx.image.imagerdocx.opc.constantsrr"docx.opc.packagerdocx.opc.packurir docx.parts.imager docx.sharedr rrr,rrras99""""""""""""666666''''''$$$$$$&&&&&&$$$$$$ H H H H Hj H H HF<-<-<-<-<-<-<-<-<-<-r