
    c                     ^   d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZmZmZmZmZmZ  ej        e          Zde
j        d	efd
Z	 	 	 ddej        dededed	eeddf         f
dZd	efdZdeded	ee         fdZ	 ddededed	eeddf         fdZdededed	efdZ dS )zz
Functions to find importable names.

Can extract names from source code of a python file, .so object, or builtin module.
    N)import_module)	GeneratorList)ast   )ModuleCompiled
ModuleFile
ModuleInfoNameNameTypePackagePartialNameSourcenodereturnc                     t          | t          j                  rt          j        S t          | t          j                  rt          j        S t          | t          j                  rt          j        S t          j        S )zGet the lsp type of a node.)	
isinstancer   ClassDefr   ClassFunctionDefFunctionAssignVariable)r   s    =lib/python3.11/site-packages/rope/contrib/autoimport/parse.pyget_type_astr      sa    $%% ~$(( !  $
## !       Fmodulepackage_name
underlinedprocess_importsc              #   j  K   	 t          j        |                                           }n'# t          $ r}t	          |           Y d}~dS d}~ww xY wt          j        |          D ]}t          |t           j                  r|j        D ]v}	 t          |t           j	                  sJ |s|j
                            d          s$t          |j
        t          |                    V  `# t          t          f$ r Y sw xY wt          |t           j        t           j        f          rB|s|j                            d          s$t          |j        t          |                    V  |rt          |t           j                  r|j        dk    r-|j        r"||j                            d          d         u rX|j        D ]k}t          |t           j                  r|j        r|j        }	n
|j        }	n|}	|s|	                    d          st          |	t          |                    V  ldS )z.Get all the names from a given file using ast.N_r   .)r   parse
read_bytesSyntaxErrorprintiter_child_nodesr   r   targetsr   id
startswithr   r   AttributeErrorAssertionErrorr   r   name
ImportFromlevelr   splitnamesaliasasname)
r   r   r    r!   	root_nodeerrorr   targetr/   	real_names
             r   get_names_from_filer:   (   s     If//1122		   e $Y// "E "EdCJ'' !	E, 
 
	%fch77777! )=)=c)B)B )"I(..     '7   D
 s=>> 	E !5!5c!:!: !I &&      	ED#.!A!A 	EzQ ; ,$+2C2CC2H2H2K"K 
 	E 	EdCI.. %{ .$(K		$(I		 $I EY%9%9#%>%> E%id1C1CDDDDDE"E "Es'   &+ 
AA

AAC**C>=C>c                     t          j        |           rt          j        S t          j        |           st          j        |           rt          j        S t          j        S )z Determine the type of an object.)inspectisclassr   r   
isfunction	isbuiltinr   r   )imported_objects    r   get_type_objectrA   Y   sS    '' ~/** !g.?.P.P !  r   packagec                      t           t                    r-t          t          j        j         j                            S t           t                    r4 fdt           j	        j         j         j
                  D             S g S )z(Get all names from a module and package.c                 2    g | ]}t          |          S  )combine).0partial_namer   rB   s     r   
<listcomp>zget_names.<locals>.<listcomp>i   s5     
 
 
 GV\22
 
 
r   )r    r!   )r   r   listget_names_from_compiledr/   sourcer    r	   r:   filepathr!   )r   rB   s   ``r   	get_namesrN   b   s    &.)) 
#GL'.&BSTT
 
 	
 &*%% 	

 
 
 
 
 3!, & 6	! ! !
 
 
 	
 Ir   rL   c           
   #   R  K   ddg}| |v s|                      d          r|sdS |t          j        t          j        fvrdS 	 t	          t          |                     }t          j        |          D ]\  }}|s|                     d          skt          j        |          s(t          j	        |          st          j
        |          r/t          t          |          | | |t          |                    V  dS # t          $ r! t                              |  d           Y dS w xY w)z
    Get the names from a compiled module.

    Instead of using ast, it imports the module.
    Parameters
    ----------
    package : str
        package to import. Must be in sys.path
    underlined : bool
        include underlined names
    builtinspython_crunr#   Nz. could not be imported for autoimport analysis)r,   r   BUILTINSTANDARDr   strr<   
getmembersr=   r>   r?   r   rA   ImportErrorloggerr7   )rB   rL   r    bannedr   r/   values          r   rK   rK   u   si     $ -(F& W//44 Z fnfo66 s7||,,
 #-f55 		 		KD% !5!5 OE**)%00 (//
 D		7GV_U=S=S    		 			    OOOPPPs   C; ;'D&%D&r/   c                 Z    t          |j        |j        | j        | j        |j                  S )z(Combine information to form a full name.)r   r/   modnamerL   	name_type)rB   r   r/   s      r   rF   rF      s"    	6>7<XXXr   )r   FF)F)!__doc__r<   loggingpathlib	importlibr   typingr   r   	rope.baser   defsr   r	   r
   r   r   r   r   r   	getLogger__name__rW   ASTr   PathrT   boolr:   rA   rN   rK   rF   rE   r   r   <module>ri      sJ       # # # # # # " " " " " " " "      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
	8	$	$sw 8     !	.E .EL.E.E .E 	.E
 {D$&'.E .E .E .Eb    j 7 tDz    , & &&& & tT4 	& & & &RYW Yj Y Y Y Y Y Y Y Yr   