
    ,h                         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y)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              rFt        j                  j	                  |      rt
        }n&t        |      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      S/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/docx/opc/phys_pkg.pyr   zPhysPkgReader.__new__   sW    h$ww}}X&*
H%*
*+F+QRR&J]C0<<    __name__
__module____qualname____doc__r   __classcell__r   s   @r   r	   r	   
   s    6= =r   r	   c                   "     e Zd ZdZ fdZ xZS )PhysPkgWriterz,Factory for physical package writer objects.c                 2    t         t        |   t              S )N)r   r"   r   _ZipPkgWriter)r   r   r   s     r   r   zPhysPkgWriter.__new__   s    ]C0??r   r   r    s   @r   r"   r"      s    6@ @r   r"   c                   D     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                 r    t         t        |           t        j                  j                  |      | _        y)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__'   s$    mT+-WW__T*
r   c                     t         j                  j                  | j                  |j                        }t        |d      5 }|j                         }ddd       |S # 1 sw Y   S xY w)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,   sQ    ww||DJJ(;(;<$ 	668D		s   AA&c                      y)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                 ,    | j                  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                  |j                        }|S # t        $ r d}Y |S w xY w)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=   s=    	}}Z%8%89H   	H	    ..r   r   r   r   r'   r4   r8   propertyr;   rC   r   r    s   @r   r   r   #   s0    +

 0 0r   r   c                   D     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                 L    t         t        |           t        |d      | _        y )Nr)r   r   r'   r   _zipfr*   r   r   s     r   r'   z_ZipPkgReader.__init__J   s    mT+-Xs+
r   c                 L    | j                   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    
 zzx2233r   c                 8    | j                   j                          y)z;Close the zip archive, releasing any resources it is using.NrJ   r8   r7   s    r   r8   z_ZipPkgReader.closeU   s    

r   c                 ,    | j                  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                  |j                        }|S # t        $ r d}Y |S w xY w)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^   s=    	}}Z%8%89H   	H	rD   rE   r    s   @r   r   r   G   s.    J,4 0 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                 X    t         t        |           t        |dt              | _        y )Nw)compression)r   r$   r'   r   r   rJ   rK   s     r   r'   z_ZipPkgWriter.__init__k   s     mT+-XsE
r   c                 8    | j                   j                          y)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                 P    | j                   j                  |j                  |       y)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//6r   )r   r   r   r   r'   r8   rY   r   r    s   @r   r$   r$   h   s    JF
7r   r$   )r   r   zipfiler   r   r   docx.opc.exceptionsr   docx.opc.packurir   r	   r"   r   r   r$   r6   r   r   <module>r]      sS    S 	 5 5 4 .= =$@ @!M !HM B7M 7r   