o
    Zh                     @  sv   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r2d dlZG dd	 d	ZdS )
    )annotations)TYPE_CHECKING	Generatorcast)parse_iso8824_date)"FileSpecificationDictionaryEntries)PdfReadError)ArrayObjectDictionaryObjectStreamObjectNc                   @  s   e Zd ZdZd1dd	Zed2ddZed2ddZed3ddZed4ddZ	ed5ddZ
ed2ddZed6ddZed7ddZed8dd Zed8d!d"Zed9d$d%Zd3d&d'Zed:d+d,Zed;d.d/Zd0S )<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.
    namestr
pdf_objectr
   returnNonec                 C  s   || _ || _dS )z
        Args:
            name: The (primary) name as provided in the name tree.
            pdf_object: The corresponding PDF object to allow retrieving further data.
        Nr   r   )selfr   r    r   K/var/www/html/lang_env/lib/python3.10/site-packages/pypdf/generic/_files.py__init__   s   
zEmbeddedFile.__init__
str | Nonec                 C  s8   t jt jfD ]}|| jv rtt| j|    S qdS )z3Retrieve the alternative name (file specification).N)r   UFFr   r   r   
get_object)r   keyr   r   r   alternative_name   s
   
zEmbeddedFile.alternative_namec                 C  s   | j tjS )zRetrieve the description.)r   getr   ZDESCr   r   r   r   description)      zEmbeddedFile.descriptionc                 C  s   | j ddS )zJRetrieve the relationship of the referring document to this embedded file.z/AFRelationshipz/Unspecified)r   r   r   r   r   r   associated_file_relationship.   r    z)EmbeddedFile.associated_file_relationshipr   c                 C  sh   d| j vrtd| j  tt| j d }tjtjfD ]}||v r,tt||    S q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   Zefr   r   r   r   _embedded_file3   s   
zEmbeddedFile._embedded_filec                 C  s   | j dt  S )z&Retrieve the file-specific parameters.z/Params)r"   r   r
   r   r   r   r   r   _params>   s   zEmbeddedFile._paramsc                 C     | j dS )zERetrieve the subtype. This is a MIME media type, prefixed by a slash.z/Subtype)r"   r   r   r   r   r   subtypeC      zEmbeddedFile.subtypebytesc                 C  s
   | j  S )z!Retrieve the actual file content.)r"   get_datar   r   r   r   contentH   s   
zEmbeddedFile.content
int | Nonec                 C  r$   )z4Retrieve the size of the uncompressed file in bytes.z/Sizer#   r   r   r   r   r   sizeM   r&   zEmbeddedFile.sizedatetime.datetime | Nonec                 C     t | jdS )z$Retrieve the file creation datetime.z/CreationDater   r#   r   r   r   r   r   creation_dateR      zEmbeddedFile.creation_datec                 C  r.   )z4Retrieve the datetime of the last file modification.z/ModDater/   r   r   r   r   modification_dateW   r1   zEmbeddedFile.modification_datebytes | Nonec                 C  r$   )z5Retrieve the MD5 checksum of the (uncompressed) file.z	/CheckSumr+   r   r   r   r   checksum\   r&   zEmbeddedFile.checksumc                 C  s   d| j j d| jdS )N<z name=>)	__class____name__r   r   r   r   r   __repr__a   s   zEmbeddedFile.__repr__namesr	   Generator[EmbeddedFile]c                 c  sH    t |D ]\}}t|ts!| }||d   }t||dV  qdS )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   )clsr:   ir   Zfile_dictionaryZdirect_namer   r   r   _load_from_namesd   s   
zEmbeddedFile._load_from_namescatalogc                 c  s    zt tt t|d d }W n
 ty   Y dS w d|v r?t t|d  D ]}| }d|v r>| t t|d E dH  q'd|v rR| t t|d E dH  dS dS )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   rA   )r?   rB   	containerkidr   r   r   _loadw   s$   zEmbeddedFile._loadN)r   r   r   r
   r   r   )r   r   )r   r   )r   r   )r   r
   )r   r'   )r   r*   )r   r-   )r   r3   )r:   r	   r   r;   )rB   r
   r   r;   )r8   
__module____qualname____doc__r   propertyr   r   r!   r"   r#   r%   r)   r,   r0   r2   r4   r9   classmethodrA   rF   r   r   r   r   r      s<    
		

r   )
__future__r   typingr   r   r   Zpypdf._utilsr   Zpypdf.constantsr   Zpypdf.errorsr   Zpypdf.genericr	   r
   r   datetimer   r   r   r   r   <module>   s    