ó
æNXc           @  sü   d  Z  d d l m 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 m Z m Z d d	 l m Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s/   A base class for objects that are configurable.iÿÿÿÿ(   t   print_functionN(   t   deepcopyi   (   t   Configt   LazyConfigValue(   t	   HasTraitst   Instance(   t   indentt   dedentt   wrap_paragraphs(   t	   iteritemst   ConfigurableErrorc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR
      s   t   MultipleInstanceErrorc           B  s   e  Z RS(    (   R   R   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR      s   t   Configurablec           B  sÂ   e  Z e e d i  ƒ Z e d  d e ƒZ d „  Z e d „  ƒ Z	 d „  Z
 d d d „ Z d „  Z d „  Z e d d „ ƒ Z e d d	 „ ƒ Z e d d
 „ ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s*   traitlets.config.configurable.Configurablet
   allow_nonec         K  sÓ   | j  d d ƒ } | d k	 rR | j d d ƒ d k rF | j | d <n  | |  _ n  | j  d d ƒ } t t |  ƒ j |   | d k	 r’ | |  _ n |  j |  j ƒ x* | j	 ƒ  D] \ } } t
 |  | | ƒ q¯ Wd S(   s„  Create a configurable given a config config.

        Parameters
        ----------
        config : Config
            If this is empty, default values are used. If config is a
            :class:`Config` instance, it will be used to configure the
            instance.
        parent : Configurable instance, optional
            The parent Configurable instance of this object.

        Notes
        -----
        Subclasses of Configurable must call the :meth:`__init__` method of
        :class:`Configurable` *before* doing anything else and using
        :func:`super`::

            class MyConfigurable(Configurable):
                def __init__(self, config=None):
                    super(MyConfigurable, self).__init__(config=config)
                    # Then any other code you need to finish initialization.

        This ensures that instances will be configured properly.
        t   parentt   configN(   t   popt   Nonet   getR   R   t   superR   t   __init__t   _load_configt   itemst   setattr(   t   selft   kwargsR   R   t   keyt   value(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR   '   s    c         C  sA   g  t  |  j ƒ D]- } t | t ƒ r t |  | ƒ r | j ^ q S(   s   return section names as a list(   t   reversedt   __mro__t
   issubclassR   R   (   t   clst   c(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   section_namesd   s    c         C  s†   | g } |  j  r. | j |  j  j | ƒ ƒ n  t ƒ  } xH | D]@ } x7 |  j ƒ  D]) } | j | ƒ rQ | j | | ƒ qQ qQ Wq> W| S(   sã  extract my config from a global Config object
        
        will construct a Config object of only the config values that apply to me
        based on my mro(), as well as those of my parent(s) if they exist.
        
        If I am Bar and my parent is Foo, and their parent is Tim,
        this will return merge following config sections, in this order::
        
            [Bar, Foo.bar, Tim.Foo.Bar]
        
        With the last item being the highest priority.
        (   R   t   appendt   _find_my_configR   R#   t   _has_sectiont   merge(   R   t   cfgt   cfgst	   my_configR"   t   sname(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR%   k   s    			c      
   C  sÔ   | d k r! |  j d t ƒ } n  | d k r< |  j ƒ  } n  |  j | ƒ } |  j ƒ  w xo t | ƒ D]a \ } } | | k re t | t ƒ r­ t	 |  | ƒ } | j
 | ƒ } n  t |  | t | ƒ ƒ qe qe WWd QXd S(   s    load traits from a Config objectR   N(   R   t   traitst   TrueR#   R%   t   hold_trait_notificationsR	   t
   isinstanceR   t   getattrt	   get_valueR   R   (   R   R(   R#   R,   R*   t   namet   config_valuet   initial(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR   „   s    c         C  s;   |  j  d t ƒ } |  j ƒ  } |  j | d | d | ƒd S(   sò   Update all the class traits having ``config=True`` as metadata.

        For any class trait with a ``config`` metadata attribute that is
        ``True``, we update the trait with the value of the corresponding
        config entry.
        R   R,   R#   N(   R,   R-   R#   R   (   R   R2   t   oldt   newR,   R#   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   _config_changedœ   s    c         C  s)   t  |  j ƒ } | j | ƒ | |  _ d S(   s2   Fire the traits events when the config is updated.N(   R   R   R'   (   R   R   t	   newconfig(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   update_config¬   s    c         C  s±   | d k s! t | |  ƒ s! t ‚ g  } | j d |  j ƒ | j t | d ƒ d ƒ xK t |  j d t ƒ j	 ƒ  ƒ D]+ \ } } |  j
 | | ƒ } | j | ƒ qu Wd j | ƒ S(   s«   Get the help string for this class in ReST format.
        
        If `inst` is given, it's current trait values will be used in place of
        class defaults.
        u
   %s optionsi    u   -R   s   
N(   R   R/   t   AssertionErrorR$   R   t   lent   sortedt   class_traitsR-   R   t   class_get_trait_helpt   join(   R!   t   instt
   final_helpt   kt   vt   help(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_get_help¶   s    !+c         C  sŒ  | d k s! t | |  ƒ s! t ‚ g  } d |  j | j | j j f } | j | ƒ | d k	 rˆ | j t d t | | j ƒ d ƒ ƒ ny y t	 | j
 ƒ } Wn t k
 r´ d } n X| d k	 rt | ƒ d k rä | d  d } n  | j t d | d ƒ ƒ n  d | j j k r3| j t d	 | j f ƒ ƒ n  | j d
 ƒ } | d k	 rd j t | d ƒ ƒ } | j t | d ƒ ƒ n  d j | ƒ S(   s£   Get the help string for a single trait.
        
        If `inst` is given, it's current trait values will be used in place of
        the class default.
        s   --%s.%s=<%s>s   Current: %ri   i@   i=   s   ...s   Default: %st   Enums   Choices: %rRD   s   
iL   N(   R   R/   R:   R   R2   t	   __class__R$   R   R0   t   reprt   default_valuet	   ExceptionR;   t   valuest   get_metadataR?   R   (   R!   t   traitR@   t   linest   headert   dvrRD   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR>   Æ   s*    !)
 c         C  s   t  |  j | ƒ ƒ d S(   s4   Get the help string for a single trait and print it.N(   t   printRE   (   R!   R@   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_print_helpæ   s    c   	      C  s#  d „  } d d d } d |  j  } | | | d g } |  j ƒ  j d ƒ } | r] | j } n t |  d d ƒ } | r˜ | j | | ƒ ƒ | j d ƒ n  x{ t |  j d	 t ƒ ƒ D]a \ } } | j	 d
 ƒ pÏ d } | j | | ƒ ƒ | j d |  j  | | j f ƒ | j d ƒ q± Wd j
 | ƒ S(   s#   Get the config class config sectionc         S  s,   d j  t |  d ƒ ƒ }  d |  j d d ƒ S(   s"   return a commented, wrapped block.s   

iN   s   # s   
s   
# (   R?   R   t   replace(   t   s(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR"   î   s    t   #t   -iN   s   # %s configurationt    t   descriptiont   __doc__R   RD   s   # c.%s.%s = %rs   
(   R   R=   R   RI   R0   R$   R	   t   class_own_traitsR-   RL   R?   (	   R!   R"   t   breakerRT   RN   t   descR2   RM   RD   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_config_sectionë   s"    	% c   
      C  s¯  g  } |  j  } xt |  j d t ƒ j ƒ  ƒ D]p\ } } | j j  } | d | j } d | k rŠ | d d j d „  | j Dƒ ƒ 7} n | d | 7} | j	 | ƒ y | j
 } t | ƒ } Wn t k
 rÛ d } } n X| d k	 rJ| d k	 rJt | ƒ d k r| d  d	 } n  | j d
 d ƒ } | j	 d | ƒ | j	 d ƒ n  | j d ƒ }	 |	 d k	 r„| j	 t t |	 ƒ d ƒ ƒ n | j	 d ƒ | j	 d ƒ q. Wd j | ƒ S(   sw   Generate rST documentation for this class' config options.

        Excludes traits defined on parent classes.
        R   t   .RF   s    : t   |c         s  s   |  ] } t  | ƒ Vq d  S(   N(   RH   (   t   .0t   x(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pys	   <genexpr>  s    i@   i=   s   ...s   \ns   \\ns       Default: ``%s``RW   RD   i   s       No descriptions   
N(   R   R<   RZ   R-   R   RG   R2   R?   RK   R$   RI   RH   RJ   R   R;   RS   RL   R   R   (
   R!   RN   t	   classnameRB   RM   t   ttypet   termlinet   dvRP   RD   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_config_rst_doc
  s4    	+'	(    N(   R   R   R   R   R   R-   R   R   t   classmethodR#   R%   R   R   R7   R9   RE   R>   RR   R]   Rf   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyR   "   s    	=			
t   SingletonConfigurablec           B  sP   e  Z d  Z d Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 RS(   sô   A configurable that only allows one instance.

    This class is for classes that should only have one instance of itself
    or *any* subclass. To create and retrieve such a class use the
    :meth:`SingletonConfigurable.instance` method.
    c         c  sM   xF |  j  ƒ  D]8 } t |  | ƒ r t | t ƒ r | t k r | Vq q Wd S(   sf   Walk the cls.mro() for parent classes that are also singletons

        For use in instance()
        N(   t   mroR    Rh   (   R!   t   subclass(    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt	   _walk_mroD  s
    c         C  sI   |  j  ƒ  s d Sx2 |  j ƒ  D]$ } t | j |  ƒ r d | _ q q Wd S(   s>   unset _instance for this class and singleton parents.
        N(   t   initializedRk   R/   t	   _instanceR   (   R!   Rj   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   clear_instanceQ  s
    c         O  sq   |  j  d k rA |  | | Ž  } x  |  j ƒ  D] } | | _  q+ Wn  t |  j  |  ƒ rZ |  j  St d |  j ƒ ‚ d S(   s³  Returns a global instance of this class.

        This method create a new instance if none have previously been created
        and returns a previously created instance is one already exists.

        The arguments and keyword arguments passed to this method are passed
        on to the :meth:`__init__` method of the class upon instantiation.

        Examples
        --------

        Create a singleton class using instance, and retrieve it::

            >>> from traitlets.config.configurable import SingletonConfigurable
            >>> class Foo(SingletonConfigurable): pass
            >>> foo = Foo.instance()
            >>> foo == Foo.instance()
            True

        Create a subclass that is retrived using the base class instance::

            >>> class Bar(SingletonConfigurable): pass
            >>> class Bam(Bar): pass
            >>> bam = Bam.instance()
            >>> bam == Bar.instance()
            True
        sA   Multiple incompatible subclass instances of %s are being created.N(   Rm   R   Rk   R/   R   R   (   R!   t   argsR   R@   Rj   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   instance]  s    c         C  s   t  |  d ƒ o |  j d k	 S(   s   Has an instance been created?Rm   N(   t   hasattrRm   R   (   R!   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyRl   Š  s    N(
   R   R   RY   R   Rm   Rg   Rk   Rn   Rp   Rl   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyRh   :  s   -t   LoggingConfigurablec           B  s#   e  Z d  Z e d ƒ Z d „  Z RS(   s«   A parent class for Configurables that log.

    Subclasses have a log trait, and the default behavior
    is to get the logger from the currently running Application.
    s   logging.Loggerc         C  s   d d l  m } | j ƒ  S(   Niÿÿÿÿ(   t   log(   t	   traitletsRs   t
   get_logger(   R   Rs   (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   _log_default˜  s    (   R   R   RY   R   Rs   Rv   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyRr     s   (   RY   t
   __future__R    t   loggingt   copyR   t   loaderR   R   t   traitlets.traitletsR   R   t   ipython_genutils.textR   R   R   t   ipython_genutils.py3compatR	   RJ   R
   R   R   Rh   Rr   (    (    (    sU   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/traitlets/config/configurable.pyt   <module>   s   ÿ V