{fc@s~dZddlmZddlZddlZddlmZddlmZddlm Z m Z de fdYZ d e fd YZ d e fd YZd e fdYZdefdYZdefdYZdfdYZeZedkrzddlmZddf\aadZdZeejeejedtdtddndS(sProvides 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. i(tprint_functionN(t ConfigParser(t TkVersion(tFontt nametofonttInvalidConfigTypecBseZRS((t__name__t __module__(((s-/usr/lib64/python2.7/idlelib/configHandler.pyRstInvalidConfigSetcBseZRS((RR(((s-/usr/lib64/python2.7/idlelib/configHandler.pyRst InvalidFgBgcBseZRS((RR(((s-/usr/lib64/python2.7/idlelib/configHandler.pyR st InvalidThemecBseZRS((RR(((s-/usr/lib64/python2.7/idlelib/configHandler.pyR stIdleConfParsercBs>eZdZddZddedZdZdZRS(sI A ConfigParser specialised for idle configuration file handling cCs ||_tj|d|dS(sK cfgFile - string, fully specified configuration file name tdefaultsN(tfileRt__init__(tselftcfgFilet cfgDefaults((s-/usr/lib64/python2.7/idlelib/configHandler.pyR&s cCsh|j||s|S|dkr2|j||S|dkrN|j||S|j||d|SdS(s Get an option value for given section/option or return default. If type is specified, return as type. tbooltinttrawN(t has_optiont getbooleantgetinttget(RtsectiontoptionttypetdefaultR((s-/usr/lib64/python2.7/idlelib/configHandler.pytGet-s  cCs$|j|r|j|SgSdS(s4Return a list of options for given section, else [].N(t has_sectiontoptions(RR((s-/usr/lib64/python2.7/idlelib/configHandler.pyt GetOptionList>s cCs|j|jdS(s&Load the configuration file from disk.N(treadR (R((s-/usr/lib64/python2.7/idlelib/configHandler.pytLoadEsN( RRt__doc__tNoneRtFalseRR R"(((s-/usr/lib64/python2.7/idlelib/configHandler.pyR "s   tIdleUserConfParsercBsMeZdZdZdZdZdZdZdZdZ RS(sG IdleConfigParser specialised for user configuration handling. cCs#|j|s|j|ndS(s!If section doesn't exist, add it.N(Rt add_section(RR((s-/usr/lib64/python2.7/idlelib/configHandler.pyt AddSectionNscCs:x3|jD]%}|j|s |j|q q WdS(s)Remove any sections that have no options.N(tsectionsR tremove_section(RR((s-/usr/lib64/python2.7/idlelib/configHandler.pytRemoveEmptySectionsSscCs|j|j S(s9Return True if no sections after removing empty sections.(R+R)(R((s-/usr/lib64/python2.7/idlelib/configHandler.pytIsEmptyYs cCs#|j|r|j||StS(sReturn True if option is removed from section, else False. False if either section does not exist or did not have option. (Rt remove_optionR%(RRR((s-/usr/lib64/python2.7/idlelib/configHandler.pyt RemoveOption^scCs|j||rH|j|||kr.tS|j|||tSn6|j|sg|j|n|j|||tSdS(sReturn True if option is added or changed to value, else False. Add section if required. False means option already had value. N(RRR%tsettTrueRR'(RRRtvalue((s-/usr/lib64/python2.7/idlelib/configHandler.pyt SetOptiongscCs,tjj|jr(tj|jndS(s9Remove user config file self.file from disk if it exists.N(tostpathtexistsR tremove(R((s-/usr/lib64/python2.7/idlelib/configHandler.pyt RemoveFilexscCs|jsu|j}yt|d}Wn-tk rWtj|t|d}nX||j|WdQXn |jdS(sUpdate 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. twN(R,R topentIOErrorR3tunlinktwriteR7(RtfnameR((s-/usr/lib64/python2.7/idlelib/configHandler.pytSave}s    ( RRR#R(R+R,R.R2R7R>(((s-/usr/lib64/python2.7/idlelib/configHandler.pyR&Is     tIdleConfcBseZdZdZdZdZddeedZ dZ dZ ddZ dZ d Zd Zeeed Zd Zd ZdZdZdZdZdZdZdZddZdZdZdZdZdZRS(slHold config parsers for all idle config files in singleton instance. Default config files, self.defaultCfg -- for config_type in self.config_types: (idle install dir)/config-{config-type}.def User config files, self.userCfg -- for config_type in self.config_types: (user home dir)/.idlerc/config-{config-type}.cfg cCs<d|_i|_i|_i|_|j|jdS(Ntmaint extensionst highlighttkeys(R@RARBRC(t config_typest defaultCfgtuserCfgtcfgtCreateConfigHandlerst LoadCfgFiles(R((s-/usr/lib64/python2.7/idlelib/configHandler.pyRs      cCstdkr!tjjt}ntjjtjd}|j}i}i}xS|jD]H}tjj |d|d||>' s<>RiN(R$RtGetExtensionKeys(Rt virtualEventtextNametvEventRtevent((s-/usr/lib64/python2.7/idlelib/configHandler.pytGetExtnNameForEvents c Cs|d}|j}i}|jdj|r~|jdj|}x3|D](}d|d}||}|||>(tGetCurrentKeySetRERR ( Rt extensionNametkeysNamet activeKeystextKeyst eventNamest eventNameRtbinding((s-/usr/lib64/python2.7/idlelib/configHandler.pyRs    cCs|d}i}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||>(RERR Rdtsplit(RRRRRRRR((s-/usr/lib64/python2.7/idlelib/configHandler.pyt__GetRawExtensionKeyss  cCs|d}|j|}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||>(RRERR RdR(RRt bindsNametextBindsRRRR((s-/usr/lib64/python2.7/idlelib/configHandler.pytGetExtensionBindingss  cCs2|dd!}|jd||ddj}|S(sReturn the keybinding list for keySetName eventStr. keySetName - name of key binding set (config-keys section). eventStr - virtual event, including brackets, as in '<>'. iiRCRRz(RdR(Rt keySetNameteventStrRR((s-/usr/lib64/python2.7/idlelib/configHandler.pyt GetKeyBinding s !cCs|j|j}tjdkrx[|jD]J\}}g|D]}|jdd^qD}||kr1|||>' s<>(R(RR((s-/usr/lib64/python2.7/idlelib/configHandler.pyt IsCoreBinding;scCsi1ddgd6ddgd6ddgd 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}|rxx|D]m}|j||}|r:|||s s<>s s s<>s s s <>s ss<>s s<>s s<>ss<>s<>s s<>ss<>s s<>ss<>ss<>s<>ss<>s s<>ss<>ss<>s s<>s s<>s s<>s s<>s s<>ss<>s s<>ss<>s s<>ss<>ss<>s s<>s ss<>ss<>s s<>s s<>s s <>ss <>ss<>s ss<>s s<>ss<>ss<>s s<>s s<>s s<>s s<>s s<>s s<>ss<>ss<>s Warning: configHandler.py - IdleConf.GetCoreKeys - problem retrieving key binding for event %r from key set %r. returning default value: %rR (RRXRNRYR:(RRt keyBindingsRRRc((s-/usr/lib64/python2.7/idlelib/configHandler.pyRFs|                                                      c Csg}|dkr"|jd}n(|dkr>|jd}n td|jd}x|D]}|jd|dd}|jddkrd}d}n/|jd}|d j}|d j}|r`|r`|j|||fq`q`W|j d d |S( sReturn 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'. ReR@RsInvalid configSet specifiedt HelpFilest;iRziitkeycSst|dS(Ni(R(R((s-/usr/lib64/python2.7/idlelib/configHandler.pytRz( RFRERR RtfindRtstripRR( RRft helpSourcesRgRRR1tmenuItemthelpPath((s-/usr/lib64/python2.7/idlelib/configHandler.pytGetExtraHelpSourceLists&       cCs |jd|jd}|S(sReturn a list of the details of all additional help sources. Tuples in the list are those of GetExtraHelpSourceList. RRe(R(RtallHelpSources((s-/usr/lib64/python2.7/idlelib/configHandler.pytGetAllExtraHelpSourcesLists c Cs|j||ddd}|j||ddddd}|j||ddd dd }|d krtd kr~d }qtdd dtd|}tj|}|d}|d}|d krd}n|ddk}n|||rdndfS(sRetrieve a font from configuration (font, font-size, font-bold) Intercept the special value 'TkFixedFont' and substitute the actual font, factoring in some tweaks if needed for appearance sakes. The 'root' parameter can normally be any valid Tkinter widget. Return a tuple (family, size, weight) suitable for passing to tkinter.Font tfontRtcouriers font-sizeRRt10s font-boldiRt TkFixedFontg!@tCourierR{R5troottfamilytsizei tweighttboldtnormal(RdRRR0tactual( RRRaRRRRtft actualFont((s-/usr/lib64/python2.7/idlelib/configHandler.pytGetFonts          cCs:x3|jD](}|j|j|j|jq WdS(sLoad all configuration files.N(RER"RF(RR((s-/usr/lib64/python2.7/idlelib/configHandler.pyRIscCs)x"|jD]}|j|jq WdS(s2Write all loaded user configuration files to disk.N(RFR>(RR((s-/usr/lib64/python2.7/idlelib/configHandler.pytSaveUserCfgFilessN( RRR#RRHROR$R0R%RdR2RhRuRnR}RRRRRRRRRRRRRRRRIR(((s-/usr/lib64/python2.7/idlelib/configHandler.pyR?s8   -    @  #       M  RJ(tcrc32icCs?t|}td7at|jddtat|dS(Nitencodingsutf-8(tstrtlineRtencodetcrcRX(tobjttxt((s-/usr/lib64/python2.7/idlelib/configHandler.pytsprints  cCstd|dxt|jD]}||j}t|t|xh|D]`}||j|}t|t|x0|D](}t|d||j||qWqTWq#WdS(Ns s = (RXtsortedRCR)RRR(RGRR)RRR((s-/usr/lib64/python2.7/idlelib/configHandler.pytdumpCfgs      s lines = s, crc = tsepRz(R#t __future__RR3RNRtTkinterRttkFontRRt ExceptionRRR R R R&R?tidleConfRtzlibRRRRRRERFRX(((s-/usr/lib64/python2.7/idlelib/configHandler.pyts0  'GW