o
    i                     @   sF  d dl Zd dlmZ d dlmZmZ d dlZddl	m
Z
mZmZ ddlmZmZmZmZ G dd deZejd	 ejd
 ejd fZejd ejd ejd gesWejd fndesaejd fndejd erresrejd fndR Zejd Zg esejd fnderejd fndR Z	dded dee fddZdS )    N)IntFlag)OptionalUnion   )DUAL_ARG_OPCODESCellVarFreeVar)PY311PY312PY313PY314c                   @   s@   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdS )CompilerFlagszPossible values of the co_flags attribute of Code object.

    Note: We do not rely on inspect values here as some of them are missing and
    furthermore would be version dependent.

    r                   @         i   i   i   N)__name__
__module____qualname____doc__	OPTIMIZED	NEWLOCALSVARARGSVARKEYWORDSNESTED	GENERATORNOFREE	COROUTINEITERABLE_COROUTINEASYNC_GENERATORFUTURE_GENERATOR_STOPFUTURE_ANNOTATIONS r&   r&   B/home/ubuntu/.local/lib/python3.10/site-packages/bytecode/flags.pyr      s    r   
STORE_NAME	LOAD_NAMEDELETE_NAMEGET_AWAITABLE	GET_AITER	GET_ANEXTBEFORE_ASYNC_WITHr&   SETUP_ASYNC_WITHEND_ASYNC_FORASYNC_GEN_WRAPYIELD_VALUE
YIELD_FROMRETURN_GENERATORbytecode)z_bytecode.Bytecodez_bytecode.ConcreteBytecodez_bytecode.ControlFlowGraphis_asyncc                 C   s  t d}t| tjtjtjfsd}t||  t| tjr!|  n| }t| tj}d}|s/dn| jo4| j	}d}d}	d}
t
|}|D ]}t|tjtjtjtjfrQqA|j}|tv r[d}qA|tv rbd}qA|tkrtrtt| }tjtjtjtjfr	 tt| }tjtjtjtjfsy|jdksJ |jd@ dkrd}	qAd}qAd}	qA|tv rd}
qA|tjv rd}qA|s|tv rt|jd tst|jd trd}qAtr|tjv rt|jttfrd}qA|r|t jO }|s|t j O }|| j!t j"t j#B t j$B t j%B @ O }|dv rl| j!t j&@ s| j!t j'@ r|	r|t j'O }ng|t j&O }na| j!t j(@ r3|r-d	}t||t j(O }nK|rE|	r?|t j'O }n?|t j&O }n9|	sK|
rc|r]|	rW|t j'O }n'|t j&O }n!|t j)O }n|rk|t j&O }n|rstd
|	sy|
r~|t j)O }|| j!t j*@ O }|S )a  Infer the proper flags for a bytecode based on the instructions.

    Because the bytecode does not have enough context to guess if a function
    is asynchronous the algorithm tries to be conservative and will never turn
    a previously async code into a sync one.

    Parameters
    ----------
    bytecode : Bytecode | ConcreteBytecode | ControlFlowGraph
        Bytecode for which to infer the proper flags
    is_async : bool | None, optional
        Force the code to be marked as asynchronous if True, prevent it from
        being marked as asynchronous if False and simply infer the best
        solution based on the opcode and the existing flag if None.

    r   zIExpected a Bytecode, ConcreteBytecode or ControlFlowGraph instance not %sTFRESUME   r   )NTzThe ITERABLE_COROUTINE flag is set but bytecode thatcan only be used in async functions have been detected. Please unset that flag before performing inference.ziThe is_async argument is False but bytecodes that can only be used in async functions have been detected.)+r   
isinstance	_bytecodeBytecodeConcreteBytecodeControlFlowGraph
ValueError_get_instructionscellvarsfreevarsiter	SetLinenoLabelTryBeginTryEndopcodeUNOPTIMIZED_OPCODESASYNC_OPCODESYIELD_VALUE_OPCODEr	   nextnameargGENERATOR_LIKE_OPCODES_opcodehasfreer   r   r   haslocalr   r   r    flagsr   r   r   r   r!   r#   r"   r   r$   )r5   r6   rR   msginstructionsis_concrete	optimizedhas_freeknown_asyncknown_generatorpossible_generator
instr_iterinstrrG   nir&   r&   r'   infer_flags@   s   

	
	






	



r^   )N)rG   rO   enumr   typingr   r   r5   r:   r\   r   r   r   utilsr	   r
   r   r   r   opmaprH   rI   rJ   rN   boolr^   r&   r&   r&   r'   <module>   sJ    


