
    hi                         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          Z
 G d d	          Z G d
 de
          Z G d de
          Z G 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Z xZS )PhysPkgReaderz,Factory for physical package reader objects.c                 ,   t          |t                    rPt          j                            |          rt
          }n0t          |          rt          }nt          d|z            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__s      i/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/docx/opc/phys_pkg.pyr   zPhysPkgReader.__new__   s    h$$ 	'w}}X&& S*

H%% S*

*+F+QRRR&J]C((00<<<    __name__
__module____qualname____doc__r   __classcell__r   s   @r   r	   r	   
   s>        66= = = = = = = = =r   r	   c                   "     e Zd ZdZ fdZ xZS )PhysPkgWriterz,Factory for physical package writer objects.c                 ^    t          t          |                               t                    S )N)r   r"   r   _ZipPkgWriter)r   r   r   s     r   r   zPhysPkgWriter.__new__   s!    ]C((00???r   r   r    s   @r   r"   r"      sG        66@ @ @ @ @ @ @ @ @r   r"   c                   J     e Zd ZdZ fdZd Zd Zed             Zd Z	 xZ
S )r   zWImplements |PhysPkgReader| interface for an OPC package extracted into a
    directory.c                     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   s     r   r'   z_DirPkgReader.__init__'   s8    mT""++---W__T**


r   c                     t           j                            | j        |j                  }t          |d          5 }|                                }ddd           n# 1 swxY 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blobs        r   blob_forz_DirPkgReader.blob_for,   s    w||DJ(;<<$ 	6688D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA #A c                     dS )z|Provides interface consistency with |ZipFileSystem|, but does nothing, a
        directory file system doesn't need closing.N r*   s    r   closez_DirPkgReader.close3   s	     	r   c                 6    |                      t                    S )z7Return the `[Content_Types].xml` blob from the package.r4   r   r7   s    r   content_types_xmlz_DirPkgReader.content_types_xml8        }}.///r   c                 b    	 |                      |j                  }n# t          $ r d}Y nw xY w|S )z`Return rels item XML for source with `source_uri`, or None if the item has no
        rels item.N)r4   rels_uriIOErrorr*   
source_urirels_xmls      r   rels_xml_forz_DirPkgReader.rels_xml_for=   sF    	}}Z%899HH 	 	 	HHH	    ,,r   r   r   r   r'   r4   r8   propertyr;   rC   r   r    s   @r   r   r   #   s         + + + + +
    
 0 0 X0      r   r   c                   J     e Zd ZdZ fdZd Zd Zed             Zd Z	 xZ
S )r   z@Implements |PhysPkgReader| interface for a zip file OPC package.c                     t          t          |                                            t          |d          | _        d S )Nr)r   r   r'   r   _zipfr*   r   r   s     r   r'   z_ZipPkgReader.__init__J   s4    mT""++---Xs++


r   c                 @    | j                             |j                  S )zReturn blob corresponding to `pack_uri`.

        Raises |ValueError| if no matching member is present in zip archive.
        )rJ   r0   r.   )r*   r1   s     r   r4   z_ZipPkgReader.blob_forN   s    
 zx2333r   c                 8    | j                                          dS )z;Close the zip archive, releasing any resources it is using.NrJ   r8   r7   s    r   r8   z_ZipPkgReader.closeU   s    
r   c                 6    |                      t                    S )z;Return the `[Content_Types].xml` blob from the zip package.r:   r7   s    r   r;   z_ZipPkgReader.content_types_xmlY   r<   r   c                 b    	 |                      |j                  }n# t          $ r d}Y nw xY w|S )z]Return rels item XML for source with `source_uri` or None if no rels item is
        present.N)r4   r>   KeyErrorr@   s      r   rC   z_ZipPkgReader.rels_xml_for^   sF    	}}Z%899HH 	 	 	HHH	rD   rE   r    s   @r   r   r   G   s        JJ, , , , ,4 4 4   0 0 X0      r   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )r$   z@Implements |PhysPkgWriter| interface for a zip file OPC package.c                     t          t          |                                            t          |dt                    | _        d S )Nw)compression)r   r$   r'   r   r   rJ   rK   s     r   r'   z_ZipPkgWriter.__init__k   s9    mT""++---XsEEE


r   c                 8    | j                                          dS )zkClose the zip archive, flushing any pending physical writes and releasing any
        resources it's using.NrN   r7   s    r   r8   z_ZipPkgWriter.closeo   s     	
r   c                 F    | j                             |j        |           dS )zYWrite `blob` to this zip package with the membername corresponding to
        `pack_uri`.N)rJ   writestrr.   )r*   r1   r3   s      r   writez_ZipPkgWriter.writet   s%     	
H/66666r   )r   r   r   r   r'   r8   rY   r   r    s   @r   r$   r$   h   sa        JJF F F F F  
7 7 7 7 7 7 7r   r$   )r   r   zipfiler   r   r   docx.opc.exceptionsr   docx.opc.packurir   r	   r"   r   r   r$   r6   r   r   <module>r]      s8   S S 				 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 . . . . . .= = = = = = = =$@ @ @ @ @ @ @ @! ! ! ! !M ! ! !H    M   B7 7 7 7 7M 7 7 7 7 7r   