o
    W_                     @   s   d Z ddlmZmZmZ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 G dd deZdS )z*|DocumentPart| and closely related objects    )absolute_importdivisionprint_functionunicode_literals)Document)RELATIONSHIP_TYPE)
FooterPart
HeaderPart)NumberingPart)SettingsPart)BaseStoryPart)
StylesPart)InlineShapes)lazypropertyc                   @   s   e Zd ZdZdd Zdd Zedd Zedd	 Zd
d Z	dd Z
dd Zdd Zdd Zedd Zedd Zdd Zedd Zedd Zedd Zed d! Zd"S )#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RTZFOOTER)selffooter_partrId r   CD:\Projects\ConvertPro\env\Lib\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_partc                 C      | j jS )zx
        A |CoreProperties| object providing read/write access to the core
        properties of this document.
        )r   core_propertiesr   r   r   r   r!   '      zDocumentPart.core_propertiesc                 C   s   t | j| S )zW
        A |Document| object providing access to the content of this document.
        )r   _elementr"   r   r   r   document/   s   zDocumentPart.documentc                 C   s   |  | dS )z/Remove related header part identified by *rId*.N)Zdrop_relr   r   r   r   r   drop_header_part6   s   zDocumentPart.drop_header_partc                 C   
   | j | S )z%Return |FooterPart| related by *rId*.Zrelated_partsr&   r   r   r   r   :      
zDocumentPart.footer_partc                 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*.
        )stylesZ	get_by_id)r   Zstyle_id
style_typer   r   r   	get_style>      zDocumentPart.get_stylec                 C   r+   )a\  
        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   Zstyle_or_namer-   r   r   r   r0   F   s   zDocumentPart.get_style_idc                 C   r(   )z%Return |HeaderPart| related by *rId*.r)   r&   r   r   r   r   P   r*   zDocumentPart.header_partc                 C   s   t | jj| S )zc
        The |InlineShapes| instance containing the inline shapes in the
        document.
        )r   r$   bodyr"   r   r   r   inline_shapesT   r/   zDocumentPart.inline_shapesc                 C   s<   z|  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.
        )part_related_byr   Z	NUMBERINGKeyErrorr
   r   r   )r   numbering_partr   r   r   r5   \   s   zDocumentPart.numbering_partc                 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   Zpath_or_streamr   r   r   r6   j   s   zDocumentPart.savec                 C   r    )zu
        A |Settings| object providing access to the settings in the settings
        part of this document.
        )_settings_partsettingsr"   r   r   r   r8   q   r#   zDocumentPart.settingsc                 C   r    )zo
        A |Styles| object providing access to the styles in the styles part
        of this document.
        )_styles_partr,   r"   r   r   r   r,   y   r#   zDocumentPart.stylesc                 C   @   z|  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.
        )r3   r   ZSETTINGSr4   r   defaultr   r   )r   Zsettings_partr   r   r   r7      s   zDocumentPart._settings_partc                 C   r:   )zy
        Instance of |StylesPart| for this document. Creates an empty styles
        part if one is not present.
        )r3   r   ZSTYLESr4   r   r;   r   r   )r   Zstyles_partr   r   r   r9      s   zDocumentPart._styles_partN)__name__
__module____qualname____doc__r   r   propertyr!   r%   r'   r   r.   r0   r   r   r2   r5   r6   r8   r,   r7   r9   r   r   r   r   r      s4    







r   N)r?   Z
__future__r   r   r   r   Zdocx.documentr   Zdocx.opc.constantsr   r   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   r   r   r   r   r   <module>   s   