B 억ˣ! @ s d Z ddlmZ ddlZddlZddlmZ ddlZG dd deZ G dd deZ G d d d eZG dd deZG d d deZ G dd dZe Ze Zdd ZG dd deZdd ZedkrddlmZ edddd dS )aE idlelib.config -- Manage IDLE configuration information. The comments at the beginning of config-main.def describe the configuration files and the design implemented to update user configuration information. In particular, user configuration choices which duplicate the defaults will be removed from the user's configuration files, and if a user file becomes empty, it will be deleted. The configuration database maps options to values. Conceptually, the database keys are tuples (config-type, section, item). As implemented, there are separate dicts for default and user values. Each has config-type keys 'main', 'extensions', 'highlight', and 'keys'. The value for each key is a ConfigParser instance that maps section and item to values. For 'main' and 'extensions', user values override default values. For 'highlight' and 'keys', user sections augment the default sections (and must, therefore, have distinct names). Throughout this module there is an emphasis on returning useable defaults when a problem occurs in returning a requested configuration value back to idle. This is to allow IDLE to continue to function in spite of errors in the retrieval of config information. When a default is returned instead of a requested config value, a message is printed to stderr to aid in configuration problem notification and resolution. )ConfigParserN)Fontc @ s e Zd ZdS )InvalidConfigTypeN)__name__ __module____qualname__ r r 3/opt/alt/python37/lib64/python3.7/idlelib/config.pyr # s r c @ s e Zd ZdS )InvalidConfigSetN)r r r r r r r r $ s r c @ s e Zd ZdS )InvalidThemeN)r r r r r r r r % s r c @ s4 e Zd ZdZdddZd ddZdd Zd d ZdS )IdleConfParserzI A ConfigParser specialised for idle configuration file handling Nc C s || _ tj| |dd dS )zK cfgFile - string, fully specified configuration file name F)defaultsstrictN)filer __init__)selfcfgFileZcfgDefaultsr r r r + s zIdleConfParser.__init__Fc C sL | ||s|S |dkr$| ||S |dkr8| ||S | j|||dS dS )z Get an option value for given section/option or return default. If type is specified, return as type. boolint)rawN) has_optionZ getbooleanZgetintget)r sectionoptiontypedefaultr r r r Get2 s zIdleConfParser.Getc C s | |r| |S g S dS )z4Return a list of options for given section, else [].N)has_sectionoptions)r r r r r GetOptionListC s zIdleConfParser.GetOptionListc C s | j r| | j dS )z&Load the configuration file from disk.N)r read)r r r r LoadJ s zIdleConfParser.Load)N)NNF)r r r __doc__r r r r! r r r r r ' s r c @ s@ e Zd ZdZdd Zdd Zdd Zdd Zd d Zdd Z dS )IdleUserConfParserzG IdleConfigParser specialised for user configuration handling. c C s^ | ||r4| |||kr dS | ||| dS n&| |sH| | | ||| dS dS )zReturn True if option is added or changed to value, else False. Add section if required. False means option already had value. FTN)r r setr add_section)r r r valuer r r SetOptionT s zIdleUserConfParser.SetOptionc C s | |r| ||S dS )zReturn True if option is removed from section, else False. False if either section does not exist or did not have option. F)r Z remove_option)r r r r r r RemoveOptione s zIdleUserConfParser.RemoveOptionc C s | |s| | dS )z!If section doesn't exist, add it.N)r r% )r r r r r AddSectionn s zIdleUserConfParser.AddSectionc C s* x$| D ]}| |s | | q W dS )z)Remove any sections that have no options.N)sectionsr remove_section)r r r r r RemoveEmptySectionss s z&IdleUserConfParser.RemoveEmptySectionsc C s | | S )z9Return True if no sections after removing empty sections.)r, r* )r r r r IsEmptyy s zIdleUserConfParser.IsEmptyc C s | j }|r|d dkr| sryt|d}W n( tk rT t| t|d}Y nX | | | W dQ R X ntj| j rt | j dS )zUpdate user configuration file. If self not empty after removing empty sections, write the file to disk. Otherwise, remove the file from disk if it exists. r #wN) r r- openOSErrorosunlinkwritepathexistsremove)r Zfnamer r r r Save~ s zIdleUserConfParser.SaveN) r r r r" r' r( r) r, r- r8 r r r r r# O s r# c @ s e Zd ZdZdFddZdd Zdd ZdGddZd d Zdd Z dd Z dd Zdd Zdd Z dd Zedd ZdHddZdd Zd!d" Zd#d$ Zd%d&