XjdZddlmZddlmZmZmZddlmZddl m Z ddl m Z ddlmZmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZerddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&GddeZ'y)z+|DocumentPart| and closely related objects.) annotations)IO TYPE_CHECKINGcast)Document)RELATIONSHIP_TYPE) CommentsPart) FooterPart HeaderPart) NumberingPart) SettingsPart) StoryPart) StylesPart) InlineShapes) lazyproperty)Comments) WD_STYLE_TYPE)CoreProperties)Settings) BaseStyleceZdZdZdZdZeddZeddZedZ ddZ ddZ dd Z d Z dd Zed Zedd ZddZeddZedZeddZeddZeddZy) DocumentPartaMain document part of a WordprocessingML (WML) package, aka a .docx file. Acts as broker to other parts such as image, core properties, and style parts. It also acts as a convenient delegate when a mid-document object needs a service involving a remote ancestor. The `Parented.part` property inherited by many content objects provides access to this part object for that purpose. ctj|j}|j|tj }||fS)z=Return (footer_part, rId) pair for newly-created footer part.)r newpackage relate_toRTFOOTER)self footer_partrIds g/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/parts/document.pyadd_footer_partzDocumentPart.add_footer_part#3 nnT\\2 nn["))4Cctj|j}|j|tj }||fS)z=Return (header_part, rId) pair for newly-created header part.)r rrrrHEADER)r header_partr!s r"add_header_partzDocumentPart.add_header_part)r$r%c.|jjS)zJ|Comments| object providing access to the comments added to this document.)_comments_partcommentsrs r"r,zDocumentPart.comments/s""+++r%c.|jjS)zfA |CoreProperties| object providing read/write access to the core properties of this document.)rcore_propertiesr-s r"r/zDocumentPart.core_properties4s||+++r%c.t|j|S)zEA |Document| object providing access to the content of this document.)r_elementr-s r"documentzDocumentPart.document:s t,,r%c&|j|y)z/Remove related header part identified by `rId`.N)drop_relrr!s r"drop_header_partzDocumentPart.drop_header_part?s cr%c |j|S)z%Return |FooterPart| related by `rId`. related_partsr5s r"r zDocumentPart.footer_partC!!#&&r%c:|jj||S)zReturn the style in this document matching `style_id`. Returns the default style for `style_type` if `style_id` is |None| or does not match a defined style of `style_type`. )styles get_by_id)rstyle_id style_types r" get_stylezDocumentPart.get_styleGs {{$$Xz::r%c:|jj||S)aTReturn the style_id (|str|) of the style of `style_type` matching `style_or_name`. Returns |None| if the style resolves to the default style for `style_type` or if `style_or_name` is itself |None|. Raises if `style_or_name` is a style of the wrong type or names a style not present in the document. )r< get_style_id)r style_or_namer?s r"rBzDocumentPart.get_style_idOs{{'' zBBr%c |j|S)z%Return |HeaderPart| related by `rId`.r8r5s r"r(zDocumentPart.header_partYr:r%cBt|jj|S)zIThe |InlineShapes| instance containing the inline shapes in the document.)rr1bodyr-s r" inline_shapeszDocumentPart.inline_shapes]sDMM..55r%c tt|jtjS#t $r9tj }|j|tj|cYSwxYw)zA |NumberingPart| object providing access to the numbering definitions for this document. Creates an empty numbering part if one is not present. )rr part_related_byr NUMBERINGKeyErrorrr)rnumbering_parts r"rLzDocumentPart.numbering_partbsX  " t';';BLL'IJ J "*..0N NN>2<< 8! ! "s,/?A10A1c:|jj|y)zSave this document to `path_or_stream`, which can be either a path to a filesystem location (a string) or a file-like object.N)rsave)rpath_or_streams r"rNzDocumentPart.saveos .)r%c.|jjS)zcA |Settings| object providing access to the settings in the settings part of this document.)_settings_partsettingsr-s r"rRzDocumentPart.settingsts""+++r%c.|jjS)z]A |Styles| object providing access to the styles in the styles part of this document.) _styles_partr<r-s r"r<zDocumentPart.styleszs  '''r%c tt|jtjS#t $rR|j Jtj|j }|j|tj|cYSwxYw)zA |CommentsPart| object providing access to the comments added to this document. Creates a default comments part if one is not present. ) rr rIrCOMMENTSrKrdefaultr)r comments_parts r"r+zDocumentPart._comments_partsn  ! d&:&:2;;&GH H !<<+ ++(00>M NN="++ 6  !s,/AB  B c tt|jtjS#t $rDtj |j}|j|tj|cYSwxYw)zA |SettingsPart| object providing access to the document-level settings for this document. Creates a default settings part if one is not present. ) rr rIrSETTINGSrKrWrr)r settings_parts r"rQzDocumentPart._settings_parts^ ! d&:&:2;;&GH H !(00>M NN="++ 6  !s,/A A<;A<c  tt|jtjS#t $rJ|j }|Jtj|}|j|tj|cYSwxYw)zqInstance of |StylesPart| for this document. Creates an empty styles part if one is not present. ) rrrIrSTYLESrKrrWr)rr styles_parts r"rTzDocumentPart._styles_partso   D$8$8$CD D llG& &&$,,W5K NN; 2   s,/ABBN)returnr)r_r)r!strr_None)r!r`)r>z str | Noner?rr_r)r_r )rOzstr | IO[bytes])r_r)r_r )r_r )r_r)__name__ __module__ __qualname____doc__r#r)propertyr,r/r2r6r r@rBr(rrGrLrNrRr<r+rQrTr%r"rrs  ,,,, --';C'66 " "* ,, ((  ! ! ! !  r%rN)(re __future__rtypingrrr docx.documentrdocx.opc.constantsrrdocx.parts.commentsr docx.parts.hdrftrr r docx.parts.numberingr docx.parts.settingsr docx.parts.storyrdocx.parts.stylesr docx.shaper docx.sharedr docx.commentsrdocx.enum.stylerdocx.opc.corepropsr docx.settingsrdocx.styles.stylerrrgr%r"rysO1"**"6,4.,&(#$&-1&+O9Or%