ó
ù2¢\c           @   s°   d  Z  d d l Z 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 m Z d „  Z d „  Z d e
 f d	 „  ƒ  YZ d S(
   s5   Manager to read and modify config data in JSON files.iÿÿÿÿN(   t   PY3(   t   LoggingConfigurable(   t   Unicodet   Boolc         C   sš   x“ | j  ƒ  D]… \ } } t | t ƒ ri | |  k rA i  |  | <n  t |  | | ƒ |  | s’ |  | =q’ q | d k rˆ |  j | d ƒ q | |  | <q Wd S(   s^   Recursively update one dictionary using another.

    None values will delete their keys.
    N(   t   itemst
   isinstancet   dictt   recursive_updatet   Nonet   pop(   t   targett   newt   kt   v(    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyR      s    
c         C   s‹   x„ t  |  j ƒ  ƒ D]p \ } } | | k r t | t ƒ rf t |  | | | ƒ |  | s€ |  | =q€ qƒ | | | k rƒ |  | =qƒ q q Wd S(   s?   Recursively remove items from dict that are already in defaultsN(   t   listR   R   R   t   remove_defaults(   t   datat   defaultst   keyt   value(    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyR   (   s    
t   BaseJSONConfigManagerc           B   s_   e  Z d  Z e d ƒ Z e e ƒ Z d „  Z d „  Z	 d „  Z
 e d „ Z d „  Z d „  Z RS(   s   General JSON config manager

    Deals with persisting/storing config in a json file with optionally
    default values in a {section_name}.d directory.
    t   .c         C   sI   y t  j |  j d ƒ Wn+ t k
 rD } | j t j k rE ‚  qE n Xd S(   s,   Will try to create the config_dir directory.ií  N(   t   ost   makedirst
   config_dirt   OSErrort   errnot   EEXIST(   t   selft   e(    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt   ensure_config_dir_exists@   s
    c         C   s   t  j j |  j | d ƒ S(   sP   Returns the json filename for the section_name: {config_dir}/{section_name}.jsons   .json(   R   t   patht   joinR   (   R   t   section_name(    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt	   file_nameH   s    c         C   s   t  j j |  j | d ƒ S(   sN   Returns the directory name for the section name: {config_dir}/{section_name}.ds   .d(   R   R   R    R   (   R   R!   (    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt	   directoryL   s    c      	   C   sä   | r |  j  | ƒ g n g  } |  j ra t j j |  j | ƒ d ƒ } t t j | ƒ ƒ | } n  |  j j	 d | d j | ƒ ƒ i  } xW | D]O } t j j
 | ƒ r t j | d d ƒ } t | t j | ƒ ƒ Wd QXq q W| S(   s  Retrieve the config data for the specified section.

        Returns the data as a dictionary, or an empty dictionary if the file
        doesn't exist.

        When include_root is False, it will not read the root .json file,
        effectively returning the default values.
        s   *.jsons(   Paths used for configuration of %s: 
	%ss   
	t   encodings   utf-8N(   R"   t   read_directoryR   R   R    R#   t   sortedt   globt   logt   debugt   isfilet   iot   openR   t   jsont   load(   R   R!   t   include_roott   pathst   patternR   R   t   f(    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt   getP   s    		#c         C   s¹   |  j  | ƒ } |  j ƒ  |  j rV t j | ƒ } |  j | d t ƒ} t | | ƒ n  t j	 | d d ƒ} t
 rŒ t j | d d d ƒ} n t | d ƒ } |  | j | ƒ Wd QXd S(	   s%   Store the given config data.
        R/   t   indenti   t   wR$   s   utf-8t   wbN(   R"   R   R%   t   copyt   deepcopyR3   t   FalseR   R-   t   dumpsR    R+   R,   t   write(   R   R!   R   t   filenameR   t   json_contentR2   (    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt   setj   s    
	c         C   s0   |  j  | ƒ } t | | ƒ |  j | | ƒ | S(   s‡   Modify the config section by recursively updating it with new_data.

        Returns the modified config data as a dictionary.
        (   R3   R   R>   (   R   R!   t   new_dataR   (    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt   update   s    (   t   __name__t
   __module__t   __doc__R   R   R   t   TrueR%   R   R"   R#   R3   R>   R@   (    (    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyR   6   s   				(   RC   R   R'   R+   R-   R   R7   t   sixR    t   traitlets.configR   t   traitlets.traitletsR   R   R   R   R   (    (    (    s6   lib/python2.7/site-packages/notebook/config_manager.pyt   <module>   s   		