
    *'h                    |    d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZ erd dlZ G d d	      Zy)
    )annotations)TYPE_CHECKING	Generatorcast)parse_iso8824_date)"FileSpecificationDictionaryEntries)PdfReadError)ArrayObjectDictionaryObjectStreamObjectNc                  
   e Zd ZdZddZedd       Zedd       Zedd       Zedd       Z	edd       Z
edd       Zedd	       Zedd
       Zedd       Zedd       Zedd       ZddZedd       Zedd       Zy)EmbeddedFilez
    Container holding the information on an embedded file.

    Attributes are evaluated lazily if possible.

    Further information on embedded files can be found in section 7.11 of the PDF 2.0 specification.
    c                     || _         || _        y)z
        Args:
            name: The (primary) name as provided in the name tree.
            pdf_object: The corresponding PDF object to allow retrieving further data.
        Nname
pdf_object)selfr   r   s      [/home/kushmeetdev/Regenta/Chatbot/venv/lib/python3.12/site-packages/pypdf/generic/_files.py__init__zEmbeddedFile.__init__   s     	$    c                    t         j                  t         j                  fD ]=  }|| j                  v st	        t
        | j                  |   j                               c S  y)z3Retrieve the alternative name (file specification).N)r   UFFr   r   str
get_object)r   keys     r   alternative_namezEmbeddedFile.alternative_name   sY     799;];_;_` 	DC doo%C!5!@!@!BCC		D
 r   c                T    | j                   j                  t        j                        S )zRetrieve the description.)r   getr   DESCr   s    r   descriptionzEmbeddedFile.description)   s      ""#E#J#JKKr   c                :    | j                   j                  dd      S )zJRetrieve the relationship of the referring document to this embedded file.z/AFRelationshipz/Unspecified)r   r   r!   s    r   associated_file_relationshipz)EmbeddedFile.associated_file_relationship.   s     ""#4nEEr   c                <   d| j                   vrt        d| j                          t        t        | j                   d         }t        j
                  t        j                  fD ])  }||v st        t        ||   j                               c S  t        d|       )z)Retrieve the actual embedded file stream.z/EFz/EF entry not found: z'No /(U)F key found in file dictionary: )	r   r	   r   r   r   r   r   r   r   )r   efr   s      r   _embedded_filezEmbeddedFile._embedded_file3   s     '!6t6GHII"DOOE$:;699;];_;_` 	@CbyL"S'*<*<*>??	@ DRDIJJr   c                f    | j                   j                  dt                     j                         S )z&Retrieve the file-specific parameters.z/Params)r'   r   r   r   r!   s    r   _paramszEmbeddedFile._params>   s*     ""&&y2B2DEPPRRr   c                8    | j                   j                  d      S )zERetrieve the subtype. This is a MIME media type, prefixed by a slash.z/Subtype)r'   r   r!   s    r   subtypezEmbeddedFile.subtypeC   s     ""&&z22r   c                6    | j                   j                         S )z!Retrieve the actual file content.)r'   get_datar!   s    r   contentzEmbeddedFile.contentH   s     ""++--r   c                8    | j                   j                  d      S )z4Retrieve the size of the uncompressed file in bytes.z/Sizer)   r   r!   s    r   sizezEmbeddedFile.sizeM   s     ||((r   c                J    t        | j                  j                  d            S )z$Retrieve the file creation datetime.z/CreationDater   r)   r   r!   s    r   creation_datezEmbeddedFile.creation_dateR   s     "$,,"2"2?"CDDr   c                J    t        | j                  j                  d            S )z4Retrieve the datetime of the last file modification.z/ModDater3   r!   s    r   modification_datezEmbeddedFile.modification_dateW   s     "$,,"2"2:">??r   c                8    | j                   j                  d      S )z5Retrieve the MD5 checksum of the (uncompressed) file.z	/CheckSumr0   r!   s    r   checksumzEmbeddedFile.checksum\   s     ||,,r   c                P    d| j                   j                   d| j                  dS )N<z name=>)	__class____name__r   r!   s    r   __repr__zEmbeddedFile.__repr__a   s&    4>>**+6$))a@@r   c              #     K   t        |      D ]K  \  }}t        |t              r|j                         }||dz
     j                         }t	        ||       M yw)z
        Convert the given name tree into class instances.

        Args:
            names: The name tree to load the data from.

        Returns:
            Iterable of class instances for the files found.
           r   N)	enumerate
isinstancer   r   r   )clsnamesir   file_dictionarydirect_names         r   _load_from_nameszEmbeddedFile._load_from_namesd   s[      !' 	QGAtdC("&//"3#AEl557"PP	Qs
   "A8Ac              #    K   	 t        t        t        t        |d         d         }d|v ret        t        |d   j	                               D ]A  }|j	                         }d|v s| j                  t        t        |d               E d{    C d|v r+| j                  t        t        |d               E d{    yy# t        $ r Y yw xY w7 E7 w)aI  
        Load the embedded files for the given document catalog.

        This method and its signature are considered internal API and thus not exposed publicly for now.

        Args:
            catalog: The document catalog to load from.

        Returns:
            Iterable of class instances for the files found.
        z/Namesz/EmbeddedFilesNz/Kids)r   r   KeyErrorr
   r   rH   )rC   catalog	containerkids       r   _loadzEmbeddedFile._loadw   s     	 %wx'89:JKI iK7);)F)F)HI V nn&s?"33Dc(m4TUUUV y ++Di>Q,RSSS !  		 VSsK   C$C <C%%C
C/C:C;C	C
CCCCN)r   r   r   r   returnNone)rO   z
str | None)rO   r   )rO   r   )rO   r   )rO   bytes)rO   z
int | None)rO   zdatetime.datetime | None)rO   zbytes | None)rD   r
   rO   Generator[EmbeddedFile])rK   r   rO   rR   )r=   
__module____qualname____doc__r   propertyr   r"   r$   r'   r)   r+   r.   r1   r4   r6   r8   r>   classmethodrH   rN    r   r   r   r      s&   %   L L F F K K S S 3 3 . . ) ) E E @ @ - -A Q Q$ T Tr   r   )
__future__r   typingr   r   r   pypdf._utilsr   pypdf.constantsr   pypdf.errorsr	   pypdf.genericr
   r   r   datetimer   rX   r   r   <module>r`      s1    " 1 1 + > % E EFT FTr   