
V5'                 @   s  d  d l  m Z d  d l Z d  d l Z e j d  d k Z y d j Z Wn" e k
 rl d  d l m Z Yn Xd  d l	 Z	 d d l
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z m Z e j  Z  d d	 l! m" Z" m# Z# m$ Z$ m% Z% m& Z& e j'   Z( i  Z) d
 d   Z* d d   Z+ Gd d   d e,  Z- d d   Z. d S)    )absolute_importN    )	maketrans   )
RepositoryFunctionInfoRegisteredTypeInfoEnumInfo
ObjectInfoInterfaceInfoConstantInfo
StructInfo	UnionInfoCallbackInfoStructBoxed	CCallbackenum_addenum_register_new_gtype_and_add	flags_add flags_register_new_gtype_and_add_gobject)GObjectMeta
StructMeta)	TYPE_NONE
TYPE_BOXEDTYPE_POINTER	TYPE_ENUM
TYPE_FLAGSc             C   sp   |  j    } | s8 |  j   } | r4 | j r4 | j St S| j   } | j   } t j d |  } t | |  S)Nzgi.repository.)	Z
get_parent
get_g_typepytypeobjectget_namespaceget_name	importlibimport_modulegetattr)object_infoZparent_object_infoZgtype	namespacenamemodule r,   +/usr/lib/python3/dist-packages/gi/module.pyget_parent_for_objectM   s    r.   c             C   sb   g  } xU |  j    D]G } | j   } | j   } t j d |  } | j t | |   q W| S)Nzgi.repository.)Zget_interfacesr#   r$   r%   r&   appendr'   )r(   
interfacesZinterface_infor)   r*   r+   r,   r,   r-   get_interfaces_for_objectd   s    r1   c               @   sI   e  Z d  Z d Z d d d  Z d d   Z d d   Z d	 d
   Z d S)IntrospectionModuleaU  An object which wraps an introspection typelib.

    This wrapping creates a python module like representation of the typelib
    using gi repository as a foundation. Accessing attributes of the module
    will dynamically pull them in and create wrappers for the members.
    These members are then cached on this introspection module.
    Nc             C   s   t  j | |  | |  _ | |  _ d | |  _ t  j |  j  |  _ t r_ |  j j d  |  _ |  j d k r t  j	 |  j  |  _ d S)z"Might raise gi._gi.RepositoryErrorzgi.repository.zUTF-8N)

repositoryZrequire
_namespaceZ_version__name__get_typelib_path__path__	_have_py3decodeZget_version)selfr)   versionr,   r,   r-   __init__w   s    		zIntrospectionModule.__init__c                s  t  j |  j |  } | s4 t d |  j | f   t | t  r| j   } | j } | d  k r| j	   r | j
 t  r t |  } q | t k s t  t |  } n< | j
 t  r t |  } n | t k s t  t |  } | | _ d | j   | _ t d d  } xE | j   D]7 } | j   j |  } t | | | | j     q#Wx' | j   D] } t | | j |  qkW| t k r| | _ nt | t  rw| j   } t | t  rt |    t    f d d   t! |  D  }	   f |	 }
 t" } n t | t#  r2t$ f }
 t" } n t | t%  rSt& f }
 t" } n t | t' t( f  r| j
 t)  rt* f }
 nX | j
 t+  s| t k s| j, | k rt- f }
 n" t. d | j   | j/   f   t0 } n t1 |   | t k r.| j } | d  k	 r.| |
 k r.| |  j2 | <| Sd | d	 d |  j d
 | i } | | |
 |  } | t k r| | _ nB t | t3  r| } n* t | t4  r| j   } n t1 |   | |  j2 | <| S)Nz%r object has no attribute %rzgi.repository.ZabcdefgjhijklmnopqrstuvwxyzZABCDEFGJHIJKLMNOPQRSTUVWXYZc             3   s$   |  ] } t    |  s | Vq d  S)N)
issubclass).0Z	interface)parentr,   r-   	<genexpr>   s    z2IntrospectionModule.__getattr__.<locals>.<genexpr>z$unable to create a wrapper for %s.%s__info__
__module__Z	__gtype__)5r3   Zfind_by_namer4   AttributeErrorr5   
isinstancer
   r    r!   Zis_flagsZis_ar   r   r   AssertionErrorr   r   r   r   rA   r#   rB   r   Z
get_valuesZget_name_unescaped	translatesetattrZ	get_valueZget_methodsr	   r   r.   tupler1   r   r   r   r   
GInterfacer   r   r   r   r   Zfundamentalr   	TypeErrorr$   r   NotImplementedError__dict__r   r   )r:   r*   infoZg_typewrapperZascii_upper_transZ
value_infoZ
value_nameZmethod_infor0   bases	metaclassZtype_Zdict_r,   )r?   r-   __getattr__   s    			 %					"			zIntrospectionModule.__getattr__c             C   s8   t  j |  j  } t r' | j d  } d |  j | f S)NzUTF-8z <IntrospectionModule %r from %r>)r3   r6   r4   r8   r9   )r:   pathr,   r,   r-   __repr__   s    zIntrospectionModule.__repr__c             C   sa   t  t |  j   } | j |  j j    t j |  j  } | j d d   | D  t	 |  S)Nc             s   s*   |  ]  } t  | t  s | j   Vq d  S)N)rD   r   r$   )r>   rM   r,   r,   r-   r@     s    z.IntrospectionModule.__dir__.<locals>.<genexpr>)
setdir	__class__updaterL   keysr3   Z	get_infosr4   list)r:   resultZnamespace_infosr,   r,   r-   __dir__   s
    zIntrospectionModule.__dir__)r5   rB   __qualname____doc__r<   rQ   rS   r[   r,   r,   r,   r-   r2   o   s
   jr2   c             C   s@   |  t  k r t  |  St j |   } t |  |  } | t  |  <| S)z
    :Returns:
        An object directly wrapping the gi module without overrides.

    Might raise gi._gi.RepositoryError
    )_introspection_modulesgiZget_required_versionr2   )r)   r;   r+   r,   r,   r-   get_introspection_module  s    
r`   )/Z
__future__r   sysr%   version_infor8   r   rC   stringr_   Z_gir   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typesr   r   rI   Z
_constantsr   r   r   r   r   Zget_defaultr3   r^   r.   r1   r"   r2   r`   r,   r,   r,   r-   <module>   s$   v	(