o
    tBh                     @  s   d Z ddlmZ ddlZddl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mZ d	ZG d
d deZ	d;d<ddZd=ddZd>ddZe	d?d@d%d&ZdAdBd+d,ZdCd/d0ZedDd3d4ZedEd5d4ZdFd7d4ZdGd9d:ZdS )HzDUtilities for mypy.stubgen, mypy.stubgenc, and mypy.stubdoc modules.    )annotationsN)contextmanager)Iterator)overload)ModuleNotFoundReason)InspectErrorModuleInspect c                   @  s   e Zd ZdddZdS )
CantImportmodulestrmessagec                 C  s   || _ || _d S N)r   r   )selfr   r   r	   r	   d/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/mypy/stubutil.py__init__   s   
zCantImport.__init__N)r   r   r   r   )__name__
__module____qualname__r   r	   r	   r	   r   r
      s    r
   Finspectr   packages	list[str]verboseboolreturnIterator[str]c              	   c  s    |D ]E}|t v rt| d q|rtd|d z| |}W n ty/   t| Y qw |jV  |jrBt| |j|E dH  q|jE dH  qdS )a  Iterates through all packages and sub-packages in the given list.

    This uses runtime imports (in another process) to find both Python and C modules.
    For Python packages we simply pass the __path__ attribute to pkgutil.walk_packages() to
    get the content of the package (all subpackages and modules).  However, packages in C
    extensions do not have this attribute, so we have to roll out our own logic: recursively
    find all modules imported in the package that have matching names.
    z: Skipped (blacklisted)Trying to import  for runtime introspectionN)	NOT_IMPORTABLE_MODULESprintget_package_propertiesr   report_missingnameis_c_modulewalk_packagessubpackages)r   r   r   package_namepropr	   r	   r   r$      s$   r$   r   r   sys_path
str | Nonec                 C  sd   |  ddd tj|  dddf}|D ]}|D ]}tj||}tj|r.|    S qqd S )N./z.pyz__init__.py)replaceospathjoinisfile)r   r(   relative_candidatesbaserelative_pathr.   r	   r	   r   find_module_path_using_sys_path7   s   r4   *tuple[str | None, list[str] | None] | Nonec              
   C  s   |t v r	t|d|rtd|d z| |}W n( tyB } zt|tj}|du r4t|t|||dfW  Y d}~S d}~ww |j	rHdS |j
|jfS )zFind module and determine __all__ for a Python 3 module.

    Return None if the module is a C module. Return (module_path, __all__) if
    it is a Python module. Raise CantImport if import failed.
     r   r   N)r   r
   r   r    r   r4   sysr.   r   r#   fileall)r   r   r   moder.   r	   r	   r   find_module_path_and_all_py3D   s    
r<   Tr:   targetignore_errorsIterator[None]c              
   c  sx    |r
t d|   zdV  W n ty. } z|s|t d| tjd W Y d}~dS d}~ww |r:t d|  dS dS )zTIgnore or report errors during stub generation.

    Optionally report success.
    zProcessing NzStub generation failed for)r8   zCreated )r   	Exceptionr7   stderr)r:   r=   r>   r   r;   r	   r	   r   generate_guarded_   s   
rB   r6   r   	tracebackNonec                 C  s"   |rd| }t |  d|  d S )Nz with error: z: Failed to import, skipping)r   )r:   r   rC   r	   r	   r   r!   v   s   r!   reasonr   c                 C  s@   |t ju rd}n|t ju rd}nd| d}td|  d| )Nz(consider using --search-path)z5(module likely exists, but is not PEP 561 compatible)z(unknown reason 'z')zCan't find module 'z' )r   	NOT_FOUNDFOUND_WITHOUT_TYPE_HINTS
SystemExit)r:   rE   clarificationr	   r	   r   fail_missing|   s   

rJ   sourcebytesc                 C     d S r   r	   rK   r	   r	   r   remove_misplaced_type_comments      rO   c                 C  rM   r   r	   rN   r	   r	   r   rO      rP   str | bytesc                 C  s   t | tr| d}n| }tjdd|tjd}tjdd|tjd}tjdd|tjd}tjd	d|tjd}t | tr?|dS |S )
zRemove comments from source that could be understood as misplaced type comments.

    Normal comments may look like misplaced type comments, and since they cause blocking
    parse errors, we want to avoid them.
    latin1z ^[ \t]*# +type: +["\'a-zA-Z_].*$r6   )flagsz""" *\n[ \t\n]*# +type: +\(.*$z"""
z''' *\n[ \t\n]*# +type: +\(.*$z'''
z%^[ \t]*# +type: +\([^()]+(\)[ \t]*)?$)
isinstancerL   decoderesub	MULTILINEencode)rK   textr	   r	   r   rO      s   


pathsc                 C  sn   | sdS t jt j| d }| dd  D ]}	 t jt j|}|t j |t j r1|}nqq|p6dS )Nr*   r      )r-   r.   dirnamenormpathsep
startswith)r[   curr.   r	   r	   r   common_dir_prefix   s   rb   )F)r   r   r   r   r   r   r   r   )r   r   r(   r   r   r)   )r   r   r   r   r   r   r   r5   )TF)
r:   r   r=   r   r>   r   r   r   r   r?   )r6   r6   )r:   r   r   r)   rC   r   r   rD   )r:   r   rE   r   r   rD   )rK   rL   r   rL   )rK   r   r   r   )rK   rQ   r   rQ   )r[   r   r   r   )__doc__
__future__r   os.pathr-   rV   r7   
contextlibr   typingr   typing_extensionsr   mypy.modulefinderr   mypy.moduleinspectr   r   r   r@   r
   r$   r4   r<   rB   r!   rJ   rO   rb   r	   r	   r	   r   <module>   s6    




