a
    ]øj  ã                   @  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rà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& 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ddœdd	„ƒZed
dœdd„ƒZedd„ ƒZ	dddœdd„Z
ddœdd„Zddddœdd„Zdd„ Zddœdd „Zed!d"„ ƒZed#dœd$d%„ƒZd&d'œd(d)„Zed*dœd+d,„ƒZed-d.„ ƒZed/dœd0d1„ƒZed2dœd3d4„ƒZed5dœd6d7„ƒZd8S )9Ú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  s"   t  | j¡}|  |tj¡}||fS )z=Return (footer_part, rId) pair for newly-created footer part.)r	   ÚnewÚpackageÚ	relate_toÚRTZFOOTER)ÚselfÚfooter_partÚrId© r   úO/var/www/html/assistant/venv/lib/python3.9/site-packages/docx/parts/document.pyÚadd_footer_part#   s    zDocumentPart.add_footer_partc                 C  s"   t  | j¡}|  |tj¡}||fS )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)   s    zDocumentPart.add_header_partr   )Úreturnc                 C  s   | 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  s   | j jS )zfA |CoreProperties| object providing read/write access to the core properties
        of this document.)r   Úcore_propertiesr'   r   r   r   r(   4   s    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.documentÚstrÚNone)r   r$   c                 C  s   |   |¡ dS )z/Remove related header part identified by `rId`.N)Zdrop_rel©r   r   r   r   r   Údrop_header_part?   s    zDocumentPart.drop_header_part)r   c                 C  s
   | j | S )z%Return |FooterPart| related by `rId`.©Zrelated_partsr-   r   r   r   r   C   s    zDocumentPart.footer_partz
str | Noner   r   )Ústyle_idÚ
style_typer$   c                 C  s   | 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`.
        )ÚstylesZ	get_by_id)r   r0   r1   r   r   r   Ú	get_styleG   s    zDocumentPart.get_stylec                 C  s   | j  ||¡S )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.
        )r2   Úget_style_id)r   Zstyle_or_namer1   r   r   r   r4   O   s    zDocumentPart.get_style_idc                 C  s
   | j | S )z%Return |HeaderPart| related by `rId`.r/   r-   r   r   r   r"   Y   s    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  sF   zt t|  tj¡ƒW S  ty@   t ¡ }|  |tj¡ | Y S 0 dS )z¢A |NumberingPart| object providing access to the numbering definitions for this document.

        Creates an empty numbering part if one is not present.
        N)r   r   Úpart_related_byr   Z	NUMBERINGÚKeyErrorr   r   )r   Únumbering_partr   r   r   r9   b   s    zDocumentPart.numbering_partzstr | IO[bytes])Úpath_or_streamc                 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   r:   r   r   r   r;   o   s    zDocumentPart.saver   c                 C  s   | j jS )zcA |Settings| object providing access to the settings in the settings part of
        this document.)Ú_settings_partÚsettingsr'   r   r   r   r=   t   s    zDocumentPart.settingsc                 C  s   | j jS )z]A |Styles| object providing access to the styles in the styles part of this
        document.)Ú_styles_partr2   r'   r   r   r   r2   z   s    zDocumentPart.stylesr   c                 C  sX   zt t|  tj¡ƒW S  tyR   | jdus0J ‚t | j¡}|  |tj¡ | Y S 0 dS )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   r7   r   ZCOMMENTSr8   r   Údefaultr   )r   Zcomments_partr   r   r   r%   €   s    zDocumentPart._comments_partr   c                 C  sJ   zt t|  tj¡ƒW S  tyD   t | j¡}|  |tj¡ | Y S 0 dS )z«A |SettingsPart| object providing access to the document-level settings for
        this document.

        Creates a default settings part if one is not present.
        N)	r   r   r7   r   ZSETTINGSr8   r?   r   r   )r   Zsettings_partr   r   r   r<   Ž   s    zDocumentPart._settings_partr   c                 C  sZ   zt t|  tj¡ƒW S  tyT   | j}|dus4J ‚t |¡}|  |tj¡ | Y S 0 dS )zqInstance of |StylesPart| for this document.

        Creates an empty styles part if one is not present.
        N)	r   r   r7   r   ÚSTYLESr8   r   r?   r   )r   r   Zstyles_partr   r   r   r>   œ   s    
zDocumentPart._styles_partN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r#   Úpropertyr&   r(   r*   r.   r   r3   r4   r"   r   r6   r9   r;   r=   r2   r%   r<   r>   r   r   r   r   r      s:   



r   N)(rD   Ú
__future__r   Útypingr   r   r   Zdocx.documentr   Zdocx.opc.constantsr   r   Zdocx.parts.commentsr   Zdocx.parts.hdrftrr	   r
   Zdocx.parts.numberingr   Zdocx.parts.settingsr   Zdocx.parts.storyr   Zdocx.parts.stylesr   Z
docx.shaper   Zdocx.sharedr   Zdocx.commentsr   Zdocx.enum.styler   Zdocx.opc.corepropsr   Zdocx.settingsr   Zdocx.styles.styler   r   r   r   r   r   Ú<module>   s&   