ó
#ŠNc           @   s±   d  d l  m Z d  d l m Z m Z e d j Z g  Z d e f d „  ƒ  YZ	 d e j
 f d „  ƒ  YZ
 e d „  ƒ Z d	 „  Z e e
 d
 e ƒ e e
 d e ƒ e j d ƒ d S(   i   (   t   modules(   t   variant_new_tuplet   variant_type_from_stringt   GLibt   _VariantCreatorc           B   sè   e  Z i e j j d  6e j j d 6e j j d 6e j j d 6e j j d 6e j j	 d 6e j j
 d 6e j j d 6e j j d 6e j j d	 6e j j d
 6e j j d 6e j j d 6e j j d 6Z d „  Z d „  Z d „  Z d „  Z RS(   t   bt   yt   nt   qt   it   ut   xt   tt   ht   dt   st   ot   gt   vc         C   sé   |  j  j | d ƒ } | rv | d k	 rb | s= t d ƒ ‚ n  | | d ƒ } | | d | d f Sd | d d f Sn  | d d k r– |  j | | ƒ S| j d ƒ rµ |  j | | ƒ S| d d k rÕ |  j | | ƒ St d | ƒ ‚ d S(	   s@  Create a GVariant object from given format and argument list.

        This method recursively calls itself for complex structures (arrays,
        dictionaries, boxed).

        Return a tuple (variant, rest_format, rest_args) with the generated
        GVariant, the remainder of the format string, and the remainder of the
        arguments.

        If args is None, then this won't actually consume any arguments, and
        just parse the format string and generate empty GVariant structures.
        This is required for creating empty dictionaries or arrays.
        i    s/   not enough arguments for GVariant format stringi   t   (s   a{t   as   cannot handle GVariant type N(	   t   _LEAF_CONSTRUCTORSt   gett   Nonet	   TypeErrort   _create_tuplet
   startswitht   _create_dictt   _create_arrayt   NotImplementedError(   t   selft   formatt   argst   constructorR   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   _create/   s    c         C   só   | d } t  j j t d ƒ ƒ } | d k	 rÜ | sQ t | d ƒ t d ƒ k r` t d f ‚ n  xl t t | d ƒ ƒ D]T } | j	 d ƒ r› t d f ‚ n  |  j
 | | d | ƒ \ } } } | j | ƒ qw W| d } n  | j ƒ  | d | f S(	   s>   Handle the case where the outermost type of format is a tuple.i   t   ri    s   expected tuple argumentt   )s&   too many arguments for tuple signatureN(    (   R   t   VariantBuildert   newR   R   t   typeR   t   ranget   lenR   R"   t	   add_valuet   end(   R   R   R    t   builderR	   R   t   _(    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR   S   s    
##c         C   s¼  d } | d k s | d rª |  j | d d ƒ d } |  j | d ƒ d } | j d ƒ sk t d ƒ ‚ n  | d } | t | ƒ t | ƒ  } t j j t | ƒ ƒ } næ t j j t d ƒ ƒ } xË | d j	 ƒ  D]¹ \ } } |  j | d | g ƒ \ } } }	 |  j | | g ƒ \ }
 } }	 | j d ƒ s=t d ƒ ‚ n  | d } t j j t d ƒ ƒ } | j
 | ƒ | j
 |
 ƒ | j
 | j ƒ  ƒ qÓ W| d k	 r©| d } n  | j ƒ  | | f S(	   s=   Handle the case where the outermost type of format is a dict.i    i   i   t   }s(   dictionary type string not closed with }s   a{?*}s   {?*}N(   R   R"   R   t
   ValueErrorR)   R   R%   R&   R   t   itemsR*   R+   (   R   R   R    R,   t   rest_formatt   element_typet   kR   t   key_vR-   t   val_vt   entry(    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR   e   s.    
"
c   	      C   s  d } | d k s | d rl |  j | d d ƒ d } | t | ƒ t | ƒ  } t j j t | ƒ ƒ } nm t j j t d ƒ ƒ } xR t t | d ƒ ƒ D]: } |  j | d | d | ƒ \ } } } | j | ƒ q› W| d k	 rò | d } n  | j	 ƒ  | | f S(   s?   Handle the case where the outermost type of format is an array.i    i   s   a*N(
   R   R"   R)   R   R%   R&   R   R(   R*   R+   (	   R   R   R    R,   R1   R2   R	   R   R-   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR   †   s    '(   t   __name__t
   __module__R   t   Variantt   new_booleant   new_bytet	   new_int16t
   new_uint16t	   new_int32t
   new_uint32t	   new_int64t
   new_uint64t
   new_handlet
   new_doublet
   new_stringt   new_object_patht   new_signaturet   new_variantR   R"   R   R   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR      s&   	$		!R9   c           B   sM   e  Z d  „  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 RS(   c         C   sD   t  ƒ  } | j | | g ƒ \ } } } | r@ t d | ƒ ‚ n  | S(   s½  Create a GVariant from a native Python object.

        format_string is a standard GVariant type signature, value is a Python
        object whose structure has to match the signature.
        
        Examples:
          GLib.Variant('i', 1)
          GLib.Variant('(is)', (1, 'hello'))
          GLib.Variant('(asa{sv})', ([], {'foo': GLib.Variant('b', True), 
                                          'bar': GLib.Variant('i', 2)}))
        s%   invalid remaining format string: "%s"(   R   R"   R   (   t   clst   format_stringt   valuet   creatorR   R1   R-   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   __new__š   s
    	c         C   s   d t  |  d ƒ t ƒ S(   Ns   <GLib.Variant(%s)>t   print(   t   getattrt   True(   R   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   __repr__¬   s    c         C   sö  i |  j  d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d 6|  j d	 6|  j	 d
 6|  j
 d 6|  j
 d 6|  j
 d 6} | j |  j ƒ  ƒ } | rª | ƒ  S|  j ƒ  j d ƒ rý g  t |  j ƒ  ƒ D] } |  j | ƒ j ƒ  ^ qÒ } t | ƒ S|  j ƒ  j d ƒ rpi  } xQ t |  j ƒ  ƒ D]= } |  j | ƒ } | j d ƒ j ƒ  | | j d ƒ j ƒ  <q+W| S|  j ƒ  j d ƒ r·g  t |  j ƒ  ƒ D] } |  j | ƒ j ƒ  ^ q˜S|  j ƒ  j d ƒ rÜ|  j ƒ  j ƒ  St d |  j ƒ  ƒ ‚ d S(   s1   Decompose a GVariant into a native Python object.R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   s   a{i   i    R   R   s   unsupported GVariant type N(   t   get_booleant   get_bytet	   get_int16t
   get_uint16t	   get_int32t
   get_uint32t	   get_int64t
   get_uint64t
   get_handlet
   get_doublet
   get_stringR   t   get_type_stringR   R(   t
   n_childrent   get_child_valuet   unpackt   tuplet   get_variantR   (   R   t   LEAF_ACCESSORSt   laR	   t   resR   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR_   ¯   sB    











1
,/c   	      C   s,  | d k r g  S| j  d ƒ s& | g Sg  } d } | d d !} xæ | r'| d } | | 7} | d } | d k rx qB n  | d k rd } | } | d k r¥ d
 } n d } xc | d k r| d } | | 7} | d } | | k rñ | d 7} q® | | k r® | d 8} q® q® Wn  | j | ƒ d } qB W| S(   sc  Return a list of the element signatures of the topmost signature tuple.

        If the signature is not a tuple, it returns one element with the entire
        signature. If the signature is an empty tuple, the result is [].
        
        This is useful for e. g. iterating over method parameters which are
        passed as a single Variant.
        s   ()R   t    i   iÿÿÿÿi    t   mR   t   {R$   R.   (   Rf   R   (   R   Rg   (   R   t   append(	   t   klasst	   signaturet   resultt   headt   tailt   ct   levelt   upt   down(    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   split_signatureà   s<    
	


	



c         C   sp   |  j  ƒ  d k r" t |  j ƒ  ƒ S|  j  ƒ  j d ƒ sL |  j  ƒ  j d ƒ rV |  j ƒ  St d |  j  ƒ  ƒ ‚ d  S(   NR   R   R   R   R   s'   GVariant type %s does not have a length(   R   R   R   (   R\   R)   R[   R   R]   R   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   __len__  s
    *
c         C   s§  |  j  ƒ  j d ƒ rÓ yA |  j | t d ƒ ƒ } | d  k rK t | ƒ ‚ n  | j ƒ  SWqÓ t k
 rÏ xW t |  j	 ƒ  ƒ D]C } |  j
 | ƒ } | j
 d ƒ j ƒ  | k ry | j
 d ƒ j ƒ  Sqy Wt | ƒ ‚ qÓ Xn  |  j  ƒ  j d ƒ sý |  j  ƒ  j d ƒ rht | ƒ } | d k  r(|  j	 ƒ  | } n  | d k  sF| |  j	 ƒ  k rUt d ƒ ‚ n  |  j
 | ƒ j ƒ  S|  j  ƒ  d k r|  j ƒ  j | ƒ St d |  j  ƒ  ƒ ‚ d  S(   Ns   a{t   *i    i   R   R   s   list index out of rangeR   R   R   s#   GVariant type %s is not a container(   R   R   R   (   R\   R   t   lookup_valueR   R   t   KeyErrorR_   R   R(   R]   R^   t   intt
   IndexErrorR[   t   __getitem__(   R   t   keyt   valR	   R   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyRy     s,    *c         C   s{   |  j  ƒ  j d ƒ s) t d |  j  ƒ  f Sg  } xE t |  j ƒ  ƒ D]1 } |  j | ƒ } | j | j d ƒ j ƒ  ƒ qB W| S(   Ns   a{s$   GVariant type %s is not a dictionaryi    (   R\   R   R   R(   R]   R^   Rh   R_   (   R   Rd   R	   R   (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   keys=  s     (
   R7   R8   RL   RP   R_   t   classmethodRr   Rs   Ry   R|   (    (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR9   ™   s   			15		!c         G   s
   t  | ƒ S(   N(   R   (   RH   t   elements(    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt	   new_tupleG  s    c         C   s   t  j j |  ƒ \ } } | S(   N(   R   R9   R[   (   R   RJ   t   length(    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyR[   K  s    R   R[   N(   t   importerR    t   _giR   R   t   _introspection_moduleR   t   __all__t   objectR   R9   R}   R   R[   t   setattrRh   (    (    (    s5   /usr/lib/python2.7/dist-packages/gi/overrides/GLib.pyt   <module>   s   }®	