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 )Ú_DeprecatedAttributezÉA 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 q›w t|||ƒ q›t |g ¡D ]+\}}zt||ƒ}W n t
yÕ   td| ƒ‚w t||ƒ t||||ƒ}t|||ƒ q½|S )z¿Loads 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|r�t jdd ‡fd	d„t
|ƒD ƒ¡ ˆˆd� ˆD ]}||v r�| |¡ q’ˆ| fi |¤ŽS )
z†Initializer for a GObject based classes with support for property
        sets through the use of explicit keyword arguments.
        zÒUsing 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/   z…The 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>z�Initializer 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