o
    S(                     @   s8   d Z ddlZddlZG dd deZedZedZdS )zd
Provides the PackURI value type along with some useful known pack URI strings
such as PACKAGE_URI.
    Nc                   @   s~   e Zd ZdZedZdd Zedd Z	e
dd Ze
d	d
 Ze
dd Ze
dd Ze
dd Z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]*)?c                 C   s(   |d dksd}t || t| |S )Nr   /z'PackURI must begin with slash, got '%s')
ValueErrorstr__new__)clsZpack_uri_strtmpl r	   @D:\Projects\ConvertPro\env\Lib\site-packages\docx\opc\packuri.pyr      s   zPackURI.__new__c                 C   s   t | |}t |}t|S )z
        Return a |PackURI| instance containing the absolute pack URI formed by
        translating *relative_ref* onto *baseURI*.
        )	posixpathjoinabspathr   )baseURIrelative_refZ
joined_uriZ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   Z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
   filename6   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
   
membernameQ   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
   r   Z   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.relsZ_rels)r   r   r   r   r   )r   Zrels_filenameZrels_uri_strr	   r	   r
   rels_urih   s   
zPackURI.rels_uriN)__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)r*   r   r+   r   r   ZPACKAGE_URIZCONTENT_TYPES_URIr	   r	   r	   r
   <module>   s   h