frc@s@dZddlZddlZddlmZddlmZmZmZGddde Z Gddde Z Gd d d e Z Gd d d e Z Gd ddeZGdddeZGdddZeZedkr<ddZeejeejeejdjddndS(uProvides access to stored IDLE configuration information. Refer to the comments at the beginning of config-main.def for a description of the available 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 file becomes empty, it will be deleted. The contents of the user files may be altered using the Options/Configure IDLE menu to access the configuration GUI (configDialog.py), or manually. 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. iN(u macosxSupport(u ConfigParseru NoOptionErroruNoSectionErrorcBs|EeZdZdS(uInvalidConfigTypeN(u__name__u __module__u __qualname__(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuInvalidConfigTypesuInvalidConfigTypecBs|EeZdZdS(uInvalidConfigSetN(u__name__u __module__u __qualname__(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuInvalidConfigSetsuInvalidConfigSetcBs|EeZdZdS(u InvalidFgBgN(u__name__u __module__u __qualname__(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu InvalidFgBgsu InvalidFgBgcBs|EeZdZdS(u InvalidThemeN(u__name__u __module__u __qualname__(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu InvalidThemesu InvalidThemecBsV|EeZdZdZd ddZd d d ddZddZdd Z d S( uIdleConfParseruI A ConfigParser specialised for idle configuration file handling cCs&||_tj|d|dddS(uK cfgFile - string, fully specified configuration file name udefaultsustrictNF(ufileu ConfigParseru__init__uFalse(uselfucfgFileu cfgDefaults((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu__init__#s uIdleConfParser.__init__cCsh|j||s|S|dkr2|j||S|dkrN|j||S|j||d|SdS(u Get an option value for given section/option or return default. If type is specified, return as type. ubooluinturawN(u has_optionu getbooleanugetintuget(uselfusectionuoptionutypeudefaulturaw((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGet*s  uIdleConfParser.GetcCs$|j|r|j|SgSdS(u6 Get an option list for given section N(u has_sectionuoptions(uselfusection((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu GetOptionList8s uIdleConfParser.GetOptionListcCs|j|jdS(u7 Load the configuration file from disk N(ureadufile(uself((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuLoadAsuIdleConfParser.LoadNF( u__name__u __module__u __qualname__u__doc__uNoneu__init__uFalseuGetu GetOptionListuLoad(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuIdleConfParsers  uIdleConfParsercBsn|EeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS(uIdleUserConfParseruG IdleConfigParser specialised for user configuration handling. cCs#|j|s|j|ndS(u2 if section doesn't exist, add it N(u has_sectionu add_section(uselfusection((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu AddSectionLsuIdleUserConfParser.AddSectioncCs:x3|jD]%}|j|s |j|q q WdS(u: remove any sections that have no options N(usectionsu GetOptionListuremove_section(uselfusection((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuRemoveEmptySectionsSsu&IdleUserConfParser.RemoveEmptySectionscCs"|j|jrdSdSdS(up Remove empty sections and then return 1 if parser has no sections left, else return 0. iiN(uRemoveEmptySectionsusections(uself((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuIsEmpty[s  uIdleUserConfParser.IsEmptycCs#|j|r|j||SdS(ul If section/option exists, remove it. Returns 1 if option was removed, 0 otherwise. N(u has_sectionu remove_option(uselfusectionuoption((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu RemoveOptionfsuIdleUserConfParser.RemoveOptioncCs|j||rH|j|||kr.dS|j|||dSn6|j|sg|j|n|j|||dSdS(u Sets option to value, adding section if required. Returns 1 if option was added or changed, otherwise 0. iiN(u has_optionugetusetu has_sectionu add_section(uselfusectionuoptionuvalue((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu SetOptionnsuIdleUserConfParser.SetOptioncCs,tjj|jr(tj|jndS(uF Removes the user config file from disk if it exists. N(uosupathuexistsufileuremove(uself((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu RemoveFilesuIdleUserConfParser.RemoveFilecCs|jsv|j}yt|d}Wn.tk rXtj|t|d}YnX||j|WdQXn |jdS(uUpdate user configuration file. Remove empty sections. If resulting config isn't empty, write the file to disk. If config is empty, remove the file from disk if it exists. uwN(uIsEmptyufileuopenuOSErroruosuunlinkuwriteu RemoveFile(uselfufnameucfgFile((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuSaves    uIdleUserConfParser.SaveN( u__name__u __module__u __qualname__u__doc__u AddSectionuRemoveEmptySectionsuIsEmptyu RemoveOptionu SetOptionu RemoveFileuSave(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuIdleUserConfParserGs     uIdleUserConfParsercBsa|EeZdZdZddZddZddZd4d4d5d6dd Z d d Z d d Z d4ddZ ddZddZddZd5d6d6ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd4d*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4S(7uIdleConfu holds config parsers for all idle config files: default config files (idle install dir)/config-main.def (idle install dir)/config-extensions.def (idle install dir)/config-highlight.def (idle install dir)/config-keys.def user config files (user home dir)/.idlerc/config-main.cfg (user home dir)/.idlerc/config-extensions.cfg (user home dir)/.idlerc/config-highlight.cfg (user home dir)/.idlerc/config-keys.cfg cCs3i|_i|_i|_|j|jdS(N(u defaultCfguuserCfgucfguCreateConfigHandlersu LoadCfgFiles(uself((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu__init__s     uIdleConf.__init__cCstdkr!tjjt}ntjjtjd}|j}d }i}i}xP|D]H}tjj|d|d||In user's config file, set section's option to value. N(uuserCfgu SetOption(uselfu configTypeusectionuoptionuvalue((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu SetOptionsuIdleConf.SetOptioncCsi|d krtdn|dkr7|j|}n(|dkrS|j|}n td|jS( u Get a list of sections from either the user or default config for the given config type. configSet must be either 'user' or 'default' configType must be one of ('main','extensions','highlight','keys') umainu extensionsu highlightukeysuInvalid configType specifieduuserudefaultuInvalid configSet specified(umainu extensionsu highlightukeys(uInvalidConfigTypeuuserCfgu defaultCfguInvalidConfigSetusections(uselfu configSetu configTypeu cfgParser((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetSectionLists    uIdleConf.GetSectionListcCs|jdj|r+|jd|}n|jd|}||d}|dkrd|d}n||d}i|d6|d 6}|s|S|d kr|dS|d kr|d Std d S(u$ return individual highlighting theme elements. fgBg - string ('fg'or'bg') or None, if None return a dictionary containing fg and bg colours (appropriate for passing to Tkinter in, e.g., a tag_config call), otherwise fg or bg colour only as specified. u highlightudefaultuuseru -foregrounducursorunormal-backgroundu -backgroundu foregroundu backgroundufgubguInvalid fgBg specifiedN(u defaultCfgu has_sectionu GetThemeDictu InvalidFgBg(uselfuthemeuelementufgBgu themeDictuforeubacku highlight((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu GetHighlight(s    uIdleConf.GetHighlightcCs|dkr|jd}n(|dkr8|jd}n tdidd6dd6dd 6dd 6dd 6dd 6dd 6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6dd!6dd"6}x|D]}|j||sid#||||f}ytjj|Wqitk reYqiXn|j||d||}|||>' u<>u active_onlyiN(uNoneu GetExtensionsuGetExtensionKeys(uselfu virtualEventuextNameuvEventuextnuevent((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetExtnNameForEvents uIdleConf.GetExtnNameForEventc Cs|d}|j}i}|jdj|r~|jdj|}x3|D](}d|d}||}|||>(uGetCurrentKeySetu defaultCfgu has_sectionu GetOptionList( uselfu extensionNameukeysNameu activeKeysuextKeysu eventNamesu eventNameueventubinding((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetExtensionKeyss    uIdleConf.GetExtensionKeyscCs|d}i}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||>(u defaultCfgu has_sectionu GetOptionListu GetOptionusplit(uselfu extensionNameukeysNameuextKeysu eventNamesu eventNameubindinguevent((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu__GetRawExtensionKeyss   uIdleConf.__GetRawExtensionKeyscCs|d}|j|}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||>(uGetExtensionKeysu defaultCfgu has_sectionu GetOptionListu GetOptionusplit(uselfu extensionNameu bindsNameuextBindsu eventNamesu eventNameubindinguevent((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetExtensionBindingss   uIdleConf.GetExtensionBindingscCs5|dd}|jd||ddj}|S(u returns the keybinding for a specific event. keySetName - string, name of key binding set eventStr - string, the virtual event we want the binding for, represented as a string, eg. '<>' iukeysudefaultui(u GetOptionusplit(uselfu keySetNameueventStru eventNameubinding((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu GetKeyBindings!uIdleConf.GetKeyBindingcCsq|j|j}tjrmxI|jD]8\}}dd|D}||kr.|||s u-IdleConf.GetCurrentKeySet..(u GetKeySetu CurrentKeysu macosxSupporturunningAsOSXAppuitems(uselfuresultukuvuv2((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetCurrentKeySet s  uIdleConf.GetCurrentKeySetcCs|j|}|jdd}xh|D]`}|j|}|r(xB|D]7}|||jkrsd||>' u<>(u GetCoreKeys(uselfu virtualEvent((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu IsCoreBinding-suIdleConf.IsCoreBindingc Csi1ddgd6ddgd6ddgd 6d d gd 6d gd6dgd6dgd6dgd6dgd6dgd6dgd6dgd6dgd6dgd6dgd 6d!gd"6d#gd$6d%gd&6d'gd(6d)gd*6d+gd,6d-gd.6d/gd06d1gd26d3gd46d5gd66d7gd86d9gd:6d;gd<6d=gd>6d?d@gdA6dBgdC6dDgdE6dFgdG6dHgdI6dJgdK6dLgdM6dNdOgdP6dQgdR6dSgdT6dUgdV6dWgdX6dYgdZ6d[gd\6d]gd^6d_gd`6dagdb6dcgdd6degdf6}|rxv|D]k}|j||}|r:|||u u<>u u u<>u u u <>u uu<>u u<>u u<>uu<>u<>u u<>uu<>u u<>uu<>uu<>u<>uu<>u u<>uu<>uu<>u u<>u u<>u u<>u u<>u u<>uu<>u u<>uu<>u u<>uu<>uu<>u u<>u uu<>uu<>u u<>u u<>u u <>uu <>uu<>u uu<>u u<>uu<>uu<>u u<>u u<>u u<>u u<>u u<>u u<>uu<>uu<>u Warning: configHandler.py - IdleConf.GetCoreKeys - problem retrieving key binding for event %r from key set %r. returning default value: %r (u GetKeyBindingusysustderruwriteuOSError(uselfu keySetNameu keyBindingsueventubindinguwarning((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu GetCoreKeys5s|                                                      uIdleConf.GetCoreKeysc Csg}|dkr"|jd}n(|dkr>|jd}n td|jd}x|D]}|jd|dd}|jdd krd}d}n/|jd}|d j}|dj}|r`|r`|j|||fq`q`W|j d d d |S(uFetch list of extra help sources from a given configSet. Valid configSets are 'user' or 'default'. Return a list of tuples of the form (menu_item , path_to_help_file , option), or return the empty list. 'option' is the sequence number of the help resource. 'option' values determine the position of the menu items on the Help menu, therefore the returned list must be sorted by 'option'. uuserumainudefaultuInvalid configSet specifiedu HelpFilesu;iuiukeycSs|dS(Ni((ux((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyusu1IdleConf.GetExtraHelpSourceList..i( uuserCfgu defaultCfguInvalidConfigSetu GetOptionListuGetufindusplitustripuappendusort( uselfu configSetu helpSourcesu cfgParseruoptionsuoptionuvalueumenuItemuhelpPath((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetExtraHelpSourceLists&       uIdleConf.GetExtraHelpSourceListcCs |jd|jd}|S(u Returns a list of tuples containing the details of all additional help sources configured, or an empty list if there are none. Tuples are of the format returned by GetExtraHelpSourceList. udefaultuuser(uGetExtraHelpSourceList(uselfuallHelpSources((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuGetAllExtraHelpSourcesLists u#IdleConf.GetAllExtraHelpSourcesListcCs:x3|jD](}|j|j|j|jq WdS(u/ load all configuration files. N(u defaultCfguLoaduuserCfg(uselfukey((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyu LoadCfgFilessuIdleConf.LoadCfgFilescCs)x"|jD]}|j|jq WdS(uH write all loaded user configuration files back to disk N(uuserCfguSave(uselfukey((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuSaveUserCfgFilessuIdleConf.SaveUserCfgFilesNTF( u__name__u __module__u __qualname__u__doc__u__init__uCreateConfigHandlersu GetUserCfgDiruNoneuTrueuFalseu GetOptionu SetOptionuGetSectionListu GetHighlightu GetThemeDictu CurrentThemeu CurrentKeysu GetExtensionsuRemoveKeyBindNamesuGetExtnNameForEventuGetExtensionKeysu_IdleConf__GetRawExtensionKeysuGetExtensionBindingsu GetKeyBindinguGetCurrentKeySetu GetKeySetu IsCoreBindingu GetCoreKeysuGetExtraHelpSourceListuGetAllExtraHelpSourcesListu LoadCfgFilesuSaveUserCfgFiles(u __locals__((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyuIdleConfs6    .   @  !       L  uIdleConfu__main__c Cstd|dx|D]}||j}t|t|xf|D]^}||j|}t|t|x.|D]&}t|d||j||q|WqHWqWdS(Nu u=(uprintusectionsuoptionsuGet(ucfgukeyusectionsusectionuoptionsuoption((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyudumpCfgs       udumpCfgumainuThemeuname(u__doc__uosusysuidlelibu macosxSupportu configparseru ConfigParseru NoOptionErroruNoSectionErroru ExceptionuInvalidConfigTypeuInvalidConfigSetu InvalidFgBgu InvalidThemeuIdleConfParseruIdleUserConfParseruIdleConfuidleConfu__name__udumpCfgu defaultCfguuserCfguprintuGet(((u:/opt/alt/python33/lib64/python3.3/idlelib/configHandler.pyus&  (R"