U
    cqe|  ã                   @   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 )z_Provides the PackURI value type.

Also 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rd}t || ƒ‚t | |¡S )Nr   ú/z'PackURI must begin with slash, got '%s')Ú
ValueErrorÚstrÚ__new__)ÚclsZpack_uri_strÚtmpl© r	   ú4/tmp/pip-unpacked-wheel-gx5hpqp3/docx/opc/packuri.pyr      s    zPackURI.__new__c                 C   s   t  | |¡}t  |¡}t|ƒS )zyReturn 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   s   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   !   s    zPackURI.baseURIc                 C   s(   t  | ¡d }| d¡r$|dd… S |S )zThe 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   s   t  | ¡d S )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   s    zPackURI.filenamec                 C   sP   | j }|sdS t |¡d }| j |¡}|dkr4dS | d¡rLt| 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   Z	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.relsZ_rels)r   r   r   r   r   )r   Zrels_filenameZrels_uri_strr	   r	   r
   Úrels_uria   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
   c