o
    ¿Z2h•  ã                   @  sD   d Z ddlmZ ddlZddlZG dd„ deƒZedƒZedƒZdS )z_Provides the PackURI value type.

Also some useful known pack URI strings such as PACKAGE_URI.
é    )ÚannotationsNc                   @  sˆ   e Zd ZdZe d¡Zddd„Zedd
d„ƒZ	e
ddd„ƒZe
ddd„ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZddd„Ze
dd„ ƒZdS )ÚPackURIz|Provides access to pack URI components such as the baseURI and the filename
    slice.

    Behaves as |str| otherwise.
    z([a-zA-Z]+)([1-9][0-9]*)?Úpack_uri_strÚstrc                 C  s(   |d dkrd}t || ƒ‚t | |¡S )Nr   ú/z'PackURI must begin with slash, got '%s')Ú
ValueErrorr   Ú__new__)Úclsr   Útmpl© r   úa/home/skpark/git/infrasmart_work/infrasmart/venv/lib/python3.10/site-packages/docx/opc/packuri.pyr      s   zPackURI.__new__ÚbaseURIÚrelative_refÚreturnc                 C  s   t  | |¡}t  |¡}t|ƒS )zIThe absolute PackURI formed by translating `relative_ref` onto `baseURI`.)Ú	posixpathÚjoinÚabspathr   )r   r   Ú
joined_uriÚabs_urir   r   r   Úfrom_rel_ref   s   
zPackURI.from_rel_refc                 C  ó   t  | ¡d S )zÐThe base URI of this pack URI, the directory portion, roughly speaking.

        E.g. ``'/ppt/slides'`` for ``'/ppt/slides/slide1.xml'``. For the package pseudo-
        partname '/', baseURI is '/'.
        r   ©r   Úsplit©Úselfr   r   r   r   "   ó   zPackURI.baseURIc                 C  s(   t  | ¡d }| d¡r|dd… S |S )z‡The extension portion of this pack URI, e.g. ``'xml'`` for ``'/word/document.xml'``.

        Note the period is not included.
        é   Ú.N)r   ÚsplitextÚ
startswith)r   Úraw_extr   r   r   Úext+   s   zPackURI.extc                 C  r   )z¯The "filename" portion of this pack URI, e.g. ``'slide1.xml'`` for
        ``'/ppt/slides/slide1.xml'``.

        For the package pseudo-partname '/', filename is ''.
        r   r   r   r   r   r   Úfilename5   r   zPackURI.filenamec                 C  sP   | j }|sdS t |¡d }| j |¡}|du rdS | d¡r&t| d¡ƒS dS )z½Return partname index as integer for tuple partname or None for singleton
        partname, e.g. ``21`` for ``'/ppt/slides/slide21.xml'`` and |None| for
        ``'/ppt/presentation.xml'``.Nr   é   )r"   r   r   Ú_filename_reÚmatchÚgroupÚint)r   r"   Ú	name_partr%   r   r   r   Úidx>   s   
zPackURI.idxc                 C  s   | dd… S )zºThe pack URI with the leading slash stripped off, the form used as the Zip
        file membername for the package item.

        Returns '' for the package pseudo-partname '/'.
        r   Nr   r   r   r   r   Ú
membernameN   s   zPackURI.membernamec                 C  s    |dkr
| dd… S t  | |¡S )zãReturn string containing relative reference to package item from `baseURI`.

        E.g. PackURI('/ppt/slideLayouts/slideLayout1.xml') would return
        '../slideLayouts/slideLayout1.xml' for baseURI '/ppt/slides'.
        r   r   N)r   Úrelpath)r   r   r   r   r   r   W   s    zPackURI.relative_refc                 C  s"   d| j  }t | jd|¡}t|ƒS )z¿The pack URI of the .rels part corresponding to the current pack URI.

        Only produces sensible output if the pack URI is a partname or the package
        pseudo-partname '/'.
        z%s.relsÚ_rels)r"   r   r   r   r   )r   Úrels_filenameÚrels_uri_strr   r   r   Úrels_uria   s   
zPackURI.rels_uriN)r   r   )r   r   r   r   r   r   )r   r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚreÚcompiler$   r   Ústaticmethodr   Úpropertyr   r!   r"   r)   r*   r   r/   r   r   r   r   r      s&    

	




r   r   z/[Content_Types].xml)	r3   Ú
__future__r   r   r4   r   r   ÚPACKAGE_URIÚCONTENT_TYPES_URIr   r   r   r   Ú<module>   s    a