
    JeD                     .   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mZ	 ddl
Z
ddlZddlZddlmZmZ ddlmZmZ ddlmZ  G d d      Z G d d	ej,                  e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)z
This module provides user configuration file management features for Spyder.

It is based on the ConfigParser module present in the standard library.
    N)get_conf_pathget_module_source_path)is_text_stringto_text_string)check_versionc                       e Zd Zy)	NoDefaultN)__name__
__module____qualname__     4/usr/lib/python3/dist-packages/spyder/config/user.pyr	   r	   !   s    r   r	   c                   D     e Zd ZdZ fdZd Z fdZd Zd Zd Z	 xZ
S )DefaultsConfigzM
    Class used to save defaults to a file and as UserConfig base class.
    c                    t         t        |   d       || _        || _        t        j                  t        j                  | j                              s3t        j                  t        j                  | j                               yy)zU
        Class used to save defaults to a file and as UserConfig base class.
        N)interpolation)
superr   __init___name_pathospisdirdirnameosmakedirs)selfnamepath	__class__s      r   r   zDefaultsConfig.__init__-   s\     	nd,4,@

yyTZZ01KKDJJ/0 2r   c                    | j                   r|j                  dj                  t        j                               | j                   j                         D ]A  \  }}t        |      j                  dd      }|j                  dj                  ||             C |j                  d       | j                  D ]  }|j                  dj                  |             | j                  |   j                         D ]v  \  }}|dk(  r|| j                  | j                  k(  r0t        |      }|j                  dd      }dj                  ||f      }|j                  dj                  |             x |j                  d        y)	zu
        Write method for Python 2.

        The one from configparser fails for non-ascii Windows accounts.
        z[{}]

z
	z{} = {}
r
   Nz = z{}
)	_defaultswriteformatcpDEFAULTSECTitemsstrreplace	_sections_optcreOPTCREr   join)r   fpkeyvaluevalue_plus_end_of_linesections         r   _writezDefaultsConfig._write9   sB    >>HHX__R^^45 $ 4 4 6 Je),U););D&)I&++C1GHIJ HHTN~~ 	GHHX__W-. $w 7 = = ? 	-e*$%4<<4;;+F*51E-2]]4-H***c+A%BCCs+,	- HHTN	r   c                     | j                  |      s| j                  |       t        |      st        |      }|rdj	                  |||      }t        |       t        t        | #  |||       y)zSet method.z[{}][{}] = {}N)	has_sectionadd_sectionr   reprr%   printr   r   set)r   r3   optionr1   verbosetextr    s         r   _setzDefaultsConfig._setV   sa    (W%e$KE"))'65AD$Knd'?r   c                 J     j                         } fd}	  ||       y# t        $ rx 	 t        j                  |      rt	        j
                  |       t        j                  d        ||       Y y# t        $ r!}t        d       t        |       Y d}~Y yd}~ww xY ww xY w)z*Save config into the associated .ini file.c                     t        j                  | dd      5 }j                  |       d d d        y # 1 sw Y   y xY w)Nwutf-8encoding)ioopenr$   )fpath
configfiler   s     r   _write_filez)DefaultsConfig._save.<locals>._write_fileh   s6    g6 '*

:&' ' 's   5>g?zOFailed to write user configuration file to disk, with the exception shown belowN)
get_config_fpathEnvironmentErrorr   isfiler   removetimesleep	Exceptionr9   )r   rG   rI   es   `   r   _savezDefaultsConfig._saved   s    %%'	'	 	
::e$IIe$

4 E"  2 3a	s-   ! 	B"AA44	B=BB"BB"c                 |    | j                   }t        j                  |dj                  | j                              }|S )z7Return the ini file where this configuration is stored.z{}.ini)r   r   r.   r%   r   )r   r   config_files      r   rJ   zDefaultsConfig.get_config_fpath~   s.    zzhhtX__TZZ%@Ar   c                 Z    |D ]&  \  }}|D ]  }||   }| j                  |||d        ( y)z8Set default values and save to defaults folder location.F)r<   N)r>   )r   defaultsr3   optionsr;   	new_values         r   set_defaultszDefaultsConfig.set_defaults   sF     ( 	EGW! E#FO			'69e	DE	Er   )r
   r   r   __doc__r   r4   r>   rR   rJ   rY   __classcell__r    s   @r   r   r   (   s(    
1:@4Er   r   c                   "    e Zd ZdZdZ	 	 	 d  fd	Zed        Zed        Zed        Z	d Z
ed        Zd!d	Zd
 Zd Zd Zd"dZd Zd Zd#dZd!dZd#dZd#dZd$dZd%dZd&dZd Zd Zef fd	Zd Zd'dZ  fdZ! fdZ"d Z#d Z$ xZ%S )(
UserConfigaB  
    UserConfig class, based on ConfigParser.

    Parameters
    ----------
    name: str
        Name of the config
    path: str
        Configuration file will be saved in path/%name%.ini
    defaults: {} or [(str, {}),]
        Dictionary containing options *or* list of tuples (sec_name, options)
    load: bool
        If a previous configuration file is found, load will take the values
        from this existing file, instead of using default values.
    version: str
        version of the configuration file in 'major.minor.micro' format.
    backup: bool
        A backup will be created on version changes and on initial setup.
    raw_mode: bool
        If `True` do not apply any automatic conversion on values read from
        the configuration.
    remove_obsolete: bool
        If `True`, values that were removed from the configuration on version
        change, are removed from the saved configuration file.

    Notes
    -----
    The 'get' and 'set' arguments number and type differ from the overriden
    methods. 'defaults' is an attribute and not a method.
    mainc
                    t         t        |   ||       || _        | j	                  |      | _        || _        |rdnd| _        || _        |	| _	        t        d      | _        d| _        d| _        d| _        d| _        | j!                  |      | _        |r| j%                          |r| j'                         }
| j)                  |
       | j+                  |      }|| _        | j/                  | j"                         | j1                  |      | j1                  |      k7  rL|r| j%                  |       | j3                  |	       |r| j5                  |       | j7                  |d
       || j9                          yyy)z(UserConfig class, based on ConfigParser.r   r      r   spyderrV   backupsz.bakversion)old_versionFsaveN)r   r^   r   _load_check_version_version_backup_raw_remove_obsolete_external_pluginr   _module_source_path_defaults_folder_backup_folder_backup_suffix_defaults_name_prefix_check_defaultsrV   _make_backupget_previous_config_fpath_load_from_iniget_version_old_version_save_new_defaults_get_minor_versionapply_configuration_patches_remove_deprecated_optionsset_versionset_as_defaults)r   r   r   rV   loadrf   backupraw_moderemove_obsoleteexternal_pluginprevious_fpathrg   r    s               r   r   zUserConfig.__init__   s}    	j$(d(>
++G4!Aq	 / /#9(#C  *'$%/" ,,X6!;;=N/**73K +D ##DMM2 ''0..{;< %%k%:00[0I #33K@   u 5$$&  5 r   c                 *    | d| j                  d       S )z3Return the 'major.minor' components of the version.N.)rfindre   s    r   r}   zUserConfig._get_minor_version   s     *c*++r   c                 *    | d| j                  d       S )z,Return the 'major' component of the version.Nr   )findre   s    r   _get_major_versionzUserConfig._get_major_version   s     )S)**r   c                 n    t        j                  d|       }| |t        dj                  |             | S )z'Check version is compliant with format.z^(\d+).(\d+).(\d+)$zDVersion number {} is incorrect - must be in major.minor.micro format)rematch
ValueErrorr%   )rf   regex_checks     r   rk   zUserConfig._check_version   sD     hh5w?;#6 88>wI I r   c                 t   || j                   i fg}nt        |t              r| j                   |fg}njt        |t              rO|D ]I  \  }}t	        |      sJ t        |t              sJ |j                         D ]  \  }}t	        |      rJ  K nt        d      || _        || j                  d       |S )z7Check if defaults are valid and update defaults values.z.`defaults` must be a dict or a list of tuples!Frh   )	DEFAULT_SECTION_NAME
isinstancedictlistr   r(   r   rV   reset_to_defaults)r   rV   secrW   opt_s         r   rv   zUserConfig._check_defaults   s    22B78H$'22H=>H$' ( /W%c***!'4000%mmo /FC)#...// MNN !""".r   c                 |    || j                   }nt        |      st        d      t        |      st        d      |S )zCheck section and option types.z#Argument 'section' must be a stringz"Argument 'option' must be a string)r   r   RuntimeError)clsr3   r;   s      r   _check_section_optionz UserConfig._check_section_option  sA     ?..G(DEEf%CDDr   c                 (   | j                         }| j                  ||      }t        j                  j	                  |      }t        j                  |      st        j                  |       	 t        j                  ||       y# t        $ r Y yw xY w)a  
        Make a backup of the configuration file.

        If `old_version` is `None` a normal backup is made. If `old_version`
        is provided, then the backup was requested for minor version changes
        and appends the version number to the backup file.
        )rf   rg   N)rJ   get_backup_fpath_from_versionr   r   r   r   r   r   shutilcopyfileIOError)r   rf   rg   rG   fpath_backupr   s         r   rw   zUserConfig._make_backup"  sz     %%'99 : 6ww|,yyKK	OOE<0 		s   .B 	BBc                 x    	 | j                  |d       y# t        j                  $ r d}t        |       Y yw xY w)z;Load config from the associated .ini file found at `fpath`.rB   rC   z*Warning: File contains no section headers.N)readr&   MissingSectionHeaderErrorr9   )r   rG   
error_texts      r   ry   zUserConfig._load_from_ini7  s9    	IIegI.++ 	EJ*	s     99c                     t        j                         }| j                  |      \  }}|j                  t	        j
                  ||dz                |S )zRead old defaults.z.ini)r&   ConfigParser#get_defaults_path_name_from_versionr   r   r.   )r   rg   old_defaultsr   r   s        r   _load_old_defaultszUserConfig._load_old_defaults?  sE    (==kJ
d#((478r   c                     | j                         \  }}t        ||      }t        j                  |j	                               s"|j                  |       |j                          yy)zSave new defaults.ra   N)r   r   r   rL   rJ   rY   rR   )r   rV   r   r   new_defaultss        r   r|   zUserConfig._save_new_defaultsF  sT    ==?
d%4d;zz,779:%%h/  ;r   c                    | j                  |      }|D ]I  \  }}|D ]?  }||   }	 |j                  ||      }	|	t        |      |	k7  s,| j                  ||||       A K y# t        j                  t        j                  f$ r d}	Y Qw xY w)z*Update defaults after a change in version.N)r   getr&   NoSectionErrorNoOptionErrorr   r>   )
r   rV   rg   r<   r   r3   rW   r;   rX   old_vals
             r   _update_defaultszUserConfig._update_defaultsN  s    ..{; ( 		CGW! C#FO	#*..w?G ?nY&?7&JIIgvy'BC		C
 ))2+;+;< #"G#s   A!!%B	B	c                    | j                  |      }|j                         D ]  }|j                  || j                        D ]k  \  }}| j	                  ||      t
        u s	 | j                  ||       t        | j                  || j                              dk(  r| j                  |       m  y# t        j                  $ r | j                  |       Y w xY w)zX
        Remove options which are present in the .ini file but not in defaults.
        rawr   N)r   sectionsr(   rn   get_defaultr	   remove_optionlenremove_sectionr&   r   )r   rg   r   r3   r;   r   s         r   r   z%UserConfig._remove_deprecated_options\  s     ..{;#,,. 	5G)//TYY/G 5	##GV4	A5**7F;tzz'tyyzABaG //85	5 ,, 5++G45s   "AB33$CCc                 "    | j                         S )z1Return the last configuration file used if found.rJ   r   s    r   rx   z$UserConfig.get_previous_config_fpathm  s    $$&&r   c                 "    | j                         S )z
        Return the configuration path for given version.

        If no version is provided, it returns the current file path.
        r   r   rf   s     r   get_config_fpath_from_versionz(UserConfig.get_config_fpath_from_versionq  s     $$&&r   c                 X   | j                         }t        j                  t        j                  |      | j                        }t        j                  |t        j
                  |            }|dj                  || j                        }|S dj                  ||| j                        }|S )z
        Get backup location based on version.

        `old_version` can be used for checking compatibility whereas `version`
        relates to adding the version to the file name.

        To be overridden if versions changed backup location.
        {}{}{}-{}{})rJ   r   r.   r   rs   basenamer%   rt   )r   rf   rg   rG   r   	new_fpathbackup_fpaths          r   r   z(UserConfig.get_backup_fpath_from_versiony  s     %%'xxE*D,?,?@HHT3<<#67	?!==D4G4GHL  %++Iw,0,?,?ALr   c                 N   |r|n| j                   }t        j                  t        j                  | j	                               | j
                        }dj                  | j                  | j                  |      }t        j                  |      st        j                  |       ||fS )zz
        Get defaults location based on version.

        To be overridden if versions changed defaults location.
        z{}-{}-{})rl   r   r.   r   rJ   rr   r%   ru   r   r   r   r   )r   rg   rf   defaults_pathr   s        r   r   z.UserConfig.get_defaults_path_name_from_version  s     "-+$--T-B-B-D!E!%!6!68  &&JJ

 yy'KK&d""r   c                      y)z
        Apply any patch to configuration values on version changes.

        To be overridden if patches to configuration values are needed.
        Nr   )r   rg   s     r   r~   z&UserConfig.apply_configuration_patches  s     	r   c                 <    | j                  | j                  d|      S )z0Return configuration (not application!) version.rf   )r   r   r   s     r   rz   zUserConfig.get_version  s    xx119gFFr   c                 d    | j                  |      }| j                  | j                  d||       y)z-Set configuration (not application!) version.rf   rh   N)rk   r:   r   )r   rf   ri   s      r   r   zUserConfig.set_version  s,    %%g.**IwTJr   c                     | j                   D ]0  \  }}|dk(  s||k(  s|D ]  }||   }| j                  ||||        2 |r| j                          yy)zReset config to Default values.N)rV   r>   rR   )r   ri   r<   r3   r   rW   r;   r1   s           r   r   zUserConfig.reset_to_defaults  sc     MM 	;LC$'S.% ;F#FOEIIc65':;	;
 JJL r   c                 $   g | _         | j                         D ]a  }i }| j                  || j                        D ]   \  }}	 t	        j
                  |      }|||<   " | j                   j                  ||f       c y# t        t        f$ r Y 8w xY w)z%Set defaults from the current config.r   N)	rV   r   r(   rn   astliteral_evalSyntaxErrorr   append)r   r3   secdictr;   r1   s        r   r   zUserConfig.set_as_defaults  s    }} 	5GG!%G!C (,,U3E #(( MM  '7!34	5
 $Z0 s   A==BBc                     | j                  ||      }| j                  D ]  \  }}||k(  s||v s||   } |S  t        }|S )z
        Get default value for a given `section` and `option`.

        This is useful for type checking in `get` method.
        )r   rV   r	   )r   r3   r;   r   rW   r1   s         r   r   zUserConfig.get_default  s[     ,,Wf= MM 	LCg~W$#FOE 	 Er   c                    | j                  ||      }| j                  |      s.|t        u rt        j                  |      | j                  |       | j                  ||      s3|t        u rt        j                  ||      | j                  |||       |S t        t        | /  ||| j                        }| j                  ||      }t        |t              rt!        j"                  |      }|S t        |t$              rt%        |      }|S t        |t&              rt'        |      }|S t)        |      r	 |S 	 t!        j"                  |      }|S # t*        t,        f$ r Y |S w xY w)ad  
        Get an option.

        Parameters
        ----------
        section: str
            Section name. If `None` is provide use the default section name.
        option: str
            Option name for `section`.
        default:
            Default value (if not specified, an exception will be raised if
            option doesn't exist).
        r   )r   r6   r	   r&   r   r7   
has_optionr   r:   r   r^   r   rn   r   r   boolr   r   floatintr   r   r   )r   r3   r;   defaultr1   default_valuer    s         r   r   zUserConfig.get  s_    ,,Wf=()#''00  )w/)#&&vw77&'2j$+GV+K((&9mT*$$U+E  u-%LE  s+JE  M* ((/   , s   :E E$#E$c                 f    | j                  ||      }| j                  D ]  \  }}||k(  s|||<    y)z
        Set Default value for a given `section`, `option`.

        If no defaults exist, no default is created. To be able to set
        defaults, a call to set_as_defaults is needed to create defaults
        based on current values.
        N)r   rV   )r   r3   r;   r   r   rW   s         r   set_defaultzUserConfig.set_default  s=     ,,Wf= MM 	0LCg~"/	0r   c                    | j                  ||      }| j                  ||      }|t        u r|}| j                  |||       t	        |t
              rt        |      }nNt	        |t              rt        |      }n2t	        |t              rt        |      }nt        |      st        |      }| j                  ||||       |r| j                          yy)
        Set an `option` on a given `section`.

        If section is None, the `option` is added to the default section.
        N)r   r   r	   r   r   r   r   r   r   r8   r>   rR   )r   r3   r;   r1   r<   ri   r   s          r   r:   zUserConfig.set  s     ,,Wf=((&9I%!MWfm<mT*KEu-%LEs+JE.KE		'65'2JJL r   c                 L    t         t        |   |       | j                          yz+Remove `section` and all options within it.N)r   r^   r   rR   )r   r3   r    s     r   r   zUserConfig.remove_section2  s    j$.w7

r   c                 N    t         t        |   ||       | j                          yzRemove `option` from `section`.N)r   r^   r   rR   )r   r3   r;   r    s      r   r   zUserConfig.remove_option7  s    j$-gv>

r   c                 J    t        j                  | j                                y)z&Remove .ini file associated to config.N)r   rM   rJ   r   s    r   cleanupzUserConfig.cleanup<  s    
		$'')*r   c                     g }| j                  | j                                | j                  D ]E  }i }| j                  |      D ]  \  }}| j	                  ||      ||<    |j                  ||f       G |S )z
        Return in list format.

        The format is [('section1', {'opt-1': value, ...}),
                       ('section2', {'opt-2': othervalue, ...}), ...]
        )ry   rJ   r+   r(   r   r   )r   r   r3   sec_datar;   r   s         r   to_listzUserConfig.to_list@  s     D1134~~ 	5GH#zz'2 =#'88GV#< =( 34		5 r   NTNFFFFNN)FN)0.0.0)r   T)TFNFT)&r
   r   r   rZ   r   r   staticmethodr}   r   rk   rv   classmethodr   rw   ry   r   r|   r   r   rx   r   r   r   r~   rz   r   r   r   r   r	   r   r   r:   r   r   r   r   r[   r\   s   @r   r^   r^      s    < "EI?D!&5'r , , + +  0 
 
*!C5"''&#&GK
5" ,5 /b04

+r   r^   c                   B     e Zd Zd ZddZd fd	Zd fd	ZddZ xZS )SpyderUserConfigc                     | j                         }| j                  r|g}n*|t        j                  j	                  t               d      g}|D ]  }t        j                  |      s |S  |S )z]
        Override method.

        Return the last configuration file used if found.
        
spyder.ini)rJ   rp   r   r   r.   r   r   rL   )r   rG   previous_pathss      r   rx   z*SpyderUserConfig.get_previous_config_fpathT  sp     %%'   #WN ]_l;	N $ 	Ezz% 		 r   c                     || j                   r| j                         }|S t        |dd      r t        j                  t               d      }|S | j                         }|S )z
        Override method.

        Return the configuration path for given version.

        If no version is provided, it returns the current file path.
        51.0.0<r   )rp   rJ   r   r   r.   r   )r   rf   rG   s      r   r   z.SpyderUserConfig.get_config_fpath_from_versionp  sb     ?d33))+E  7Hc2HH]_l;E  ))+Er   c                 <   |rvt        |dd      rid}t        j                  j                  t	               |      }|dj                  || j                        }|S dj                  ||| j                        }|S t        t        |       }|j                  ||      }|S )zT
        Override method.

        Make a backup of the configuration file.
        r   r   r   r   r   )
r   r   r   r.   r   r%   rt   r   r   r   )r   rf   rg   r   rG   r   super_classr    s          r   r   z.SpyderUserConfig.get_backup_fpath_from_version  s     =hDDGGLL$7E%}}UD4G4GH   )//w040C0C E 	   0$7K&DD&L r   c                 <   |rst        |dd      r>dj                  | j                  |      }t        j                  t               d      }||fS t        t        |       }|j                  |      \  }}||fS t        t        |       }|j                         \  }}||fS )zS
        Override method.

        Get defaults location based on version.
        r   r   z{}-{}rV   )	r   r%   ru   r   r.   r   r   r   r   )r   rg   r   r   r   r    s        r   r   z4SpyderUserConfig.get_defaults_path_name_from_version  s     [(C8~~d&@&@+Nxx< Tz $$4d;(LL!
d Tz   0$7K$HHJJD$Tzr   c                 
   | j                  | j                  |       | j                  ry|rXt        |dd      rJt	        | j                  dd            }|t        ur&|j                  dd      }| j                  dd|       yyyy)zg
        Override method.

        Apply any patch to configuration values on version changes.
        Nz44.1.0r   ipython_consolezstartup/run_lines,z; )	r   rV   rp   r   r   r   r	   r*   r:   )r   rg   	run_liness      r   r~   z,SpyderUserConfig.apply_configuration_patches  s     	dmm[9  =hD&txx0A0C(E FI	)%--c48	*,?K * E;r   r   r   )	r
   r   r   rx   r   r   r   r~   r[   r\   s   @r   r   r   R  s    8"*(Lr   r   c                       e Zd ZdZdZ	 	 	 ddZd Zd Zed        Z	ed        Z
ed	        Zed
        ZddZed        Zd Zd Zd Zd Zd ZefdZddZddZd Zd Zd Zy)MultiUserConfigaF  
    Multiuser config class which emulates the basic UserConfig interface.

    This class provides the same basic interface as UserConfig but allows
    splitting the configuration sections and options among several files.

    The `name` is now a `name_map` where the sections and options per file name
    are defined.
    rc   Nc
           	         | j                  |      | _        || _        || _        || _        || _        || _        |rdnd| _        || _        |	| _	        i | _
        | j                  ||      | _        ||||||d|	d| _        |D ]r  }
| j                  j                  |
      }|
|d}| j                  j                         }|j!                  |       | j#                         } |di || j                  |
<   t | j                  j                  | j$                        }|j'                  |      }|j'                  |j(                        }|s||k7  r>| j                  j+                         D ]   \  }}|j-                  |j(                         " yy)z2Multi user config class based on UserConfig class.rb   r   F)r   rV   r   rf   r   r   r   r   )r   rV   Nr   )_check_name_map	_name_mapr   r#   rj   rl   rm   	_raw_modero   rp   _configs_map_get_defaults_for_name_map_config_defaults_map_config_kwargsr   copyupdateget_config_classDEFAULT_FILE_NAMEr   r{   r(   r   )r   name_mapr   rV   r   rf   r   r   r   r   r   
mod_kwargs
new_kwargsconfig_classdefault_config	major_vermajor_old_verr   configs                      r   r   zMultiUserConfig.__init__  s    --h7
!
&A / /$($C$CHDL%N!   $.	
  		AD0044T:H$J ,,113Jj)002L&2&@Z&@Dd#		A **..t/E/EF"55g>	&99'') i=8!..446 G	611&2E2EFG 9r   c                     | j                  ||      }| j                  j                  |d      }|| j                  | j                     }|S )z:Get the correct configuration based on section and option.N)_get_name_from_mapr  r   r  )r   r3   r;   r   config_values        r   _get_configzMultiUserConfig._get_config  sP     &&w7((,,T48,,T-C-CDLr   c                     g }|j                         D ]L  \  }}|D ]B  \  }}|D ]8  }||f}||vr|j                  |       dj                  ||      }	t        |	       D N |S )z,Check `name_map` follows the correct format.z=Different files are holding the same section/option: "{}/{}"!)r(   r   r%   r   )
r   r  sections_optionsr   sec_optsr3   rW   r;   sec_opt	error_msgs
             r   r  zMultiUserConfig._check_name_map  s     #>>+ 	4KAx$, 
4 % 	4F&/G&66(//877=vgv7N " )33	4
4	4 r   c                 ^    | D ]  \  }}||k(  s|} |S  t        dj                  |            )z+Get the section contents from the defaults.zsection "{}" not found!)r   r%   )rV   r3   r   rW   r1   s        r   _get_section_from_defaultsz*MultiUserConfig._get_section_from_defaults  sH     % 	HLC#~ 	H
 6==gFGGr   c                 b    t         }| D ]#  \  }}||k(  s|j                  |t               } |S  |S )z/Get the section,option value from the defaults.)r	   r   )rV   r3   r;   r1   r   rW   s         r   _get_option_from_defaultsz)MultiUserConfig._get_option_from_defaults"  sB     $ 	LC#~FI6		 r   c                 n    d}t        |       D ]  \  }\  }}||k(  s|} n || j                         yy)zRemove section from defaults.N)	enumeratepop)rV   r3   
idx_removeidxr   r   s         r   _remove_section_from_defaultsz-MultiUserConfig._remove_section_from_defaults,  sM     
&x0 	MC#q#~ 
	
 !LL "r   c                 R    | D ]"  \  }}||k(  s||v s|j                  |        y y)z$Remove section,option from defaults.N)r'  )rV   r3   r;   r   rW   s        r   _remove_option_from_defaultsz,MultiUserConfig._remove_option_from_defaults8  s5     % 	LC#~W$KK'		r   c                    | j                   j                         D ]h  \  }}| j                  j                  |      j                  }||k(  r1|D ]3  \  }}||k(  st        |      dk(  r|c c S |D ]  }||k(  s	|c c c S  5 j y)zT
        Search for section and option on the name_map and return the name.
        r   N)r  r(   r  r   r   r   )	r   r3   r;   r   r  default_sec_namer   rW   r   s	            r   r  z"MultiUserConfig._get_name_from_mapA  s     #nn224 	,ND(#0044T:OO'' ( ,W'>7|q(##* ,C"f}'+,,	,r   c                    i }t        j                  |      }|j                         D ]  \  }}g }t        |      dk(  r|||<   |D ]  \  }}	t        |	      dk(  r%| j	                  ||      }
| j                  ||       n<i }
|	D ]5  }| j                  |||      }|t        ur||
|<   | j                  |||       7 |j                  ||
f        |||<    |S )z-Split the global defaults using the name_map.r   )
r  deepcopyr(   r   r"  r*  r$  r	   r,  r   )r   rV   r  name_map_configdefaults_copyr   r  default_map_for_namer3   rW   r   r   vals                r   r	  z*MultiUserConfig._get_defaults_for_name_mapS  s    h/&nn. 	=ND(#% 8}!(5%(0 @$GW7|q(!<<]=DF 99-:AC
 !#* KC"%"?"?@G#NC")3+.C  <<]=DcKK )//#?1@4 )=%?	=B r   c                     t         S )z#Return the UserConfig class to use.)r   r   s    r   r  z MultiUserConfig.get_config_class|  s    r   c                     t               }| j                  j                         D ]+  \  }}|j                         D ]  }|j	                  |        - t        t        |            S )z.Return all sections of the configuration file.)r:   r  r(   r   addr   sorted)r   r   r   r  r3   s        r   r   zMultiUserConfig.sections  s_    5**002 	&IAv!??, &W%&	& F8$%%r   c                     | j                  |d      }|| j                  | j                     }|j                  |      r|j	                  |      S y)z9Return all the items option/values for the given section.Nr3   )r  r  r  r6   r(   r   r3   r  s      r   r(   zMultiUserConfig.items  sQ    !!'40>&&t'='=>Fg&<<<00r   c                 J    | j                  |d      }|j                  |      S )z-Return all the options for the given section.Nr:  )r  rW   r;  s      r   rW   zMultiUserConfig.options  s%    !!'40~~g~..r   c                     | j                  ||      }|| j                  | j                     }|j                  ||      S )z
        Get Default value for a given `section` and `option`.

        This is useful for type checking in `get` method.
        )r  r  r  r   r   r3   r;   r  s       r   r   zMultiUserConfig.get_default  sD     !!'62>&&t'='=>F!!'622r   c                     | j                  ||      }|| j                  | j                     }|j                  |||      S )z
        Get an `option` on a given `section`.

        If section is None, the `option` is requested from default section.
        )r3   r;   r   )r  r  r  r   )r   r3   r;   r   r  s        r   r   zMultiUserConfig.get  sF     !!'62>&&t'='=>Fzz'&'zJJr   c                 T    | j                  ||      }|j                  |||||       y)r   )r3   r;   r1   r<   ri   N)r  r:   )r   r3   r;   r1   r<   ri   r  s          r   r:   zMultiUserConfig.set  s2     !!'62

76" 	 	/r   c                 l    | j                   j                         D ]  \  }}|j                  |        y)z&Reset configuration to Default values.r:  N)r  r(   r   )r   r3   r   r  s       r   r   z!MultiUserConfig.reset_to_defaults  s5    **002 	6IAv$$W$5	6r   c                 J    | j                  |d      }|j                  |       yr   )r  r   r;  s      r   r   zMultiUserConfig.remove_section  s"    !!'40g&r   c                 L    | j                  ||      }|j                  ||       yr   )r  r   r>  s       r   r   zMultiUserConfig.remove_option  s$    !!'62Wf-r   c                     | j                   j                         D ](  \  }}t        j                  |j	                                * y)z/Remove .ini files associated to configurations.N)r  r(   r   rM   rJ   )r   r   r  s      r   r   zMultiUserConfig.cleanup  s9    **002 	1IAvIIf--/0	1r   r   r   r   r   )r
   r   r   rZ   r  r   r  r  r   r"  r$  r*  r,  r  r   r	  r  r   r(   rW   r   r	   r   r:   r   r   r   r   r   r   r   r  r    s     !IM?D!&0Gd$ 	 	   	 	  ,$ & &P &	/
	3 ,5 K/6
'
.
1r   r  c                       e Zd ZdZy)PluginConfigzPlugin configuration handler.N)r
   r   r   rZ   r   r   r   rF  rF    s    'r   rF  c                       e Zd ZdZd Zy)PluginMultiConfigz4Plugin configuration handler with multifile support.c                     t         S r   )rF  r   s    r   r  z"PluginMultiConfig.get_config_class  s    r   N)r
   r   r   rZ   r  r   r   r   rH  rH    s
    >r   rH  )rZ   r   configparserr&   r  rE   r   os.pathr   r   r   r   rN   spyder.config.baser   r   spyder.py3compatr   r   spyder.utils.programsr   r	   r   objectr   r^   r   r  rF  rH  r   r   r   <module>rP     s       	 	  	   E ; /	 	aER__f aEN@ @FgLz gLTQ1f Q1h(: ( r   