o
    ýÞh  ã                   @  sô   d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ erpddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& G dd„ deƒZ'dS )z+|DocumentPart| and closely related objects.é    )Úannotations)ÚIOÚTYPE_CHECKINGÚcast)ÚDocument)ÚRELATIONSHIP_TYPE)ÚCommentsPart)Ú
FooterPartÚ
HeaderPart)ÚNumberingPart)ÚSettingsPart)Ú	StoryPart)Ú
StylesPart)ÚInlineShapes)Úlazyproperty)ÚComments)ÚWD_STYLE_TYPE)ÚCoreProperties)ÚSettings)Ú	BaseStylec                   @  sà   e Zd ZdZdd„ Zdd„ Zed9dd	„ƒZed:dd„ƒZedd„ ƒZ	d;dd„Z
d<dd„Zd=dd„Zdd„ Zd<dd „Zed!d"„ ƒZed>d$d%„ƒZd?d(d)„Zed@d+d,„ƒZed-d.„ ƒZedAd0d1„ƒZedBd3d4„ƒZedCd6d7„ƒZd8S )DÚDocumentParta‘  Main 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.
    c                 C  ó"   t  | j¡}|  |tj¡}||fS )z=Return (footer_part, rId) pair for newly-created footer part.)r	   ÚnewÚpackageÚ	relate_toÚRTÚFOOTER)ÚselfÚfooter_partÚrId© r    úS/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/parts/document.pyÚadd_footer_part#   ó   zDocumentPart.add_footer_partc                 C  r   )z=Return (header_part, rId) pair for newly-created header part.)r
   r   r   r   r   ÚHEADER)r   Úheader_partr   r    r    r!   Úadd_header_part)   r#   zDocumentPart.add_header_partÚreturnr   c                 C  ó   | j jS )zJ|Comments| object providing access to the comments added to this document.)Ú_comments_partÚcomments©r   r    r    r!   r*   /   s   zDocumentPart.commentsr   c                 C  r(   )zfA |CoreProperties| object providing read/write access to the core properties
        of this document.)r   Úcore_propertiesr+   r    r    r!   r,   4   ó   zDocumentPart.core_propertiesc                 C  s   t | j| ƒS )zEA |Document| object providing access to the content of this document.)r   Ú_elementr+   r    r    r!   Údocument:   s   zDocumentPart.documentr   ÚstrÚNonec                 C  s   |   |¡ dS )z/Remove related header part identified by `rId`.N)Údrop_rel©r   r   r    r    r!   Údrop_header_part?   s   zDocumentPart.drop_header_partc                 C  ó
   | j | S )z%Return |FooterPart| related by `rId`.©Úrelated_partsr3   r    r    r!   r   C   ó   
zDocumentPart.footer_partÚstyle_idú
str | NoneÚ
style_typer   r   c                 C  ó   | j  ||¡S )zÆReturn 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)r   r9   r;   r    r    r!   Ú	get_styleG   s   zDocumentPart.get_stylec                 C  r<   )aT  Return 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;   r    r    r!   r@   O   s   zDocumentPart.get_style_idc                 C  r5   )z%Return |HeaderPart| related by `rId`.r6   r3   r    r    r!   r%   Y   r8   zDocumentPart.header_partc                 C  s   t | jj| ƒS )zIThe |InlineShapes| instance containing the inline shapes in the document.)r   r.   Úbodyr+   r    r    r!   Úinline_shapes]   s   zDocumentPart.inline_shapesr   c                 C  sB   z
t t|  tj¡ƒW S  ty    t ¡ }|  |tj¡ | Y S w )z¢A |NumberingPart| object providing access to the numbering definitions for this document.

        Creates an empty numbering part if one is not present.
        )r   r   Úpart_related_byr   Ú	NUMBERINGÚKeyErrorr   r   )r   Únumbering_partr    r    r!   rG   b   s   ýzDocumentPart.numbering_partÚpath_or_streamústr | IO[bytes]c                 C  s   | j  |¡ dS )z…Save this document to `path_or_stream`, which can be either a path to a
        filesystem location (a string) or a file-like object.N)r   Úsave)r   rH   r    r    r!   rJ   o   s   zDocumentPart.saver   c                 C  r(   )zcA |Settings| object providing access to the settings in the settings part of
        this document.)Ú_settings_partÚsettingsr+   r    r    r!   rL   t   r-   zDocumentPart.settingsc                 C  r(   )z]A |Styles| object providing access to the styles in the styles part of this
        document.)Ú_styles_partr=   r+   r    r    r!   r=   z   r-   zDocumentPart.stylesr   c                 C  sT   z
t t|  tj¡ƒW S  ty)   | jdusJ ‚t | j¡}|  |tj¡ | Y S w )z™A |CommentsPart| object providing access to the comments added to this document.

        Creates a default comments part if one is not present.
        N)	r   r   rD   r   ÚCOMMENTSrF   r   Údefaultr   )r   Úcomments_partr    r    r!   r)   €   s   üzDocumentPart._comments_partr   c                 C  sF   z
t t|  tj¡ƒW S  ty"   t | j¡}|  |tj¡ | Y S w )z«A |SettingsPart| object providing access to the document-level settings for
        this document.

        Creates a default settings part if one is not present.
        )	r   r   rD   r   ÚSETTINGSrF   rO   r   r   )r   Úsettings_partr    r    r!   rK   Ž   s   ýzDocumentPart._settings_partr   c                 C  sV   z
t t|  tj¡ƒW S  ty*   | j}|dusJ ‚t |¡}|  |tj¡ | Y S w )zqInstance of |StylesPart| for this document.

        Creates an empty styles part if one is not present.
        N)	r   r   rD   r   ÚSTYLESrF   r   rO   r   )r   r   Ústyles_partr    r    r!   rM   œ   s   
ûzDocumentPart._styles_partN)r'   r   )r'   r   )r   r0   r'   r1   )r   r0   )r9   r:   r;   r   r'   r   )r'   r   )rH   rI   )r'   r   )r'   r   )r'   r   )r'   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r"   r&   Úpropertyr*   r,   r/   r4   r   r?   r@   r%   r   rC   rG   rJ   rL   r=   r)   rK   rM   r    r    r    r!   r      s<    








r   N)(rX   Ú
__future__r   Útypingr   r   r   Údocx.documentr   Údocx.opc.constantsr   r   Údocx.parts.commentsr   Údocx.parts.hdrftrr	   r
   Údocx.parts.numberingr   Údocx.parts.settingsr   Údocx.parts.storyr   Údocx.parts.stylesr   Ú
docx.shaper   Údocx.sharedr   Údocx.commentsr   Údocx.enum.styler   Údocx.opc.corepropsr   Údocx.settingsr   Údocx.styles.styler   r   r    r    r    r!   Ú<module>   s(    