B
    ‹°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	   úB/var/www/html/venv/lib/python3.7/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   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 )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   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	   r
   Úfilename6   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
   Ú
membernameQ   s    zPackURI.membernamec             C   s&   |dkr| dd… }n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