
    Mh+                        d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZ ddlm	Z	 e j
        dk    rd dlZd Znd dlZd Ze j
        d	k    rej        Zn G d
 dej                  Z G d de          ZdZd Zdad Zd ZddZd Zd ZdS )    N   )__version_verifier_modules__)ffiplatform)VerificationError)   r   c                  4    t           j        j        d d          S N)	importlib	machineryEXTENSION_SUFFIXES     M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/cffi/verifier.py_extension_suffixesr      s    "5aaa88r   c                  <    d t          j                    D             S )Nc                 :    g | ]\  }}}|t           j        k    |S r   )impC_EXTENSION).0suffix_types       r   
<listcomp>z'_extension_suffixes.<locals>.<listcomp>   s4     , , ,?61d3?** ***r   )r   get_suffixesr   r   r   r   r      s+    , ,c.>.@.@ , , , 	,r   r   c                        e Zd Z fdZ xZS )NativeIOc                     t          |t                    r|                    d          }t          t          |                               |           d S )Nascii)
isinstanceunicodeencodesuperr   write)selfs	__class__s     r   r$   zNativeIO.write   sJ    !W%% &HHW%%(D!!''*****r   )__name__
__module____qualname__r$   __classcell__)r'   s   @r   r   r      s8        	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+r   r   c                   h    e Zd Z	 	 	 ddZddZd Zd Zd	 Zd
 Zd Z	d Z
d Zd ZddZd Zd ZdS )VerifierN F.cc                    |j         j        rt          d|j         j                  || _        || _        |st          j        |          }t          ||          } ||           | _        | j        	                    |           |	| _
        |                     ||
          | _        |r|rt          d          n d                    dt          j        d d         z  t"          ||g|j        z             }t          j        dk    r|                    d          }t)          t+          j        |dd d                   d	z            }|                    d
                              d          }t)          t+          j        |dd d                   d	z            }|                    d                              d          }d|d| j        j        ||}t5                      d         }|pt7                      | _        t:          j                            | j        ||z             | _        t:          j                            | j        ||z             | _         || _!        d| _"        d| _#        d S )NzIfeature not supported with ffi.verify(), but only with ffi.set_source(): z)can't specify both 'modulename' and 'tag' z%d.%d   r   zutf-8r   l    0xLr   0_cffi_r   F)$_parser_uses_new_featurer   ffipreambler   flatten_locate_engine_class_venginepatch_extension_kwdsflagsmake_relative_tokwds	TypeErrorjoinsysversion_infor   _cdefsourcesr"   hexbinasciicrc32lstriprstrip
_class_key_get_so_suffixes_caller_dir_pycachetmpdirospathsourcefilenamemodulefilenameext_package_has_source_has_module)r%   r9   r:   rO   
modulenamerT   tagforce_generic_enginesource_extensionr?   relative_torA   flattened_kwdsvengine_classkeyk1k2r   s                     r   __init__zVerifier.__init__    sj    ;( 	P##/2{/L/LOP P P   	7(066N,S2FGG%d++**4000
))$<<	 	6 M KLLLM ++w)9"1")==;'9 "./ 0 0C 4''jj))X^C1I..;<<B4'',,BX^C1I..;<<B3&&s++BB.1cc4=3K3K.0b""6J!##A&5 3 5 5 gll4;
EU8UVV gll4;
V8KLL&  r   c                     | j         j        5  | j        r|t          d          |                     |           ddd           dS # 1 swxY w Y   dS )zkWrite the C source code.  It is produced in 'self.sourcefilename',
        which can be tweaked beforehand.Nzsource code already written)r9   _lockrU   r   _write_sourcer%   files     r   write_sourcezVerifier.write_sourceI   s     X^ 	% 	% 3DL'13 3 3t$$$		% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   .AAAc                     | j         j        5  | j        rt          d          | j        s|                                  |                                  ddd           dS # 1 swxY w Y   dS )zWrite the C source code (if not done already) and compile it.
        This produces a dynamic link library in 'self.modulefilename'.zmodule already compiledN)r9   rc   rV   r   rU   rd   _compile_moduler%   s    r   compile_modulezVerifier.compile_moduleR   s     X^ 	# 	# C'(ABBB# %""$$$  """	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   AA  A$'A$c                    | j         j        5  | j        sJ|                                  | j        s/| j        s|                                  |                                  |                                 cddd           S # 1 swxY w Y   dS )a"  Get a C module from this Verifier instance.
        Returns an instance of a FFILibrary class that behaves like the
        objects returned by ffi.dlopen(), but that delegates all
        operations to the C module.  If necessary, the C code is written
        and compiled first.
        N)r9   rc   rV   _locate_modulerU   rd   ri   _load_libraryrj   s    r   load_libraryzVerifier.load_library\   s     X^ 	( 	(# +##%%%' ++ -**,,,((***%%''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   A%A??BBc                     t           j                            | j                  }|                    dd          d         }|                    d          rt          t          d          r
|d d         }|S )N.r   r   _dgettotalrefcount)rP   rQ   basenamerS   splitendswithhasattrrD   )r%   ru   s     r   get_module_namezVerifier.get_module_namel   sp    7##D$788 >>#q))!, T"" 	%ws4F'G'G 	%}Hr   c                    | j         s?| j        j        5  | j         s|                                  d d d            n# 1 swxY w Y   t	          j        | j                  }|                                 }t	          j        ||fi | j	        S r	   )
rU   r9   rc   rd   r   maybe_relative_pathrR   ry   get_extensionrA   )r%   
sourcenamemodnames      r   r|   zVerifier.get_extensionw   s     	) ) )' )&&((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) !4T5HII
&&(((WJJ	JJJs   <A A c                     | j         j        S r	   )r=   _gen_python_modulerj   s    r   generates_python_modulez Verifier.generates_python_module   s    }//r   c                 j   |rt           j                            |          rt           j                            |          |                                }t          j        D ]P}||v rJ||         }t          |t          t          f          st          d|d          fd|D             }|||<   Q|S )Nz	keyword 'z' should be a list or tuplec                 P    g | ]"}t           j                            |          #S r   )rP   rQ   rC   )r   fndirnames     r   r   z-Verifier.make_relative_to.<locals>.<listcomp>   s)    CCC27<<44CCCr   )
rP   rQ   r   copyr   LIST_OF_FILE_NAMESr    listtuplerB   )r%   rA   r[   r^   lstr   s        @r   r@   zVerifier.make_relative_to   s     
	$27??;77 
	$gook22G99;;D"5 $ $$;;s)C%cD%=99 2'i+.33)1 2 2 2CCCCsCCCC #DIr   c                    t           j                            | j                  s| j        r3	 t          | j        d d dg          }n# t          $ r Y d S w xY w|j        }nd }| j        	                    | 
                                |t                                }|d S || _        | j                                         d| _        d S )N__doc__T)rP   rQ   isfilerS   rT   
__import__ImportError__path__r=   find_modulery   rM   collect_typesrV   )r%   pkgrQ   filenames       r   rm   zVerifier._locate_module   s    w~~d122 	+ $T%5tTI;OOCC"   FF |}001E1E1G1G1A1C1CE EH"*D##%%%s   A 
AAc                 x    || j         _        	 | j                                          | j         `d S # | j         `w xY wr	   )r=   _fwrite_source_to_fre   s     r   _write_source_tozVerifier._write_source_to   sG    	!M++---        s   0 	9c                 >   ||                      |           d S t                      }|                      |           |                                }t          j                            | j                  rGt          | j        d          5 }|                                |k     }d d d            n# 1 swxY w Y   nd}|rVt          | j                   t          | j        d          5 }|
                    |           d d d            n# 1 swxY w Y   d| _        d S )NrTw)r   r   getvaluerP   rQ   existsrR   openread_ensure_dirr$   rU   )r%   rf   fsource_datafpneeds_writtens         r   rd   zVerifier._write_source   s   !!$''''' 

A!!!$$$**,,K w~~d122 %$-s33 Cr)+k)A$BMC C C C C C C C C C C C C C C !%  *D/000$-s33 *rHH[)))* * * * * * * * * * * * * * *  $Ds$   
B00B47B4)DDDc                 f   t           j                            | j                  }t	          j        ||                                           }	 t	          j        || j                  }n# t          $ r d}Y nw xY w|s.t          | j                   t          j        || j                   d| _        d S )NFT)rP   rQ   r   rR   r   compiler|   samefilerS   OSErrorr   shutilmoverV   )r%   rO   outputfilenamesames       r   ri   zVerifier._compile_module   s    !455$,VT5G5G5I5IJJ	'8KLLDD 	 	 	DDD	 	=+,,,K(;<<<s   A( (A76A7c                     | j         sJ | j        | j                            | j                  S | j                                        S r	   )rV   r?   r=   ro   rj   s    r   rn   zVerifier._load_library   sE    :!=--dj999=--///r   )NNNr.   Fr/   NNr	   )r(   r)   r*   ra   rg   rk   ro   ry   r|   r   r@   rm   r   rd   ri   rn   r   r   r   r-   r-      s        >B@E@D'! '! '! '!R% % % %# # #( ( ( 	 	 	K K K0 0 0        &! ! !$ $ $ $2     0 0 0 0 0r   r-   Fc                     t           rd}|s4dt          j        v rd}n#	 dd l}n# t          $ r d}Y nw xY w| j        |urd}|rddlm} |j        S ddlm	} |j
        S )NT__pypy__r   ?r   )vengine_gen)vengine_cpy)_FORCE_GENERIC_ENGINErD   builtin_module_names_cffi_backendr   _backendr.   r   VGenericEnginer   VCPythonEngine)r9   rY   r   r   r   s        r   r<   r<      s     $# 	,111#'  $$$$$$ $ $ $ #$|=00'+$ *!!!!!!))!!!!!!))s   # 22c                  T   t           rt           S t          j                            d          } | r| S t	          j        d          j        j        }t          j        	                    t          j        
                    t          j                            |          d                    S )NCFFI_TMPDIRr2   __pycache__)_TMPDIRrP   environgetrD   	_getframef_codeco_filenamerQ   abspathrC   r   )resultr   s     r   rN   rN      s     Z^^M**F }Q&2H7??27<<(A(A(* * + + +r   c                 
    | a dS )z:Set the temporary directory to use instead of __pycache__.N)r   )r   s    r   
set_tmpdirr      s     GGGr   c                    | pt                      } 	 t          j        |           }n# t          $ r Y dS w xY w|rd}n&t	                      d                                         }|D ]}|                                                    d          r|                                                    |          s'|                                                    d          rD	 t          j        t          j	        
                    | |                     # t          $ r Y w xY wt          j	        
                    | d          g}|D ]}	 t          j        |          D ]k}t          j	        
                    ||          }t          j	                            |          r|                    |           Wt          j        |           l# t          $ r Y w xY wdS )z}Clean up the temporary directory by removing all files in it
    called `_cffi_*.{c,so}` as well as the `build` subdirectory.Nr/   r   r6   build)rN   rP   listdirr   rM   lower
startswithrw   unlinkrQ   rC   isdirappend)rO   keep_sofilelistr   r   	clean_dirdirs          r   cleanup_tmpdirr     s    ,*,,F:f%%    /!##A&,,..  88::  ** 	

##F++	/1xxzz/B/B4/H/H		"',,vr223333   fg../I 	 		joo " "W\\#r**7==$$ "$$R((((IbMMMM"  	 	 	D		 	s1   ' 
552D
DDB G
GGc                  T    t                      } | st          j        dk    rdg} ndg} | S )Nwin32z.pydz.so)r   rD   platform)suffixess    r   rM   rM   $  s7    "$$H <7""xHHwHOr   c                     t           j                            |           }|r5t           j                            |          st          j        |           d S d S d S r	   )rP   rQ   r   r   makedirs)r   r   s     r   r   r   /  s\    gooh''G rw}}W-- 
G   r   )NF)rD   rP   rH   r   ior.   r   r   errorr   rE   importlib.machineryr
   r   r   StringIOr   BytesIOobjectr-   r   r<   r   rN   r   r   rM   r   r   r   r   <module>r      s   % $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ * * * * * *       $ $ $ $ $ $v9 9 9 9 JJJ, , ,
 t{HH+ + + + +2: + + +z0 z0 z0 z0 z0v z0 z0 z0|  * * *, + + +  
   >	 	 	    r   