o
    T`2                     @   s   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 d dlmZ d dl	m
Z
mZ d dlmZmZ d dlmZ eeeZi ZG dd dejZG d	d
 d
eZdd Zdd ZeZ	 dd Zdd Ze i i edfddZdddZdd ZdS )    N)
get_loader)PyGIDeprecationWarning)CallableInfopygobject_new_full)	TYPE_NONETYPE_INVALID)extend_pathc                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
OverridesProxyModulez7Wraps a introspection module and contains all overridesc                    s   t t| |j || _d S N)superr	   __init____name___introspection_module)selfintrospection_module	__class__ 7/usr/lib/python3/dist-packages/gi/overrides/__init__.pyr      s   

zOverridesProxyModule.__init__c                 C   s   t | j|S r
   )getattrr   )r   namer   r   r   __getattr__   s   z OverridesProxyModule.__getattr__c                 C   s6   t t| j}|| j  |t| j t|S r
   )setdirr   update__dict__keysr   sorted)r   resultr   r   r   __dir__"   s   zOverridesProxyModule.__dir__c                 C   s   dt | j| jf S )Nz<%s %r>)typer   r   )r   r   r   r   __repr__(   s   zOverridesProxyModule.__repr__)	r   
__module____qualname____doc__r   r   r   r!   __classcell__r   r   r   r   r	      s    r	   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_DeprecatedAttributezA deprecation descriptor for OverridesProxyModule subclasses.

    Emits a PyGIDeprecationWarning on every access and tries to act as a
    normal instance attribute (can be replaced and deleted).
    c                 C   s$   || _ || _td|||f | _d S )Nz#%s.%s is deprecated; use %s instead)_attr_valuer   _warning)r   	namespaceattrvaluereplacementr   r   r   r   3   s   
z_DeprecatedAttribute.__init__c                 C   s(   |d u r	t | jtj| jdd | jS )N   
stacklevel)AttributeErrorr'   warningswarnr)   r(   )r   instanceownerr   r   r   __get__:   s   
z_DeprecatedAttribute.__get__c                 C   s$   | j }tt|| t||| d S r
   )r'   delattrr    setattr)r   r4   r,   r+   r   r   r   __set__@   s   z_DeprecatedAttribute.__set__c                 C   s   t t|| j d S r
   )r7   r    r'   )r   r4   r   r   r   
__delete__F   s   z_DeprecatedAttribute.__delete__N)r   r"   r#   r$   r   r6   r9   r:   r   r   r   r   r&   ,   s    r&   c              
   C   s  | j ddd }d| }|tjv }tj|}t|d tfi }|| }|tj|< ddlm} t|ds7J |||< zAd	| }zt	|}	W n t
yQ   d
}	Y nw |	d
u rh| W ||= tj|= |rg|tj|< S S t|}
W ||= tj|= |r||tj|< n||= tj|= |r|tj|< w ||_g }t|
dr|
j}|D ]}zt|
|}W n t
tfy   Y qw t||| qt|g D ]+\}}zt||}W n t
y   td| w t|| t||||}t||| q|S )zLoads overrides for an introspection module.

    Either returns the same module again in case there are no overrides or a
    proxy module including overrides. Doesn't cache the result.
    .   gi.repository.ProxyModuler.   )modulesr   zgi.overrides.N__all__z1%s was set deprecated but wasn't added to __all__)r   rsplitsysr@   getr    r	   importerhasattrr   r1   	importlibimport_module_overrides_modulerA   r   	TypeErrorr8   _deprecated_attrspopAssertionErrorr7   r&   )r   r*   
module_keyhas_old
old_module
proxy_typeproxyr@   override_package_nameoverride_loaderoverride_modoverride_allvaritemr+   r-   r,   deprecated_attrr   r   r   load_overridesK   sv   




rZ   c                    s   t | tr| }|jddd }tjd|    fdd}|S t | tjr+td|  zt	| d}W n t
y@   td	| j w | jd
sPtd| | jf | }|tksZJ |tkra| |_| jddd }tjd|   t | j|  | S )a  Decorator for registering an override.

    Other than objects added to __all__, these can get referenced in the same
    override module via the gi.repository module (get_parent_for_object() does
    for example), so they have to be added to the module immediately.
    r;   r<   r=   r>   c                    s   t  | j|  | S r
   )r8   r   funcmoduler   r   wrapper   s   zoverride.<locals>.wrapperz"func must be a gi function, got %s__info__zKCan not override a type %s, which is not in a gobject introspection typelibzgi.overrideszUYou have tried override outside of the overrides module. This is not allowed (%s, %s))
isinstancer   r"   rB   rC   r@   typesFunctionTyperJ   r   r1   r   
startswithKeyError
get_g_typer   r   pytyper8   )type_r\   r*   r_   infog_typer   r]   r   override   s>   
rk   c                    s   t   fdd}|S )z7Decorator for marking methods and classes as deprecatedc                     s(   t jd jf tdd  | i |S )Nz %s is deprecated; use %s insteadr.   r/   )r2   r3   r   r   )argskwargsfnr-   r   r   wrapped   s   zdeprecated.<locals>.wrapped	functoolswraps)ro   r-   rp   r   rn   r   
deprecated   s   rt   c                 C   s   t | g ||f dS )a:  Marks a module level attribute as deprecated. Accessing it will emit
    a PyGIDeprecationWarning warning.

    e.g. for ``deprecated_attr("GObject", "STATUS_FOO", "GLib.Status.FOO")``
    accessing GObject.STATUS_FOO will emit:

        "GObject.STATUS_FOO is deprecated; use GLib.Status.FOO instead"

    :param str namespace:
        The namespace of the override this is called in.
    :param str namespace:
        The attribute name (which gets added to __all__).
    :param str replacement:
        The replacement text which will be included in the warning.
    N)rK   
setdefaultappend)r*   r+   r-   r   r   r   rY      s   rY   r.   c                    s    fdd}|S )a  Wrapper for deprecating GObject based __init__ methods which specify
    defaults already available or non-standard defaults.

    :param callable super_init_func:
        Initializer to wrap.
    :param list arg_names:
        Ordered argument name list.
    :param list ignore:
        List of argument names to ignore when calling the wrapped function.
        This is useful for function which take a non-standard keyword that is munged elsewhere.
    :param dict deprecated_aliases:
        Dictionary mapping a keyword alias to the actual g_object_newv keyword.
    :param dict deprecated_defaults:
        Dictionary of non-standard defaults that will be used when the
        keyword is not explicitly passed.
    :param Exception category:
        Exception category of the error.
    :param int stacklevel:
        Stack level for the deprecation passed on to warnings.warn
    :returns: Wrapped version of ``super_init_func`` which gives a deprecation
        warning when non-keyword args or aliases are used.
    :rtype: callable
    c           	         sL  |rt jdd dt|  d tt |}ni }|| g } D ]\}}||v r>||||< |	| q*|r^t jddfddt
|D dt
|f d g } D ]\}}||vrw| ||< |	| qd|rt jddfd	dt
|D  d D ]}||v r|| q| fi |S )
zInitializer for a GObject based classes with support for property
        sets through the use of explicit keyword arguments.
        zUsing positional arguments with the GObject constructor has been deprecated. Please specify keyword(s) for "%s" or use a class specific constructor. See: https://wiki.gnome.org/PyGObject/InitializerDeprecationsz, Nr/   zThe keyword(s) "%s" have been deprecated in favor of "%s" respectively. See: https://wiki.gnome.org/PyGObject/InitializerDeprecationsc                 3   s    | ]} | V  qd S r
   r   .0k)deprecated_aliasesr   r   	<genexpr>(  s    z4deprecated_init.<locals>.new_init.<locals>.<genexpr>zInitializer is relying on deprecated non-standard defaults. Please update to explicitly use: %s See: https://wiki.gnome.org/PyGObject/InitializerDeprecationsc                 3   s     | ]}d | | f V  qdS )z%s=%sNr   rw   )deprecated_defaultsr   r   r{   7  s    )r2   r3   joinlendictzipr   itemsrL   rv   r   )	r   rl   rm   
new_kwargsaliases_usedkeyaliasdefaults_usedr,   	arg_namescategoryrz   r|   ignorer0   super_init_funcr   r   new_init  sP   



z!deprecated_init.<locals>.new_initr   )r   r   r   rz   r|   r   r0   r   r   r   r   deprecated_init   s   3r   c                    s    t  fdd}|S )a  Translate method's return value for stripping off success flag.

    There are a lot of methods which return a "success" boolean and have
    several out arguments. Translate such a method to return the out arguments
    on success and None on failure.
    c                     sJ   | i |}|d rt |dkr|d S |dd  S r# p!dS )Nr   r.   r<   zcall failed)r~   )rl   rm   retexc_strexc_typefail_retmethodr   r   rp   K  s   z%strip_boolean_result.<locals>.wrappedrq   )r   r   r   r   rp   r   r   r   strip_boolean_resultD  s   r   c                    s    fdd}|S )Nc                    s&   t | d} t |d} | |g|R  S )NF)r   )ab	user_datar[   r   r   wrap\  s   

z'wrap_list_store_sort_func.<locals>.wrapr   )r\   r   r   r[   r   wrap_list_store_sort_funcZ  s   r   )NNN) rr   rb   r2   rG   rC   pkgutilr   gir   gi._gir   r   gi._constantsr   r   r   __path__r   rK   
ModuleTyper	   objectr&   rZ   rk   overridefuncrt   rY   tupler   r   r   r   r   r   r   <module>   s6    
V-


T