
    f1                        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m	Z	 d dl
mZmZ d dlmZ  eee      Zi Z G d dej$                        Z G d d	e      Zd
 Zd ZeZ	 d Zd Z e       i i edfdZddZd Zy)    N)PyGIDeprecationWarning)CallableInfopygobject_new_full)	TYPE_NONETYPE_INVALID)extend_pathc                   4     e Zd ZdZ fdZd Zd Zd Z xZS )OverridesProxyModulez7Wraps a introspection module and contains all overridesc                 N    t         t        |   |j                         || _        y N)superr
   __init____name___introspection_module)selfintrospection_module	__class__s     7/usr/lib/python3/dist-packages/gi/overrides/__init__.pyr   zOverridesProxyModule.__init__   s$    "D2 ))	+%9"    c                 .    t        | j                  |      S r   )getattrr   )r   names     r   __getattr__z OverridesProxyModule.__getattr__   s    t11488r   c                     t        t        | j                              }|j                  | j                  j                                |j                  t        | j                               t        |      S r   )setdirr   update__dict__keysr   sorted)r   results     r   __dir__zOverridesProxyModule.__dir__!   sO    S()dmm((*+c$4456f~r   c                 N    dt        |       j                  d| j                  dS )N< >)typer   r   )r   s    r   __repr__zOverridesProxyModule.__repr__'   s     J//1K1KLLr   )	r   
__module____qualname____doc__r   r   r"   r(   __classcell__)r   s   @r   r
   r
      s    A:
9Mr   r
   c                   (    e Zd ZdZd Zd Zd Zd Zy)_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                 R    || _         || _        t        |d|d|d      | _        y )N. is deprecated; use  instead)_attr_valuer   _warning)r   	namespaceattrvaluereplacements        r   r   z_DeprecatedAttribute.__init__2   s(    
.4./r   c                     |t        | j                        t        j                  | j                  d       | j
                  S )N   
stacklevel)AttributeErrorr3   warningswarnr5   r4   )r   instanceowners      r   __get__z_DeprecatedAttribute.__get__9   s3     ,,dmm2{{r   c                 `    | j                   }t        t        |      |       t        |||       y r   )r3   delattrr'   setattr)r   rA   r8   r7   s       r   __set__z_DeprecatedAttribute.__set__?   s%    zzX%$&r   c                 B    t        t        |      | j                         y r   )rE   r'   r3   )r   rA   s     r   
__delete__z_DeprecatedAttribute.__delete__E   s    X

+r   N)r   r)   r*   r+   r   rC   rG   rI    r   r   r.   r.   +   s    /',r   r.   c                 l   | j                   j                  dd      d   }d|z   }|t        j                  v }t        j                  j	                  |      }t        |dz   t        fi       } ||       }|t        j                  |<   ddlm} t        |d      sJ |||<   	 d	|z   }t        j                  j                  |      }	|	|	j                  nd
}
|
,| ||= t        j                  |= |r|t        j                  |<   S S t        j                  |      }||= t        j                  |= |r|t        j                  |<   	 ||_        g }t        |d      r|j                  }|D ]  }	 t!        ||      }t'        |||        t(        j+                  |g       D ]9  \  }}	 t!        ||      }t/        ||       t1        ||||      }t'        |||       ; |S # ||= t        j                  |= |r|t        j                  |<   w w xY w# t"        t$        f$ r Y w xY w# t"        $ r t-        d|z        w xY w)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.
    r0      gi.repository.ProxyModuler;   )modulesr   zgi.overrides.N__all__z1%s was set deprecated but wasn't added to __all__)r   rsplitsysrP   getr'   r
   importerhasattr	importlibutil	find_specloaderimport_module_overrides_modulerQ   r   r>   	TypeErrorrF   _deprecated_attrspopAssertionErrorrE   r.   )r   r6   
module_keyhas_old
old_module
proxy_typeproxyrP   override_package_namespecoverride_loaderoverride_modoverride_allvaritemr7   r9   r8   deprecated_attrs                      r   load_overridesrn   J   sn    %--44S!<R@I!I-J CKK'G,J i-/2F1I2NJ+,E#CKK
 #51222GI1 /) ;~~''(=>)-)9$++t "'
 IKK
#&0CKK
#  !../DE IKK
#&0CKK
# $EL|Y'#++ "	<-D 	sD!" /229bA 	3k	LE4(E 	t.tUK1
D/2	3 LK IKK
#&0CKK
# " 	* 		  	L CdJL L	Ls0    7G G (H H,HHHH3c                    t        | t              r>| }|j                  j                  dd      d   }t        j
                  d|z      fd}|S t        | t        j                        rt        d| z        	 t        | d      }| j                  j                  d	      st        d
| d| j                  d      |j                         }|t        k7  sJ |t         k7  r| |_        | j                  j                  dd      d   }t        j
                  d|z      t%        | j                  |        | S # t        $ r t        d| j                  z        w xY w)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.
    r0   rL   rM   rN   c                 6    t        | j                  |        | S r   )rF   r   )funcmodules    r   wrapperzoverride.<locals>.wrapper   s    FDMM40Kr   z"func must be a gi function, got %s__info__zKCan not override a type %s, which is not in a gobject introspection typelibzgi.overrideszNYou have tried override outside of the overrides module. This is not allowed (, ))
isinstancer   r)   rR   rS   rP   typesFunctionTyper]   r   r>   r   
startswithKeyError
get_g_typer   r   pytyperF   )type_rq   r6   rs   infog_typerr   s         @r   overrider      sW    %&OO**3226	-	9:	 	E5--	.<uDEE	:5*-D **>:279I9IKL L """"\!!FM$$++C3B7	-	9:.'  	:(*/..9: :	:s   9D5 5"Ec                 F     t        j                          fd       }|S )z7Decorator for marking methods and classes as deprecatedc                  l    t        j                  j                  ddt        d        | i |S )Nr1   r2   r;   r<   )r?   r@   r   r   )argskwargsfnr9   s     r   wrappedzdeprecated.<locals>.wrapped   s/    BKKU,	<4"6""r   	functoolswraps)r   r9   r   s   `` r   
deprecatedr      s%    __R# # Nr   c                 R    t         j                  | g       j                  ||f       y)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)r^   
setdefaultappend)r6   r7   r9   s      r   rm   rm      s$    "   B/66k7JKr   r;   c                 *      f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           
      :   |rLt        j                  ddj                  	dt        |             z  
       t	        t        	|            }ni }|j                  |       g }j                         D ]/  \  }}||v s|j                  |      ||<   |j                  |       1 |rXt        j                  ddj                  fdt        |      D              ddj                  t        |            d
       g }j                         D ]#  \  }}||vs|   ||<   |j                  |       % |r<t        j                  d	dj                  fd
t        |      D              z  
       D ]  }||v s|j                  |         | 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/InitializerDeprecationsru   Nr<   zThe keyword(s) "c              3   (   K   | ]	  }|     y wr   rJ   ).0kdeprecated_aliasess     r   	<genexpr>z4deprecated_init.<locals>.new_init.<locals>.<genexpr>"  s     $Yq%7%:$Ys   z$" have been deprecated in favor of "zM" respectively. See: https://wiki.gnome.org/PyGObject/InitializerDeprecationszInitializer is relying on deprecated non-standard defaults. Please update to explicitly use: %s See: https://wiki.gnome.org/PyGObject/InitializerDeprecationsc              3   2   K   | ]  }|d |     yw)=NrJ   )r   r   deprecated_defaultss     r   r   z4deprecated_init.<locals>.new_init.<locals>.<genexpr>1  s     #iaq2Ea2H$I#is   )r?   r@   joinlendictzipr   itemsr_   r   r    )r   r   r   
new_kwargsaliases_usedkeyaliasdefaults_usedr8   	arg_namescategoryr   r   ignorer=   super_init_funcs            r   new_initz!deprecated_init.<locals>.new_init  s   
 MM Z ))Ijs4y$9:; #z	;
 c)T23JJ&! ,224 	)JC
"",.."7
3##C(	)
 MM99$YF<DX$YY99VL%9:< #z	; -335 	*JC*$"5c":
3$$S)	*
 MM Z ))#iSYZgSh#iij #z	;  	$Cj s#	$ t2z22r   rJ   )r   r   r   r   r   r   r=   r   s   ``````` r   deprecated_initr      s    <13 13f Or   c                 N     t        j                          f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                  n     | i |}|d   rt        |      dk(  r|d   S |dd  S r xs d      S )Nr   r;   rL   zcall failed)r   )r   r   retexc_strexc_typefail_retmethods      r   r   z%strip_boolean_result.<locals>.wrappedE  sP    d%f%q63x1}1v12ww7-88Or   r   )r   r   r   r   r   s   ```` r   strip_boolean_resultr   >  s'     __V
 
 Nr   c                       fd}|S )Nc                 H    t        | d      } t        |d      } | |g| S )NF)r   )ab	user_datarq   s      r   wrapz'wrap_list_store_sort_func.<locals>.wrapV  s-    q%(q%(Aq%9%%r   rJ   )rq   r   s   ` r   wrap_list_store_sort_funcr   T  s    &
 Kr   )NNN)r   rx   r?   rW   rS   gir   gi._gir   r   gi._constantsr   r   pkgutilr   __path__r   r^   
ModuleTyper
   objectr.   rn   r   overridefuncr   rm   tupler   r   r   rJ   r   r   <module>r      s        
 % 3
  x*  M5++ M*,6 ,>Nb*Z  L( 8=w')r3 Qh,r   