
    HAiO2                        S SK Jr  S SKJr  S SKJrJrJr  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJrJrJrJrJrJrJrJrJrJr  \(       a
  S S
KrS SKJ r    " S S5      r!g
)    )annotations)cached_property)TYPE_CHECKING	Generatorcast)format_iso8824_dateparse_iso8824_date)CatalogAttributes)"FileSpecificationDictionaryEntries)PageAttributes)PdfReadError)
ArrayObjectByteStringObjectDecodedStreamObjectDictionaryObject
NameObject
NullObjectNumberObjectStreamObjectTextStringObjectis_null_or_noneN)	PdfWriterc                     \ rS rSrSrS S jr\S!S j5       r\S"S j5       r	\S#S j5       r
\
R                  S$S j5       r
\S#S j5       r\R                  S$S	 j5       r\S!S
 j5       r\R                  S%S j5       r\S&S j5       r\S'S j5       r\S'S j5       r\S#S j5       r\R                  S(S j5       r\S)S j5       r\R                  S*S j5       r\S+S j5       r\R                  S,S j5       r\S-S j5       r\R                  S.S j5       r\S-S j5       r\R                  S.S j5       r\S/S j5       r\R                  S0S j5       rS!S jr\S1S j5       r\S2S j5       rSrg)3EmbeddedFile   z
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                    Xl         X l        g)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)selfnamer   s      P/var/www/html/land-ocr/venv/lib/python3.13/site-packages/pypdf/generic/_files.py__init__EmbeddedFile.__init__&   s     
$    c                    U R                   $ )zEThe (primary) name of the embedded file as provided in the name tree.)r   r    s    r"   r!   EmbeddedFile.name/   s     zzr%   c           	        [        U[        5      (       a  UR                  S5      n[        5       nUR	                  U5        UR                  [        [        R                  5      [        S5      05        [        5       nUR                  [        S5      UR                  U5      05        SSKJn  [        5       nUR                  [        [        R                  5      [        S5      [        [        R                  5      U" U5      [        [        R                  5      U05        [         R"                  UR$                  ;  a=  UR                  [        5       5      UR$                  [        [         R"                  5      '   ['        [        UR$                  [         R"                     5      nSU;  aJ  [        [        [         R"                  5      [)        5       05      n	UR                  U	5      U[        S5      '   O['        [        US   5      n	['        [(        U	[         R"                     5      n
U
R+                  U" U5      U/5        U " X'S9$ )	a  
Create a new embedded file and add it to the PdfWriter.

Args:
    writer: The PdfWriter instance to add the embedded file to.
    name: The filename to display.
    content: The data in the file.

Returns:
    EmbeddedFile instance for the newly created embedded file.
latin-1z/EmbeddedFilez/Fr   )create_string_objectz	/Filespec/EmbeddedFilesr!   r   )
isinstancestrencoder   set_dataupdater   PATYPEr   _add_objectpypdf.genericr+   r   FEFCANAMES_root_objectr   r   extend)clswriterr!   content
file_entryef_entryr+   filespec
names_dictembedded_files_names_dictionarynames_arrays              r"   _create_newEmbeddedFile._create_new4   s    gs##nnY/G )*
G$:bgg.
?0KLM $%D)6+=+=j+IJK 	7#%277#Z%<=??@BVW[B\=@@A8	
 886...8>8J8JK[K]8^F
288 45*F,?,?,IJ
:-.>BHH%{}5/+ 8>7I7IJi7jJz"234.23CZP`Ea.b+ ;(G(QR06AB 22r%   c                    [         R                  [         R                  4 HS  nXR                  ;   d  M  U R                  U   R	                  5       n[        U5      (       a  MC  [        [        U5      s  $    g)z3Retrieve the alternative name (file specification).N)r   UFr7   r   
get_objectr   r   r/   )r    keyvalues      r"   alternative_nameEmbeddedFile.alternative_namem   sa     799;];_;_`C oo%,779&u--U++ a r%   c                L   Uc  [         R                  U R                  ;   a.  [        5       U R                  [	        [         R                  5      '   [         R
                  U R                  ;   a/  [        5       U R                  [	        [         R
                  5      '   gg[         R                  U R                  ;   a%  XR                  [	        [         R                  5      '   [         R
                  U R                  ;   a&  XR                  [	        [         R
                  5      '   gg)z.Set the alternative name (file specification).N)r   rI   r   r   r   r7   r    rL   s     r"   rM   rN   y   s     =144GU_Ua
+M+P+P QR133tFT^T`
+M+O+O PQ G 244GUZ
+M+P+P QR133tFTY
+M+O+O PQ Gr%   c                z    U R                   R                  [        R                  5      n[	        U5      (       a  gU$ )zRetrieve the description.N)r   getr   DESCr   rP   s     r"   descriptionEmbeddedFile.description   s2     ##$F$K$KL5!!r%   c                    Uc/  [        5       U R                  [        [        R                  5      '   gXR                  [        [        R                  5      '   g)zSet the description.N)r   r   r   r   rS   rP   s     r"   rT   rU      s>     =S]S_DOOJ'I'N'NOPSXOOJ'I'N'NOPr%   c                :    U R                   R                  SS5      $ )zJRetrieve the relationship of the referring document to this embedded file./AFRelationshipz/Unspecified)r   rR   r'   s    r"   associated_file_relationship)EmbeddedFile.associated_file_relationship   s     ""#4nEEr%   c                2    XR                   [        S5      '   g)zESet the relationship of the referring document to this embedded file.rX   N)r   r   rP   s     r"   rY   rZ      s     :?
#456r%   c                D   SU R                   ;  a  [        SU R                    35      e[        [        U R                   S   5      n[        R
                  [        R                  4 H*  nX!;   d  M
  [        [        X   R                  5       5      s  $    [        SU 35      e)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   rI   r7   r   rJ   )r    efrK   s      r"   _embedded_fileEmbeddedFile._embedded_file   s     '!6t6GHII"DOOE$:;699;];_;_`CyL"'*<*<*>?? a DRDIJJr%   c                f    U R                   R                  S[        5       5      R                  5       $ )z&Retrieve the file-specific parameters./Params)r^   rR   r   rJ   r'   s    r"   _paramsEmbeddedFile._params   s*     ""&&y2B2DEPPRRr%   c                x    U R                   nSU;  a  [        5       U[        S5      '   [        [        US   5      $ )z3Ensure the /Params dictionary exists and return it.ra   )r^   r   r   r   )r    embedded_files     r"   _ensure_paramsEmbeddedFile._ensure_params   s<     ++M)3C3EM*Y/0$mI&>??r%   c                ^    U R                   R                  S5      n[        U5      (       a  gU$ )zERetrieve the subtype. This is a MIME media type, prefixed by a slash./SubtypeN)r^   rR   r   rP   s     r"   subtypeEmbeddedFile.subtype   s-     ##''
35!!r%   c                j    U R                   nUc  [        5       U[        S5      '   gX[        S5      '   g)zGSet the subtype. This should be a MIME media type, prefixed by a slash.Nri   )r^   r   r   )r    rL   re   s      r"   rj   rk      s2     ++=4>LM*Z0149*Z01r%   c                6    U R                   R                  5       $ )z!Retrieve the actual file content.)r^   get_datar'   s    r"   r?   EmbeddedFile.content   s     ""++--r%   c                    [        U[        5      (       a  UR                  S5      nU R                  R	                  U5        g)zSet the file content.r*   N)r.   r/   r0   r^   r1   rP   s     r"   r?   ro      s3     eS!!LL+E$$U+r%   c                ^    U R                   R                  S5      n[        U5      (       a  gU$ )z4Retrieve the size of the uncompressed file in bytes./SizeNrb   rR   r   rP   s     r"   sizeEmbeddedFile.size   s+       )5!!r%   c                j    U R                   nUc  [        5       U[        S5      '   gX[        S5      '   g)z/Set the size of the uncompressed file in bytes.Nrr   rf   r   r   r    rL   paramss      r"   rt   ru      s2     $$=*4,F:g&'*/:g&'r%   c                J    [        U R                  R                  S5      5      $ )z$Retrieve the file creation datetime./CreationDater	   rb   rR   r'   s    r"   creation_dateEmbeddedFile.creation_date   s     "$,,"2"2?"CDDr%   c                    U R                   nUc  [        5       U[        S5      '   g[        U5      n[	        U5      U[        S5      '   g)zSet the file creation datetime.Nr{   rf   r   r   r   r   r    rL   ry   date_strs       r"   r}   r~      sC     $$=2<,F:o./*51H2B82LF:o./r%   c                J    [        U R                  R                  S5      5      $ )z4Retrieve the datetime of the last file modification./ModDater|   r'   s    r"   modification_dateEmbeddedFile.modification_date   s     "$,,"2"2:">??r%   c                    U R                   nUc  [        5       U[        S5      '   g[        U5      n[	        U5      U[        S5      '   g)z/Set the datetime of the last file modification.Nr   r   r   s       r"   r   r      sC     $$=-7\F:j)**51H-=h-GF:j)*r%   c                ^    U R                   R                  S5      n[        U5      (       a  gU$ )z5Retrieve the MD5 checksum of the (uncompressed) file.	/CheckSumNrs   rP   s     r"   checksumEmbeddedFile.checksum  s+       -5!!r%   c                j    U R                   nUc  [        5       U[        S5      '   gX[        S5      '   g)z0Set the MD5 checksum of the (uncompressed) file.Nr   rw   rx   s      r"   r   r     s2     $$=.8lF:k*+.3:k*+r%   c                R    SU R                   R                   SU R                  < S3$ )N<z name=>)	__class____name__r!   r'   s    r"   __repr__EmbeddedFile.__repr__  s&    4>>**+6$))a@@r%   c              #     #    [        U5       HL  u  p#[        U[        5      (       a  M  UR                  5       nXS-
     R                  5       n[	        XTS9v   MN     g7f)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)	enumerater.   r/   rJ   r   )r=   namesir!   file_dictionarydirect_names         r"   _load_from_namesEmbeddedFile._load_from_names  sP      !'GAdC(("&//"3#El557"PP (s
   $A5Ac              #    #     [        [        [        [        US   5      S   5      nSU;   aj  [        [        US   R	                  5       5       HE  nUR	                  5       nSU;   d  M  U R                  [        [        US   5      5       Sh  vN   MG     SU;   a+  U R                  [        [        US   5      5       Sh  vN   gg! [         a     gf = f NJ N7f)a  
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/Namesr,   Nz/Kids)r   r   KeyErrorr   rJ   r   )r=   catalog	containerkids       r"   _loadEmbeddedFile._load,  s     	 %wx'89:JKI iK7);)F)F)HI nn&s?"33Dc(m4TUUU J y ++Di>Q,RSSS !  		 VSsK   C$C
 >C*%CC3CCC

CCCCCr   N)r!   r/   r   r   returnNone)r   r/   )r>   r   r!   r/   r?   str | bytesr   r   )r   z
str | None)rL   zTextStringObject | Noner   r   )rL   r   r   r   )r   r   )r   r   )rL   zNameObject | Noner   r   )r   bytes)rL   r   r   r   )r   z
int | None)rL   zNumberObject | Noner   r   )r   datetime.datetime | None)rL   r   r   r   )r   zbytes | None)rL   zByteStringObject | Noner   r   )r   r   r   Generator[EmbeddedFile])r   r   r   r   )r   
__module____qualname____firstlineno____doc__r#   propertyr!   classmethodrF   rM   setterrT   rY   r^   rb   r   rf   rj   r?   rt   r}   r   r   r   r   r   __static_attributes__ r%   r"   r   r      sM   %   63 63p 	 	 Z Z   Y Y F F "((? )? K K S S @ @   ^^: : . . ^^, ,   
[[0 0 E E M M @ @ H H   __4 4A Q Q$ T Tr%   r   )"
__future__r   	functoolsr   typingr   r   r   pypdf._utilsr   r	   pypdf.constantsr
   r9   r   r   r3   pypdf.errorsr   r6   r   r   r   r   r   r   r   r   r   r   datetimepypdf._writerr   r   r   r%   r"   <module>r      sH    " % 1 1 @ 3 > 0 %   'kT kTr%   