
    vg\j                     @   S r SSKrSSKrSSKrSSKrSSKJr  S rS rS r	S r
S	 rS
 rS rS rS r\R                   " \" 5       SS9r\R%                  SS9r\R)                  SSS9r\R-                  SSSS9  \R-                  S\R.                  " SSS9SS9  \R-                  SS S9  \R)                  S!S"S9r\R-                  S#S$S9  \R-                  S%\R.                  " SSS9S&S9  \R-                  S'\R.                  " SSS9S(S9  \R-                  SS S9  S*S) jrg)+a  Implementation of the ``cffi-gen-src`` command-line tool.

This module is private; the command line is the only supported
interface. Two subcommands:

``exec-python``
    Execute a Python script that constructs a :class:`cffi.FFI`
    (the same kind of script that the CFFI docs' "Main mode of usage"
    describes) and emit the generated C source.

``read-sources``
    Create the :class:`cffi.FFI` from a separate ``cdef`` file and C
    source prelude, then emit the generated C source.
    N   )FFIc                 0    [        XSS9n[        X2U5        g )Nexec)sourcefilenamemode)compiler   )pysrcr   globscompileds       M/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/cffi/_cffi_gen_src.py	_execfiler   3   s    eVDH%     c                 2   [         R                  R                  U5      nSUS.n[        R                  SS n[        R                  R	                  S[         R                  R                  U5      5         [        XU5        X#;  a  [        SU< S35      eX2   n[        U[        5      (       d  [        U5      (       a  U" 5       n[        U[        5      (       d  [        SU< S35      eUU[        R                  SS& $ ! U[        R                  SS& f = f)	a  Execute ``pysrc`` and return the :class:`FFI` object it defines.

The script is executed with ``__name__`` set to ``"cffi.gen_src"``,
so a trailing ``if __name__ == "__main__": ffibuilder.compile()``
block in the script is skipped.

``ffivar`` is the name bound by the script to the :class:`FFI`
object, or to a callable that returns one.

Raises :class:`NameError` if the name is not bound by the script,
or :class:`TypeError` if the name does not resolve to an
:class:`FFI` instance.
zcffi.gen_src)__name____file__Nr   z.Expected to find the FFI object with the name z, but it was not found.zFound an object with the name z+ but it was not an instance of cffi.api.FFI)ospathabspathsysinsertdirnamer   	NameError
isinstancer   callable	TypeError)r   r   ffivarr   old_pathffis         r   find_ffi_in_python_scriptr!   8   s     wwx(H'X>Exx{HHHOOArwwx01%5)+14  m#s##%C#s##.47  hs   6A7D Dc                 ^    [        5       nUR                  U5        UR                  X5        U$ )zACreate an :class:`FFI` from ``cdef`` text and a C source prelude.)r   cdef
set_source)
modulenamer#   csrc
ffibuilders       r   make_ffi_from_sourcesr(   _   s)    JOOD*+r   c                 n    [         R                  " 5       nU R                  U5        UR                  5       $ )z=Return the C source that :meth:`FFI.emit_c_code` would write.)ioStringIOemit_c_codegetvalue)r    outputs     r   generate_c_sourcer/   g   s&    [[]FOOF??r   c                     U S:X  a   [         R                  R                  U5        g [        U SSS9 nUR                  U5        S S S 5        g ! , (       d  f       g = f)N-wutf-8encoding)r   stdoutwriteopen)r.   	generatedfs      r   write_c_sourcer;   n   sD    }

#	fcG	,		 
-	,	,s   A
Ac                     XL a  g [         R                  R                  U R                  UR                  5      $ ! [         a     gf = f)NTF)r   r   samefilenameOSError)file1file2s     r   same_input_filerB   v   s@    ~ww

EJJ77 s   3; 
AAc                     U   [        UR                  5       UR                  U5      nS S S 5        [        W5      n[	        X5        g ! , (       d  f       N%= fN)r!   readr>   r/   r;   )r.   pyfileffi_varr    r9   s        r   exec_pythonrH      s<    	'v{{GL 
!#&I6% 
s   &A
Ac                     U   U   UR                  5       nUR                  5       nS S S 5        S S S 5        [        UWW5      n[        U5      n[        X5        g ! , (       d  f       N:= f! , (       d  f       NC= frD   )rE   r(   r/   r;   )r.   module_name
cdef_input
csrc_inputr&   r#   r    r9   s           r   read_sourcesrM      sU    	Z      T4
8C!#&I6%  Zs!   A,!AA,
A)	%A,,
A:c                      [         R                  (       a0  [        R                  R	                  [         R                  S   5      OSn U R                  S5      (       a  gg)Nr    zcffi-gen-srczpython -m cffi.gen_src)r   argvr   r   basename
startswith)argv0s    r   _progrT      s?     .1XXBGGSXXa[)2E''#r   z-Generate CFFI C source for extension modules.)progdescriptionr	   )destexec-pythonz2Execute a Python script that defines an FFI object)helpz	--ffi-varr'   zFName of the FFI object in the Python script; defaults to 'ffibuilder'.)defaultrY   rF   rr3   r4   zPath to the Python script)typerY   r.   zOutput path for the C sourceread-sourcesz>Read cdef and C source prelude files that define an FFI objectrJ   z5Full name of the generated module, including packagesr#   zFile containing C definitionsr&   z File containing C source preludec                    [         R                  U S9n U R                  S:X  a*  [        U R                  U R
                  U R                  S9  OU R                  S:X  ao  [        U R                  U R                  5      (       a  [         R                  S5        [        U R                  U R                  U R                  U R                  S9  O[         R                  S5        [         R                  S5        g )	NargsrX   )r.   rF   rG   r]   z1cdef and csrc are the same file and should not be)r.   rJ   rK   rL   z5a subcommand is required: exec-python or read-sourcesr   )parser
parse_argsr	   rH   r.   rF   rG   rB   r#   r&   errorrM   rJ   exitr_   s    r   runre      s    $'DyyM!4;;t{{DLLQ	n	$499dii00LLLM;;((yyyy		
 	LM
KKNr   rD   )__doc__argparser*   r   r   apir   r   r!   r(   r/   r;   rB   rH   rM   rT   ArgumentParserra   add_subparsers
subparsers
add_parserexec_python_parseradd_argumentFileTyperead_sources_parserre    r   r   <module>rr      s  8  	 	 
 !
$N&&$ 
	 	 	?
 """/
**	= +     	Q   
   			3	1	$   
   	'   
 !++	I ,       	@ !      
			3	1	( ! 
     
			3	1	+ ! 
     	' ! r   