File: //home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/__pycache__/packuri.cpython-310.pyc
o
$we| � @ s8 d Z ddlZddlZG dd� de�Zed�Zed�ZdS )z_Provides the PackURI value type.
Also some useful known pack URI strings such as PACKAGE_URI.
� Nc @ s~ e Zd ZdZe�d�Zdd� Zedd� �Z e
dd� �Ze
d d
� �Ze
dd� �Z
e
d
d� �Ze
dd� �Zdd� Ze
dd� �ZdS )�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 dkrd}t || ��t�| |�S )Nr �/z'PackURI must begin with slash, got '%s')�
ValueError�str�__new__)�cls�pack_uri_str�tmpl� r
�I/home/arjun/projects/env/lib/python3.10/site-packages/docx/opc/packuri.pyr s zPackURI.__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_ref�
joined_uri�abs_urir
r
r �from_rel_ref s
zPackURI.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 ! � zPackURI.baseURIc C s( t �| �d }|�d�r|dd� 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 zPackURI.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 zPackURI.filenamec C sP | j }|sdS t�|�d }| j�|�}|du rdS |�d�r&t|�d��S dS )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>