B
„ f• ã @ sä d Z ddlmZ ddlZddlZddlmZ ddlZG dd„ deƒZ G dd„ deƒZ
G d d
„ d
eƒZG dd„ deƒZG d
d„ deƒZ
G dd„ dƒZeƒ Zeƒ Zdd„ ZG dd„ deƒZdd„ ZedkràddlmZ 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 ZdZddd„Zd
dd„Zdd „ 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)ÚdefaultsÚstrictN)Úfiler Ú__init__)ÚselfÚcfgFileZcfgDefaultsr 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.
ÚboolÚint)ÚrawN)Ú
has_optionZ
getbooleanZgetintÚget)r ÚsectionÚoptionÚtypeÚdefaultr 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_sectionÚoptions)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 )z‘Return 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 )z‹Return 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 ¡rŒt | j ¡ dS )zµUpdate 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- ÚopenÚOSErrorÚosÚunlinkÚwriteÚpathÚexistsÚremove)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 ZdZdFdd„Zdd„ Zdd„ ZdGdd„Zd
d„ Zdd„ Z dd„ Z
dd„ Zdd„ Zdd„ Z
dd„ Zedd„ ƒZdHdd„Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2d3d4d5d6d7d8d9h ZdId:d;„Zd