a
    lc[,                     @   sL  d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZmZmZ ddlmZ ddlmZmZ ddlmZmZ ddlmZ ddlmZm Z m!Z! e" Z#G dd deZ$G dd dee!Z%G dd de e%Z&G dd deZ'G dd dej(Z)e dd Z*dd Z+dd Z,e d d! Z-dS )"z 
Used only for REPL Completion.
    N)Path)get_cached_code_lines)settings)memoize_method)compiled)FileIO)NameWrapper)ValueSetValueWrapper	NO_VALUES)ModuleValue)inference_state_function_cacheinference_state_method_cache)ALLOWED_GETITEM_TYPESget_api_type)to_stub)CompiledContextCompiledModuleContextTreeContextMixinc                       s   e Zd ZdZ fddZdd Zdd Zeedd	d
 Z	e
fddZedd Zdd Zdd Zdd Zdd Zdd Z  ZS )MixedObjecta  
    A ``MixedObject`` is used in two ways:

    1. It uses the default logic of ``parser.python.tree`` objects,
    2. except for getattr calls and signatures. The names dicts are generated
       in a fashion like ``CompiledValue``.

    This combined logic makes it possible to provide more powerful REPL
    completion. It allows side effects that are not noticable with the default
    parser structure to still be completeable.

    The biggest difference from CompiledValue to MixedObject is that we are
    generally dealing with Python code and not with C code. This will generate
    fewer special cases, because we in Python you don't have the same freedoms
    to modify the runtime.
    c                    s   t  | || _|j| _d S N)super__init__compiled_valueaccess_handle)selfr   
tree_value	__class__ Y/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/compiled/mixed.pyr   ,   s    zMixedObject.__init__c                 o   s   t | j| j| jV  d S r   )MixedObjectFilterinference_stater   _wrapped_value)r   argskwargsr   r   r    get_filters1   s    zMixedObject.get_filtersc                 C   s
   | j  S r   )r   get_signaturesr   r   r   r    r'   5   s    zMixedObject.get_signatures)defaultc                 C   s   t | j}|s| j}||S r   )r   r#   
py__call__)r   	argumentsvaluesr   r   r    r*   :   s    
zMixedObject.py__call__c                 C   s"   |t u r| j S | j|S d S r   )	_sentinelr   get_safe_value)r   r)   r   r   r    r.   B   s    
zMixedObject.get_safe_valuec                 C   s   | j jS r   )r   
array_typer(   r   r   r    r/   H   s    zMixedObject.array_typec                 C   s
   | j  S r   )r   get_key_valuesr(   r   r   r    r0   L   s    zMixedObject.get_key_valuesc                 C   s0   | j jjj}t|tv r$| j |S | j|S r   )r   r   access_objtyper   py__simple_getitem__r#   )r   indexpython_objectr   r   r    r4   O   s    z MixedObject.py__simple_getitem__c                 C   s
   | j  S r   )r   negater(   r   r   r    r7   U   s    zMixedObject.negatec                 C   s   | j d u rt| S t| S r   )Zparent_contextMixedModuleContextMixedContextr(   r   r   r    _as_contextX   s    
zMixedObject._as_contextc                 C   s   dt | j| j | jf S )Nz<%s: %s; %s>)r3   __name__r   Zget_reprr#   r(   r   r   r    __repr__]   s
    zMixedObject.__repr__)r;   
__module____qualname____doc__r   r&   r'   r   r   r*   r-   r.   propertyr/   r0   r4   r7   r:   r<   __classcell__r   r   r   r    r      s   

r   c                   @   s   e Zd Zedd ZdS )r9   c                 C   s   | j jS r   )_valuer   r(   r   r   r    r   f   s    zMixedContext.compiled_valueN)r;   r=   r>   r@   r   r   r   r   r    r9   e   s   r9   c                   @   s   e Zd ZdS )r8   N)r;   r=   r>   r   r   r   r    r8   k   s   r8   c                       s8   e Zd ZdZ fddZedd Zedd Z  Z	S )	MixedNamezB
    The ``CompiledName._compiled_value`` is our MixedObject.
    c                    s   t  | || _d S r   )r   r   _parent_tree_value)r   Zwrapped_nameZparent_tree_valuer   r   r    r   s   s    zMixedName.__init__c                 C   s    t |  }|sdS |d jjS )N)r   r   r   )listinfername	start_pos)r   r,   r   r   r    rH   w   s    zMixedName.start_posc                    s`   | j   | j}| s | rJ|| j}  rJt fdd|D S |	 }t
| j |S )Nc                    s   h | ]}t  |qS r   r   ).0vr   r   r    	<setcomp>       z"MixedName.infer.<locals>.<setcomp>)Z_wrapped_nameZinfer_compiled_valuerD   Zis_instanceis_classZpy__getattribute__Zstring_nameZis_functionr	   get_root_context_createZ_inference_state)r   r   tree_valuesmodule_contextr   rL   r    rF      s    
zMixedName.infer)
r;   r=   r>   r?   r   r@   rH   r   rF   rA   r   r   r   r    rC   o   s   
rC   c                       s(   e Zd Z fddZ fddZ  ZS )r!   c                    s   t  || || _d S r   )r   r   _tree_value)r   r"   r   r   r   r   r    r      s    zMixedObjectFilter.__init__c                    s   t t || jS r   )rC   r   _create_namerT   )r   rG   r   r   r    rU      s    
zMixedObjectFilter._create_name)r;   r=   r>   r   rU   rA   r   r   r   r    r!      s   r!   c                 C   s   | j |dtjtjd S )NT)pathcacheZ
diff_cache
cache_path)parser   Zfast_parserZcache_directoryZget_root_node)r"   rV   r   r   r    _load_module   s    rZ   c                 C   s   zt | } W n ty    Y n0 t | sht | sht | sht | sht | sht | sht 	| rl| S z| j
W S  ty   tY n0 dS )z9Check if inspect.getfile has a chance to find the source.N)inspectunwrap
ValueErrorismoduleisclassismethod
isfunctionistracebackisframeiscoder   AttributeError	TypeError)r6   r   r   r    _get_object_to_check   s,    
rg   c              	      s  |}zt |}t|}W n ttfy2   Y d S 0 |d u r@d nt|}z|d u sZ| s`W d S W n tyv   Y d S 0 t|}t| |}t	|rt
| j|}||||fS z
|j}W n ty   Y d S 0 |dkrd S | |g }dd |D }|s d S z|j}	|	j W n ty$   Y n0  fdd|D }
|
rB|
}t
| j|}|d j}|jdkrvt|dkrvd S ||||fS )Nz<lambda>c                 S   s(   g | ] }|j jd v r|j j|kr|qS ))funcdefclassdef)parentr3   rG   )rJ   nr   r   r    
<listcomp>   s   z*_find_syntax_node_name.<locals>.<listcomp>c                    s   g | ]}|j d   kr|qS )r   )rH   )rJ   rG   Zline_nrr   r    rl      rN   rh   instance)rg   r[   getsourcefileOSErrorrf   r   existsr   rZ   r^   r   Zgrammarr;   re   Zget_used_namesget__code__co_firstlinenorj   r3   r   )r"   r6   Zoriginal_objectrV   file_iomodule_node
code_linesZname_strnamescodeZ
line_names	tree_noder   rm   r    _find_syntax_node_name   sT    





r|   c                    s   j jj}t| |}|d u rPt|tttfv r8t hS t	 }|st hS n|\}}}}	|d u sn|j
|kr̈   }
|
 }t|d}t| ||||	|
 d}|d ur| j|t|g | }t||h}|jdkr  s| }t fdd|D S )N.)rv   string_namesrx   
is_packageri   c                 3   s   | ]}t  |d V  qdS ))r   NrI   )rJ   r   rL   r   r    	<genexpr>2  s   z_create.<locals>.<genexpr>)r   r1   r2   r|   r3   dictrE   tupler	   r   r{   rP   	get_valueZ
py__name__splitr   r   Zmodule_cacheaddZ
as_contextZcreate_valuerO   Zexecute_with_values)r"   r   rS   r6   resultrR   rw   r{   rv   rx   Zroot_compiled_valuerG   r~   Zmodule_valuer   rL   r    rQ     s<    



rQ   ).r?   r[   pathlibr   Zjedi.parser_utilsr   Zjedir   Z
jedi.cacher   Zjedi.inferencer   Zjedi.file_ior   Zjedi.inference.namesr   Zjedi.inference.base_valuer	   r
   r   Zjedi.inference.valuer   Zjedi.inference.cacher   r   Zjedi.inference.compiled.accessr   r   Z!jedi.inference.gradual.conversionr   Zjedi.inference.contextr   r   r   objectr-   r   r9   r8   rC   ZCompiledValueFilterr!   rZ   rg   r|   rQ   r   r   r   r    <module>   s4   J
	R