3
KP\'                 @   s  d dl mZ d dlZd dlZejd  dkZy
djZW n  ek
rT   d dlmZ Y nX d 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 dd	l m!Z!m"Z"m#Z#m$Z$m%Z% ej& Z'i Z(d
d Z)dd Z*G d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
GInterface)GObjectMeta
StructMeta)	TYPE_NONE
TYPE_BOXEDTYPE_POINTER	TYPE_ENUM
TYPE_FLAGSc             C   sP   | j  }|s(| j }|r$|jr$|jS t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_objectK   s    
r.   c             C   sH   g }x>| j  D ]2}|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_objectb   s    r1   c               @   s2   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rB| jjd| _| jdkrZt 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__u   s    

zIntrospectionModule.__init__c                s  t j| j|}|s$td| j|f t|tr*|j }|j}|d kr|j	 rz|j
trdt|}q|tksptt|}n(|j
trt|}n|tkstt|}||_d|j  |_tdd}x2|j D ]&}|j j|}t||||j  qW x |j D ]}t||j|  qW |tkr||_nt|tr|j }t|tr|t| t  fddt!|D }	 f|	 }
t"}nt|t#rt$f}
t"}nt|t%rt&f}
t"}ntt|t't(fr|j
t)rt*f}
nB|j
t+s|tks|j,|krt-f}
nt.d|j |j/ f t0}nt1||tkrR|j}|d k	rR||
krR|| j2|< |S |d| j |d}|||
|}|tkr||_n0t|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   r   r   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   s(   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   sF   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>   rL   r,   r,   r-   r@      s    z.IntrospectionModule.__dir__.<locals>.<genexpr>)
setdir	__class__updaterK   keysr3   Z	get_infosr4   list)r:   resultZnamespace_infosr,   r,   r-   __dir__   s
    zIntrospectionModule.__dir__)N)r5   rB   __qualname____doc__r<   rP   rR   rZ   r,   r,   r,   r-   r2   m   s
   
jr2   c             C   s0   | t krt |  S t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   Z
_constantsr   r   r   r   r   Zget_defaultr3   r]   r.   r1   r"   r2   r_   r,   r,   r,   r-   <module>   s$   
P 