o
    ýÞh¥  ã                   @   sˆ   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 G dd„ dƒZ
G dd	„ d	ƒZG d
d„ de
ƒZG dd„ de
ƒZG dd„ deƒZdS )zMProvides a general interface to a `physical` OPC package, such as a zip file.é    N)ÚZIP_DEFLATEDÚZipFileÚ
is_zipfile)ÚPackageNotFoundError)ÚCONTENT_TYPES_URIc                       ó    e Zd ZdZ‡ fdd„Z‡  ZS )ÚPhysPkgReaderz,Factory for physical package reader objects.c                    sJ   t |tƒrtj |¡rt}nt|ƒrt}ntd| ƒ‚t}t	t
| ƒ |¡S )NzPackage not found at '%s')Ú
isinstanceÚstrÚosÚpathÚisdirÚ_DirPkgReaderr   Ú_ZipPkgReaderr   Úsuperr   Ú__new__)ÚclsÚpkg_fileÚ
reader_cls©Ú	__class__© úQ/var/www/html/premium_crap/venv/lib/python3.10/site-packages/docx/opc/phys_pkg.pyr      s   
zPhysPkgReader.__new__©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r   
   ó    r   c                       r   )ÚPhysPkgWriterz,Factory for physical package writer objects.c                    s   t t| ƒ t¡S )N)r   r    r   Ú_ZipPkgWriter)r   r   r   r   r   r      s   zPhysPkgWriter.__new__r   r   r   r   r   r       r   r    c                       óD   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zedd	„ ƒZd
d„ Z	‡  Z
S )r   zWImplements |PhysPkgReader| interface for an OPC package extracted into a
    directory.c                    s    t t| ƒ ¡  tj |¡| _dS )zA`path` is the path to a directory containing an expanded package.N)r   r   Ú__init__r   r   ÚabspathÚ_path)Úselfr   r   r   r   r#   '   s   z_DirPkgReader.__init__c                 C   sJ   t j | j|j¡}t|dƒ�}| ¡ }W d  ƒ |S 1 sw   Y  |S )zIReturn contents of file corresponding to `pack_uri` in package directory.ÚrbN)r   r   Újoinr%   Ú
membernameÚopenÚread)r&   Úpack_urir   ÚfÚblobr   r   r   Úblob_for,   s   

ÿþz_DirPkgReader.blob_forc                 C   s   dS )z|Provides interface consistency with |ZipFileSystem|, but does nothing, a
        directory file system doesn't need closing.Nr   ©r&   r   r   r   Úclose3   s   z_DirPkgReader.closec                 C   ó
   |   t¡S )z7Return the `[Content_Types].xml` blob from the package.©r/   r   r0   r   r   r   Úcontent_types_xml8   ó   
z_DirPkgReader.content_types_xmlc                 C   ó,   z	|   |j¡}W |S  ty   d}Y |S w )z`Return rels item XML for source with `source_uri`, or None if the item has no
        rels item.N)r/   Úrels_uriÚIOError©r&   Ú
source_uriÚrels_xmlr   r   r   Úrels_xml_for=   ó   þþz_DirPkgReader.rels_xml_for©r   r   r   r   r#   r/   r1   Úpropertyr4   r<   r   r   r   r   r   r   #   s    
r   c                       r"   )r   z@Implements |PhysPkgReader| interface for a zip file OPC package.c                    s   t t| ƒ ¡  t|dƒ| _d S )NÚr)r   r   r#   r   Ú_zipf©r&   r   r   r   r   r#   J   s   z_ZipPkgReader.__init__c                 C   s   | j  |j¡S )zReturn blob corresponding to `pack_uri`.

        Raises |ValueError| if no matching member is present in zip archive.
        )rA   r+   r)   )r&   r,   r   r   r   r/   N   s   z_ZipPkgReader.blob_forc                 C   ó   | j  ¡  dS )z;Close the zip archive, releasing any resources it is using.N©rA   r1   r0   r   r   r   r1   U   s   z_ZipPkgReader.closec                 C   r2   )z;Return the `[Content_Types].xml` blob from the zip package.r3   r0   r   r   r   r4   Y   r5   z_ZipPkgReader.content_types_xmlc                 C   r6   )z]Return rels item XML for source with `source_uri` or None if no rels item is
        present.N)r/   r7   ÚKeyErrorr9   r   r   r   r<   ^   r=   z_ZipPkgReader.rels_xml_forr>   r   r   r   r   r   G   s    
r   c                       s0   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )r!   z@Implements |PhysPkgWriter| interface for a zip file OPC package.c                    s"   t t| ƒ ¡  t|dtd�| _d S )NÚw)Úcompression)r   r!   r#   r   r   rA   rB   r   r   r   r#   k   s   z_ZipPkgWriter.__init__c                 C   rC   )zkClose the zip archive, flushing any pending physical writes and releasing any
        resources it's using.NrD   r0   r   r   r   r1   o   s   z_ZipPkgWriter.closec                 C   s   | j  |j|¡ dS )zYWrite `blob` to this zip package with the membername corresponding to
        `pack_uri`.N)rA   Úwritestrr)   )r&   r,   r.   r   r   r   Úwritet   s   z_ZipPkgWriter.write)r   r   r   r   r#   r1   rI   r   r   r   r   r   r!   h   s
    r!   )r   r   Úzipfiler   r   r   Údocx.opc.exceptionsr   Údocx.opc.packurir   r   r    r   r   r!   r   r   r   r   Ú<module>   s    $!