
    FZj                        d Z ddlZddlZddlZddlZddlmZ d Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z ej                    e       d      Zej%                  d      Zej)                  dd      Zej-                  ddd       ej-                  d ej.                  dd      d       ej-                  dd        ej)                  d!d"      Zej-                  d#d$       ej-                  d% ej.                  dd      d&       ej-                  d' ej.                  dd      d(       ej-                  dd        d*d)Zy)+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                 :    t        | |d      }t        |||       y )Nexec)sourcefilenamemode)compiler   )pysrcr   globscompileds       TC:\Users\Rodrigo\frota-trucks-cliente\python\Lib\site-packages\cffi/_cffi_gen_src.py	_execfiler   3   s    ehVDH5%     c                    t         j                  j                  |      }d|d}t        j                  dd }t        j                  j	                  dt         j                  j                  |             	 t        | ||       ||vrt        d|d      ||   }t        |t              st        |      r |       }t        |t              st        d|d      ||t        j                  dd S # |t        j                  dd w xY w)	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  Fm#s#%C#s#.47  hs   6A'C1 1Dc                 `    t               }|j                  |       |j                  | |       |S )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*d+r   c                 l    t        j                         }| j                  |       |j                         S )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                     | dk(  r t         j                  j                  |       y t        | dd      5 }|j                  |       d d d        y # 1 sw Y   y xY w)N-wutf-8encoding)r   stdoutwriteopen)r.   	generatedfs      r   write_c_sourcer;   n   sD    }

#	fcG	,		 
-	,	,s   AAc                     | |u ry	 t         j                  j                  | j                  |j                        S # t        $ r Y yw xY w)NTF)r   r   samefilenameOSError)file1file2s     r   same_input_filerB   v   sB    ~ww

EJJ77 s   3; 	AAc                     |5  t        |j                         |j                  |      }d d d        t              }t	        | |       y # 1 sw Y   !xY wN)r!   readr>   r/   r;   )r.   pyfileffi_varr    r9   s        r   exec_pythonrH      s>    	'v{{GL 
!#&I69% 
s   &A		Ac                     |5  |5  |j                         }|j                         }d d d        d d d        t        |      }t        |      }t        | |       y # 1 sw Y   6xY w# 1 sw Y   :xY wrD   )rE   r(   r/   r;   )r.   module_name
cdef_input
csrc_inputr&   r#   r    r9   s           r   read_sourcesrM      sW    	Z      T4
8C!#&I69%  Zs!   A(!AA(A%	!A((A1c                      t         j                  r0t        j                  j	                  t         j                  d         nd} | j                  d      ryy)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                    t         j                  |       } | j                  dk(  r-t        | j                  | j
                  | j                         n| j                  dk(  rmt        | j                  | j                        rt         j                  d       t        | j                  | j                  | j                  | j                         nt         j                  d       t         j                  d       y )	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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   