U
    ÍZj.1  ã                   @   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
 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S )é    N)Ú
get_loader)ÚPyGIDeprecationWarning)ÚCallableInfo)Ú	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__© úX/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-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 k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   r3   r+   r*   r   r   r   Ú__set__@   s    z_DeprecatedAttribute.__set__c                 C   s   t t|ƒ| jƒ d S r	   )r6   r   r&   )r   r3   r   r   r   Ú
__delete__F   s    z_DeprecatedAttribute.__delete__N)r   r!   r"   r#   r   r5   r8   r9   r   r   r   r   r%   ,   s
   r%   c              
   C   s¶  | j  dd¡d }d| }|tjk}tj |¡}t|d tfi ƒ}|| ƒ}|tj|< ddlm} t|dƒsnt	‚|||< zLd	| }zt
|ƒ}	W n tk
r¤   d
}	Y nX |	d
kr¶| W ¢S t |¡}
W 5 ||= tj|= |rà|tj|< X ||_g }t|
dƒrü|
j}|D ]B}zt|
|ƒ}W n  ttfk
�r2   Y �q Y nX t|||ƒ �q t |g ¡D ]`\}}zt||ƒ}W n" tk
�rˆ   t	d| ƒ‚Y nX t||ƒ t||||ƒ}t|||ƒ �qP|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.ZProxyModuler-   )Úmodulesr   zgi.overrides.NÚ__all__z1%s was set deprecated but wasn't added to __all__)r   ÚrsplitÚsysr>   Úgetr   r   ÚimporterÚhasattrÚAssertionErrorr   r0   Ú	importlibÚimport_moduleZ_overrides_moduler?   r   Ú	TypeErrorr7   Ú_deprecated_attrsÚpopr6   r%   )r   r)   Z
module_keyZhas_oldZ
old_moduleÚ
proxy_typeÚproxyr>   Zoverride_package_nameZoverride_loaderZoverride_modZoverride_allÚvarÚitemr*   r,   r+   Údeprecated_attrr   r   r   Úload_overridesK   sb    



ÿ

   ÿrP   c                    s   t | tƒr>| }|j dd¡d }tjd|  ‰ ‡ fdd„}|S t | tjƒrXtd|  ƒ‚n¤zt	| dƒ}W n" t
k
rˆ   td	| j ƒ‚Y nX | j d
¡s¨td| | jf ƒ‚| ¡ }|tks¼t‚|tkrÊ| |_| j dd¡d }tjd|  ‰ tˆ | j| ƒ | S d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	   )r7   r   )Úfunc©Úmoduler   r   Úwrapper®   s    zoverride.<locals>.wrapperz"func must be a gi function, got %sZ__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)N)Ú
isinstancer   r!   r@   rA   r>   ÚtypesÚFunctionTyperH   r   r0   r   Ú
startswithÚKeyErrorZ
get_g_typer   rE   r   Zpytyper7   )Útype_rQ   r)   rT   ÚinfoZg_typer   rR   r   Úoverride¡   s<    
ÿÿ
ÿÿr\   c                    s   t  ˆ ¡‡ ‡fdd„ƒ}|S )z7Decorator for marking methods and classes as deprecatedc                     s$   t jdˆ jˆf tdd� ˆ | |ŽS )Nz %s is deprecated; use %s insteadr-   r.   )r1   r2   r   r   )ÚargsÚkwargs©Úfnr,   r   r   ÚwrappedÔ   s
     ÿzdeprecated.<locals>.wrapped©Ú	functoolsÚwraps)r`   r,   ra   r   r_   r   Ú
deprecatedÒ   s    re   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)rI   Ú
setdefaultÚappend)r)   r*   r,   r   r   r   rO   Ü   s    rO   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           	         sN  |r:t jdd ˆ dt|ƒ… ¡ ˆˆd� ttˆ |ƒƒ}ni }| |¡ g }ˆ ¡ D ](\}}||krT| |¡||< | 	|¡ qT|r¼t jdd ‡fdd„t
|ƒD ƒ¡d t
|ƒ¡f ˆˆd� g }ˆ ¡ D ]&\}}||krÈˆ| ||< | 	|¡ qÈ|�r"t jdd ‡fd	d„t
|ƒD ƒ¡ ˆˆd� ˆD ]}||k�r&| |¡ �q&ˆ| f|Ž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   rh   )Údeprecated_defaultsr   r   rl   7  s     )r1   r2   ÚjoinÚlenÚdictÚzipr   ÚitemsrJ   rg   r   )	r   r]   r^   Z
new_kwargsZaliases_usedÚkeyÚaliasZdefaults_usedr+   ©Ú	arg_namesÚcategoryrk   rm   Úignorer/   Úsuper_init_funcr   r   Únew_init  sP    ý ü
ÿþ üý ü
z!deprecated_init.<locals>.new_initr   )ry   rv   rx   rk   rm   rw   r/   rz   r   ru   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                     sL   ˆ| |Ž}|d r4t |ƒdkr&|d S |dd … S nˆrDˆˆ p@dƒ‚ˆS d S )Nr   r-   r;   zcall failed)ro   )r]   r^   Úret©Úexc_strÚexc_typeÚfail_retÚmethodr   r   ra   K  s    
z%strip_boolean_result.<locals>.wrappedrb   )r�   r   r~   r€   ra   r   r}   r   Ústrip_boolean_resultD  s    r‚   )NNN)rc   rV   r1   rF   rA   Úpkgutilr   Úgir   Zgi._gir   Zgi._constantsr   r   r   Ú__path__r   rI   Ú
ModuleTyper   Úobjectr%   rP   r\   Zoverridefuncre   rO   Útupler{   r‚   r   r   r   r   Ú<module>   s2   
V-
 ý
T