B
    S\                 @   s   d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	 ddl
mZ i ZdZdd Zdd	 Zd
d Zdd Zee ee	jee dS )zAstroid hooks for the Python 2 GObject introspection bindings.

Helps with understanding everything imported from 'gi.repository'
    N)MANAGERAstroidBuildingErrornodes)AstroidBuilderz^[A-Za-z_]\w*$c             C   s  i }i }i }i }x
t | D ]}|dr,qtt|s:qyt| |}W n   wY nX t|rl|||< qt|st	|r|||< qt
|st|r|||< qt|dst|dst|dst|rd||< qt|ttfr|||< qt|r|||< qd||< qW d}|r6|d| j 7 }xdt|D ]X}|d  rVq@|| }t|}	t|trdt|d	d
 }	|d||	f 7 }q@W |r|d7 }|r|d| j 7 }x&t|D ]}|d| 7 }|d7 }qW |r|d7 }|r|d| j 7 }x&t|D ]}|d| 7 }|d7 }qW |r>|d7 }|rR|d| j 7 }x|t| D ]l\}}d}
t|tr|d}
|d||
f 7 }t|}|sd}x"| D ]}|d| d 7 }qW |d7 }q`W |S )z`
    Inspect the passed module recursively and build stubs for functions,
    classes, etc.
    __z<flagsz<enum z<GType r    z# %s constants

z"%s"\z\\z%s = %s
z

z# %s functions

zdef %s(*args, **kwargs):
z	    pass
z# %s methods

zdef %s(self, *args, **kwargs):
z# %s classes

object	Exceptionzclass %s(%s):
zpass
z    
)dir
startswithrematch_identifier_regetattrinspectZisclassZ
isfunctionZ	isbuiltinZismethodZismethoddescriptorstrZisdatadescriptor
isinstanceintcallable__name__sortedisdigitreplaceitems
issubclassr
   _gi_build_stub
splitlines)parentclassesZ	functionsZ	constantsmethodsnameobjZretvalZstrvalbaseZclassretline r'   5lib/python3.7/site-packages/astroid/brain/brain_gi.pyr   !   s    









r   c          
   C   s^  |  dst| d| tkr>| g}g }| dkr<|d n| dkrN|d yd}xt||D ]}ytt b y,dd	lm	}m
} td
| td
| W n tk
r   Y nX t| |ttj| 7 }W d Q R X W qb tk
r   ||kr Y qbX qbW W n" tk
r"   d  }t| < Y nX tt|| }|t| < nt|  }|d krZt| d|S )Nzgi.repository.)modnamezgi.repository.GLibzgi._glibzgi.repository.GObjectzgi._gobjectr   r   )PyGIDeprecationWarningPyGIWarningignore)r   r   _inspected_modulesappend	itertoolschainwarningscatch_warningsgir*   r+   simplefilterr
   
__import__r   sysmodulesImportErrorr   r   Zstring_build)r)   modnamesZoptional_modnamesZmodcodemr*   r+   Zastngr'   r'   r(   _import_gi_module   sB    




 


r;   c             C   s   t | jdkrdS tdd | jD s*dS | j}t|tjrl|jdkrJdS t|jtj	rh|jj
dkrhdS dS t|tj	r|j
dkS dS )N   Fc             s   s   | ]}t |tjV  qd S )N)r   r   ZConst).0argr'   r'   r(   	<genexpr>   s    z._looks_like_require_version.<locals>.<genexpr>require_versionr3   T)lenargsallfuncr   r   Z	AttributeZattrnameexprNamer"   )noderD   r'   r'   r(   _looks_like_require_version   s    

rH   c             C   sB   y(dd l }|| jd j| jd j W n tk
r<   Y nX | S )Nr      )r3   r@   rB   valuer
   )rG   r3   r'   r'   r(   _register_require_version   s     rK   )__doc__r   r/   r6   r   r1   Zastroidr   r   r   Zastroid.builderr   r-   r   r   r;   rH   rK   Zregister_failed_import_hookZregister_transformZCallr'   r'   r'   r(   <module>   s    b2
