
    h                         S r SSKrSSKJrJrJr  SSKJr  SSKJ	r	   " S S5      r
 " S S	5      r " S
 S\
5      r " S S\
5      r " S S\5      rg)zMProvides a general interface to a `physical` OPC package, such as a zip file.    N)ZIP_DEFLATEDZipFile
is_zipfile)PackageNotFoundError)CONTENT_TYPES_URIc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )PhysPkgReader
   z,Factory for physical package reader objects.c                    > [        U[        5      (       aP  [        R                  R	                  U5      (       a  [
        nO+[        U5      (       a  [        nO[        SU-  5      e[        n[        [        U ]/  U5      $ )NzPackage not found at '%s')
isinstancestrospathisdir_DirPkgReaderr   _ZipPkgReaderr   superr	   __new__)clspkg_file
reader_cls	__class__s      C/var/www/html/env/lib/python3.13/site-packages/docx/opc/phys_pkg.pyr   PhysPkgReader.__new__   s`    h$$ww}}X&&*
H%%*
*+F+QRR&J]C0<<     __name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__r   s   @r   r	   r	   
   s    6= =r   r	   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )PhysPkgWriter   z,Factory for physical package writer objects.c                 2   > [         [        U ]  [        5      $ )N)r   r'   r   _ZipPkgWriter)r   r   r   s     r   r   PhysPkgWriter.__new__   s    ]C0??r   r   r   r%   s   @r   r'   r'      s    6@ @r   r'   c                   N   ^  \ rS rSrSrU 4S jrS rS r\S 5       r	S r
SrU =r$ )	r   #   zSImplements |PhysPkgReader| interface for an OPC package extracted into a
directory.c                 r   > [         [        U ]  5         [        R                  R                  U5      U l        g)zA`path` is the path to a directory containing an expanded package.N)r   r   __init__r   r   abspath_path)selfr   r   s     r   r/   _DirPkgReader.__init__'   s$    mT+-WW__T*
r   c                     [         R                  R                  U R                  UR                  5      n[        US5       nUR                  5       nSSS5        U$ ! , (       d  f       W$ = f)zIReturn contents of file corresponding to `pack_uri` in package directory.rbN)r   r   joinr1   
membernameopenread)r2   pack_urir   fblobs        r   blob_for_DirPkgReader.blob_for,   sO    ww||DJJ(;(;<$668D  s   A
A+c                     g)ztProvides interface consistency with |ZipFileSystem|, but does nothing, a
directory file system doesn't need closing.Nr   r2   s    r   close_DirPkgReader.close3   s     	r   c                 ,    U R                  [        5      $ )z7Return the `[Content_Types].xml` blob from the package.r=   r   r@   s    r   content_types_xml_DirPkgReader.content_types_xml8        }}.//r   c                 d     U R                  UR                  5      nU$ ! [         a    Sn U$ f = f)zXReturn rels item XML for source with `source_uri`, or None if the item has no
rels item.N)r=   rels_uriIOErrorr2   
source_urirels_xmls      r   rels_xml_for_DirPkgReader.rels_xml_for=   s=    	}}Z%8%89H   	H	    //)r1   r   r   r    r!   r"   r/   r=   rA   propertyrE   rN   r#   r$   r%   s   @r   r   r   #   s5    +

 0 0 r   r   c                   N   ^  \ rS rSrSrU 4S jrS rS r\S 5       r	S r
SrU =r$ )	r   G   z@Implements |PhysPkgReader| interface for a zip file OPC package.c                 L   > [         [        U ]  5         [        US5      U l        g )Nr)r   r   r/   r   _zipfr2   r   r   s     r   r/   _ZipPkgReader.__init__J   s    mT+-Xs+
r   c                 L    U R                   R                  UR                  5      $ )zoReturn blob corresponding to `pack_uri`.

Raises |ValueError| if no matching member is present in zip archive.
)rW   r9   r7   )r2   r:   s     r   r=   _ZipPkgReader.blob_forN   s    
 zzx2233r   c                 8    U R                   R                  5         g)z;Close the zip archive, releasing any resources it is using.NrW   rA   r@   s    r   rA   _ZipPkgReader.closeU   s    

r   c                 ,    U R                  [        5      $ )z;Return the `[Content_Types].xml` blob from the zip package.rD   r@   s    r   rE   _ZipPkgReader.content_types_xmlY   rG   r   c                 d     U R                  UR                  5      nU$ ! [         a    Sn U$ f = f)zUReturn rels item XML for source with `source_uri` or None if no rels item is
present.N)r=   rI   KeyErrorrK   s      r   rN   _ZipPkgReader.rels_xml_for^   s=    	}}Z%8%89H   	H	rP   rW   rQ   r%   s   @r   r   r   G   s3    J,4 0 0 r   r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )r*   h   z@Implements |PhysPkgWriter| interface for a zip file OPC package.c                 R   > [         [        U ]  5         [        US[        S9U l        g )Nw)compression)r   r*   r/   r   r   rW   rX   s     r   r/   _ZipPkgWriter.__init__k   s     mT+-XsE
r   c                 8    U R                   R                  5         g)zcClose the zip archive, flushing any pending physical writes and releasing any
resources it's using.Nr]   r@   s    r   rA   _ZipPkgWriter.closeo   s     	

r   c                 P    U R                   R                  UR                  U5        g)zQWrite `blob` to this zip package with the membername corresponding to
`pack_uri`.N)rW   writestrr7   )r2   r:   r<   s      r   write_ZipPkgWriter.writet   s     	

H//6r   rd   )
r   r   r    r!   r"   r/   rA   ro   r#   r$   r%   s   @r   r*   r*   h   s    JF
7 7r   r*   )r"   r   zipfiler   r   r   docx.opc.exceptionsr   docx.opc.packurir   r	   r'   r   r   r*   r   r   r   <module>rt      sS    S 	 5 5 4 .= =$@ @!M !HM B7M 7r   