a
    lc                     @   s   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZ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 G dd deZG dd dZG dd deZG dd deeZdS )    N)Path)Optional)inference_state_method_cache)AbstractNameDefinition
ModuleName)GlobalNameFilterParserTreeFilter
DictFilterMergedFilter)compiled)	TreeValue)SubModuleName)values_from_qualified_names)create_simple_object)ValueSetModuleContextc                   @   s&   e Zd ZdZdZdddZdd ZdS )	_ModuleAttributeNamezA
    For module attributes like __file__, __str__ and so on.
    instanceNc                 C   s   || _ || _|| _d S N)parent_contextstring_name_string_value)selfparent_moduler   Zstring_value r   W/var/www/html/django/DPS/env/lib/python3.9/site-packages/jedi/inference/value/module.py__init__   s    z_ModuleAttributeName.__init__c                 C   s2   | j d ur$| j }tt| jj|gS t| jjS r   )r   r   r   r   inference_stater   Zget_string_value_set)r   sr   r   r   infer   s    
z_ModuleAttributeName.infer)N)__name__
__module____qualname____doc__api_typer   r    r   r   r   r   r      s   
r   c                   @   s   e Zd Ze dd ZdS )SubModuleDictMixinc                 C   s>   i }|   r:| jj|  }|D ]}t|  |||< q"|S )zf
        Lists modules in the directory of this module (if this module is a
        package).
        )
is_packager   Zcompiled_subprocessZiter_module_names
py__path__r   
as_context)r   namesmodsnamer   r   r   sub_modules_dict&   s    z#SubModuleDictMixin.sub_modules_dictN)r!   r"   r#   r   r-   r   r   r   r   r&   %   s   r&   c                   @   sr   e Zd ZeZdddZdd Zdd Zdd	 Ze	e
 d
d Ze
 dd Zdd Ze
g dd Zdd ZdS )ModuleMixinNc                 c   sN   t t|  |dt|  V  t|  V  t|  V  |  E d H  d S )N)r   origin_scope)r
   r   r)   r   r	   r-   _module_attributes_dictiter_star_filters)r   r/   r   r   r   get_filters=   s    
zModuleMixin.get_filtersc                 C   s   t | jdd\}|S )Ntypes
ModuleType)r   r   )r   cr   r   r   py__class__I   s    zModuleMixin.py__class__c                 C   s   dS )NTr   r   r   r   r   	is_moduleM   s    zModuleMixin.is_modulec                 C   s   dS )NFr   r7   r   r   r   is_stubP   s    zModuleMixin.is_stubc                 C   s   |  | | jd S N)_module_name_classstring_namesr7   r   r   r   r,   S   s    zModuleMixin.namec                    sF   g d}t  fdd|D }  }|d urBt dt||d< |S )N)__package__r$   r!   c                 3   s   | ]}|t  |fV  qd S r   )r   ).0nr7   r   r   	<genexpr>\       z6ModuleMixin._module_attributes_dict.<locals>.<genexpr>__file__)dict
py__file__r   str)r   r*   dctpathr   r7   r   r0   X   s    z#ModuleMixin._module_attributes_dictc                 c   s2   |   D ]$}t| d }|d us&J |V  qd S r   )star_importsnextr2   )r   Zstar_modulefr   r   r   r1   b   s    zModuleMixin.iter_star_filtersc                 C   s|   ddl m} g }|  }| j D ]T}| r"|| j| d ||jd	 }|D ]}t
|trR|| 7 }qR||7 }q"|S )Nr   )Importerr;   )Zimport_pathmodule_contextlevel)Zjedi.inference.importsrL   r)   	tree_nodeZiter_importsZis_star_importr   	get_pathsrN   follow
isinstanceModuleValuerI   )r   rL   modulesrM   inewmoduler   r   r   rI   k   s     



zModuleMixin.star_importsc                 C   s   dS )z
        A module doesn't have a qualified name, but it's important to note that
        it's reachable and not `None`. With this information we can add
        qualified names on top for all value children.
        r   r   r7   r   r   r   get_qualified_names   s    zModuleMixin.get_qualified_names)N)r!   r"   r#   r   r<   r2   r6   r8   r9   propertyr   r,   r0   r1   rI   rX   r   r   r   r   r.   :   s   

		
r.   c                       sp   e Zd ZdZd fdd	Z fddZdd	 Zee d
ddZ	dd Z
dd Zdd Zdd Zdd Z  ZS )rS   rW   NFc                    sF   t  j|d |d || _|d u r(d | _n|j| _|| _|| _|| _d S )N)r   rO   )superr   file_io_pathrH   r=   
code_lines_is_package)r   r   Zmodule_noder]   r[   r=   r'   	__class__r   r   r      s    zModuleValue.__init__c                    s$   | j d ur| j jdkrdS t  S )Nz.pyiT)r\   suffixrZ   r9   r7   r_   r   r   r9      s    zModuleValue.is_stubc                 C   s   | j d u rd S d| j S )N.)r=   joinr7   r   r   r   
py__name__   s    
zModuleValue.py__name__)returnc                 C   s   | j du rdS | j  S )z?
        In contrast to Python's __file__ can be None.
        N)r\   absoluter7   r   r   r   rE      s    
zModuleValue.py__file__c                 C   s   | j S r   )r^   r7   r   r   r   r'      s    zModuleValue.is_packagec                 C   s(   | j d u rg S | jr| j S | j d d S r:   )r=   r^   r7   r   r   r   py__package__   s
    
zModuleValue.py__package__c                 C   s   | j s
dS d| jdd }d}|d |v s:|d |v rt }| j D ],}tj|| jj	}tj
|rJ|| qJ|rt|S |  }|dusJ tj|gS )z
        In case of a package, this returns Python's __path__ attribute, which
        is a list of paths (strings).
        Returns None if the module is not a package.
        N 2   )zdeclare_namespace(__name__)zextend_path(__path__r      )r^   rc   r]   setr   Zget_sys_pathosrH   r,   r   isdiraddlistrE   dirname)r   Zfirst_few_linesoptionspathsr   otherfiler   r   r   r(      s    zModuleValue.py__path__c                 C   s   t | S r   r   r7   r   r   r   _as_context   s    zModuleValue._as_contextc                 C   s.   d| j j|  | jjd | jjd |  f S )Nz<%s: %s@%s-%s is_stub=%s>r   )r`   r!   rd   rO   	start_posend_posr9   r7   r   r   r   __repr__   s
    zModuleValue.__repr__)NNF)r!   r"   r#   r%   r   r9   rd   r   r   rE   r'   rg   r(   ru   rx   __classcell__r   r   r_   r   rS      s     	!rS   )rl   pathlibr   typingr   Zjedi.inference.cacher   Zjedi.inference.namesr   r   Zjedi.inference.filtersr   r   r	   r
   Zjedi.inferencer   Zjedi.inference.base_valuer   r   Zjedi.inference.helpersr   Zjedi.inference.compiledr   r   Zjedi.inference.contextr   r   r&   r.   rS   r   r   r   r   <module>   s    O