o
    bê²^M%  ã                   @   sÄ   d dl Z 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 ¡ Zi Z dd„ Z!dd	„ Z"G d
d„ de#ƒZ$dd„ Z%dS )é    Né   )Ú
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   |   ¡ }|s|  ¡ }|r|jr|jS tS | ¡ }| ¡ }t d| ¡}t||ƒS ©Núgi.repository.)	Ú
get_parentÚ
get_g_typeÚpytypeÚobjectÚget_namespaceÚget_nameÚ	importlibÚimport_moduleÚgetattr)Úobject_infoÚparent_object_infoÚgtypeÚ	namespaceÚnameÚmodule© r-   ú+/usr/lib/python3/dist-packages/gi/module.pyÚget_parent_for_object@   s   

r/   c                 C   sD   g }|   ¡ D ]}| ¡ }| ¡ }t d| ¡}| t||ƒ¡ q|S r   )Úget_interfacesr"   r#   r$   r%   Úappendr&   )r'   Ú
interfacesÚinterface_infor*   r+   r,   r-   r-   r.   Úget_interfaces_for_objectW   s   r4   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   sV   t  ||¡ || _|| _d| | _t  | j¡}|g| _| jdu r)t  | j¡| _dS dS )z"Might raise gi._gi.RepositoryErrorr   N)Ú
repositoryÚrequireÚ
_namespaceÚ_versionÚ__name__Úget_typelib_pathÚ__path__Úget_version)Úselfr*   ÚversionÚpathr-   r-   r.   Ú__init__j   s   

ÿzIntrospectionModule.__init__c                    s   t  | j|¡}|std| j|f ƒ‚t|tƒr�| ¡ }|j}|d u r…| 	¡ r;| 
t¡r0t|ƒ}n|tks6J ‚t|ƒ}n| 
t¡rEt|ƒ}n
|tksKJ ‚t|ƒ}||_d| ¡  |_d dd¡}| ¡ D ]}| ¡  |¡}t|||| ¡ ƒƒ qc| ¡ D ]	}t||j|ƒ q{|tkrŒ||_n¼t|tƒ�r1| ¡ }t|tƒrµt|ƒ‰ t‡ fdd„t |ƒD ƒƒ}	ˆ f|	 }
t!}nKt|t"ƒrÀt#f}
t!}n@t|t$ƒrËt%f}
t!}n5t|t&t'fƒrü| 
t(¡rÛt)f}
n| 
t*¡sé|tksé|j+|krít,f}
nt-d| ¡ | .¡ f ƒ‚t/}nt0|ƒ‚|tk�r|j}|d u�r||
v�r|| j1|< |S |d| j |d	œ}|||
|ƒ}|tk�r0||_nt|t2ƒ�r:|}nt|t3ƒ�rE| ¡ }nt0|ƒ‚|| j1|< |S )
Nz%r object has no attribute %rr   Ú ÚabcdefgjhijklmnopqrstuvwxyzÚABCDEFGJHIJKLMNOPQRSTUVWXYZc                 3   s   � | ]
}t ˆ |ƒs|V  qd S ©N)Ú
issubclass)Ú.0Ú	interface©Úparentr-   r.   Ú	<genexpr>¨   s   € ÿz2IntrospectionModule.__getattr__.<locals>.<genexpr>z$unable to create a wrapper for %s.%s)Ú__info__Ú
__module__Ú	__gtype__)4r6   Úfind_by_namer8   ÚAttributeErrorr:   Ú
isinstancer   r   r    Úis_flagsÚis_ar   r   r   r   r   r   r   rL   r"   rM   Ú	maketransÚ
get_valuesÚget_name_unescapedÚ	translateÚsetattrÚ	get_valueÚget_methodsr   r   r/   Útupler4   r   r   r   r   r   r
   r   r   r   r   Úfundamentalr   Ú	TypeErrorr#   r   ÚNotImplementedErrorÚ__dict__r   r	   )r>   r+   ÚinfoÚg_typeÚwrapperÚascii_upper_transÚ
value_infoÚ
value_nameÚmethod_infor2   ÚbasesÚ	metaclassÚtype_Údict_r-   rI   r.   Ú__getattr__x   s–   ÿ





þ€








ý
€

zIntrospectionModule.__getattr__c                 C   s   t  | j¡}d| j|f S )Nz <IntrospectionModule %r from %r>)r6   r;   r8   )r>   r@   r-   r-   r.   Ú__repr__â   s   zIntrospectionModule.__repr__c                 C   sF   t t| jƒƒ}| | j ¡ ¡ t | j¡}| dd„ |D ƒ¡ t	|ƒS )Nc                 s   s"   � | ]}t |tƒs| ¡ V  qd S rE   )rQ   r   r#   )rG   r`   r-   r-   r.   rK   ð   s   € ÿz.IntrospectionModule.__dir__.<locals>.<genexpr>)
ÚsetÚdirÚ	__class__Úupdater_   Úkeysr6   Ú	get_infosr8   Úlist)r>   ÚresultÚnamespace_infosr-   r-   r.   Ú__dir__æ   s
   zIntrospectionModule.__dir__rE   )r:   rM   Ú__qualname__Ú__doc__rA   rk   rl   rv   r-   r-   r-   r.   r5   b   s    
jr5   c                 C   s0   | t v rt |  S t | ¡}t| |ƒ}|t | < |S )z€
    :Returns:
        An object directly wrapping the gi module without overrides.

    Might raise gi._gi.RepositoryError
    )Ú_introspection_modulesÚgiÚget_required_versionr5   )r*   r?   r,   r-   r-   r.   Úget_introspection_moduleö   s   

r|   )&r$   rz   Ú_gir   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Útypesr   r   Ú
_constantsr   r   r   r   r   Úget_defaultr6   ry   r/   r4   r!   r5   r|   r-   r-   r-   r.   Ú<module>   s   P 