ó
äÛi^c           @@ s
  d  Z  d d l m Z m Z d d l m Z d d l Z d d l m Z m	 Z	 m
 Z
 d d l m Z m Z m Z m Z m Z d d l m Z m Z 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_functiont   absolute_import(   t   deepcopyNi   (   t   Configt   LazyConfigValuet   _is_section_key(   t	   HasTraitst   Instancet   observet   observe_compatt   default(   t   indentt   dedentt   wrap_paragraphst   ConfigurableErrorc           B@ s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR      s   t   MultipleInstanceErrorc           B@ s   e  Z RS(    (   R   R   (    (    (    s<   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 e d ƒ e 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(    (    s<   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(    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   section_namesc   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(    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR)   j   s    			c         C@ sË  | d k r! |  j d t ƒ } n  | d k r< |  j ƒ  } n  |  j | ƒ } |  j ƒ  nxf| j ƒ  D]X\ } } | | k rÆ t | t ƒ r­ t	 |  | ƒ } | j
 | ƒ } n  t |  | t | ƒ ƒ qe t | ƒ re t | t ƒ re d d l m } t |  t ƒ r|  j j }	 n	 d „  }	 | | | ƒ }
 d j d | d |  j j ƒ } t |
 ƒ d k rv| d	 j d
 |
 d ƒ 7} n: t |
 ƒ d k r°| d j d
 d j t |
 ƒ ƒ ƒ 7} n  |	 | ƒ qe qe WWd QXd S(   s    load traits from a Config objectR   i    (   t   get_close_matchesc         S@ s   t  j |  d d ƒS(   Nt
   stackleveli	   (   t   warningst   warn(   t   msg(    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   <lambda>Ÿ   s    u5   Config option `{option}` not recognized by `{klass}`.t   optiont   klassi   u     Did you mean `{matches}`?t   matchess#     Did you mean one of: `{matches}`?s   , N(   R   t   traitst   TrueR'   R)   t   hold_trait_notificationsR   t
   isinstanceR   t   getattrt	   get_valueR   R   R   R   t   difflibR0   t   LoggingConfigurablet   logt   warningt   formatt	   __class__R   t   lent   joint   sorted(   R   R,   R'   R9   R.   t   namet   config_valuet   initialR0   R3   R8   R4   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR   ƒ   s2    		(R   c         C@ s>   |  j  d t ƒ } |  j ƒ  } |  j | j d | d | ƒd S(   sò   Update all the class traits having ``config=True`` in 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   R9   R'   N(   R9   R:   R'   R   t   new(   R   t   changeR9   R'   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   _config_changedª   s    
c         C@ s3   t  |  j ƒ |  _ |  j | ƒ |  j j | ƒ d S(   s%   Update config and load the new valuesN(   R   R   R   R+   (   R   R   (    (    s<   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   RE   RG   t   class_traitsR:   R   t   class_get_trait_helpRF   (   R%   t   instt
   final_helpt   kt   vt   help(    (    s<   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 ƒ ƒ nv y | 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 r0| j t d	 | j f ƒ ƒ n  | j } | d
 k rv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: %rt    s   
iL   N(   R   R<   RO   R   RH   RD   R(   R   R=   t   default_value_reprt	   ExceptionRE   t   valuesRV   RF   R   (   R%   t   traitRR   t   linest   headert   dvrRV   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyRQ   Ü   s*    !)
 	c         C@ s   t  |  j | ƒ ƒ d S(   s4   Get the help string for a single trait and print it.N(   t   printRW   (   R%   RR   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_print_helpü   s    c   	      C@ sE  d „  } d d d } d j  d „  |  j Dƒ ƒ } d |  j | f } | | | d g } |  j ƒ  j d	 ƒ } | r | j } n  | sš t |  d
 d ƒ } n  | rÃ | j | | ƒ ƒ | j d ƒ n  xr t |  j	 d t
 ƒ j ƒ  ƒ D]R \ } } | j | | 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   
#  (   RF   R   t   replace(   t   s(    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR&     s    t   #t   -iN   t   ,c         s@ s   |  ] } | j  Vq d  S(   N(   R   (   t   .0t   p(    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pys	   <genexpr>  s    s   # %s(%s) configurationRY   t   descriptiont   __doc__R   s   #c.%s.%s = %ss   
(   RF   t	   __bases__R   RP   R   t   default_valueR=   R(   RG   t   class_own_traitsR:   R   RV   RZ   (	   R%   R&   t   breakert   parent_classesRd   R^   t   descRH   R]   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_config_section  s$    	+#c   	      C@ sz  g  } |  j  } x[t |  j d t ƒ j ƒ  ƒ D];\ } } | j j  } | d | j } d | k rŠ | d d j d „  | j Dƒ ƒ 7} n | d | 7} | j	 | ƒ y | j
 ƒ  } Wn t k
 rÎ d } n X| d k	 r1t | ƒ d k rþ | d  d	 } n  | j d
 d ƒ } | j	 d | ƒ | j	 d ƒ n  | j p=d } | j	 t t | ƒ d ƒ ƒ | j	 d ƒ q. Wd j | ƒ S(   sw   Generate rST documentation for this class' config options.

        Excludes traits defined on parent classes.
        R   t   .RX   s    : t   |c         s@ s   |  ] } t  | ƒ Vq d  S(   N(   t   repr(   Rh   t   x(    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pys	   <genexpr>0  s    i@   i=   s   ...s   \ns   \\ns       Default: ``%s``RY   s   No descriptioni   s   
N(   R   RG   Rn   R:   R   RD   RH   RF   R\   R(   RZ   R[   R   RE   Rc   RV   R   R   (	   R%   R^   t	   classnameRT   R]   t   ttypet   termlineR`   RV   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   class_config_rst_doc   s.    	+'
(    N(   R   R   R   R   R   R:   R   R   t   classmethodR'   R)   R   R   R   R	   RM   RN   RW   RQ   Rb   Rr   Rz   (    (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR   !   s"   	=	'		R@   c           B@ s/   e  Z d  Z e d ƒ Z e d ƒ 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.LoggerRA   c         C@ s   d d l  m } | j ƒ  S(   Ni    (   RA   (   t	   traitletsRA   t
   get_logger(   R   RA   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   _log_defaultT  s    (   R   R   Rk   R   RA   R
   R~   (    (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR@   L  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$   R   (   R%   t   subclass(    (    s<   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   initializedR‚   R<   t	   _instanceR   (   R%   R   (    (    s<   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(   R„   R   R‚   R<   R   R   (   R%   t   argsR   RR   R   (    (    s<   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?R„   N(   t   hasattrR„   R   (   R%   (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyRƒ   ª  s    N(
   R   R   Rk   R   R„   R{   R‚   R…   R‡   Rƒ   (    (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyR   Z  s   -(   Rk   t
   __future__R    R   t   copyR   R2   t   loaderR   R   R   t   traitlets.traitletsR   R   R   R	   R
   t   ipython_genutils.textR   R   R   R[   R   R   R   R@   R   (    (    (    s<   lib/python2.7/site-packages/traitlets/config/configurable.pyt   <module>   s   (ÿ ,