kWc@s1dZddlmZddlZddlZddlmZdefdYZdefdYZd efd YZ d efd YZ d efdYZ de fdYZ dfdYZ e Zedkr-dZeejeejeejdjddndS(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 ConfigParsertInvalidConfigTypecBseZRS((t__name__t __module__(((s+/usr/lib/python2.7/idlelib/configHandler.pyRstInvalidConfigSetcBseZRS((RR(((s+/usr/lib/python2.7/idlelib/configHandler.pyRst InvalidFgBgcBseZRS((RR(((s+/usr/lib/python2.7/idlelib/configHandler.pyRst InvalidThemecBseZRS((RR(((s+/usr/lib/python2.7/idlelib/configHandler.pyRstIdleConfParsercBs>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/lib/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(R tsectiontoptionttypetdefaultR((s+/usr/lib/python2.7/idlelib/configHandler.pytGet+s  cCs$|j|r|j|SgSdS(s4Return a list of options for given section, else [].N(t has_sectiontoptions(R R((s+/usr/lib/python2.7/idlelib/configHandler.pyt GetOptionList<s cCs|j|jdS(s&Load the configuration file from disk.N(treadR (R ((s+/usr/lib/python2.7/idlelib/configHandler.pytLoadCsN( RRt__doc__tNoneR tFalseRRR(((s+/usr/lib/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(R R((s+/usr/lib/python2.7/idlelib/configHandler.pyt AddSectionLscCs:x3|jD]%}|j|s |j|q q WdS(s)Remove any sections that have no options.N(tsectionsRtremove_section(R R((s+/usr/lib/python2.7/idlelib/configHandler.pytRemoveEmptySectionsQscCs|j|j S(s9Return True if no sections after removing empty sections.(R(R&(R ((s+/usr/lib/python2.7/idlelib/configHandler.pytIsEmptyWs 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"(R RR((s+/usr/lib/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$(R RRtvalue((s+/usr/lib/python2.7/idlelib/configHandler.pyt SetOptionescCs,tjj|jr(tj|jndS(s9Remove user config file self.file from disk if it exists.N(tostpathtexistsR tremove(R ((s+/usr/lib/python2.7/idlelib/configHandler.pyt RemoveFilevscCs|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 topentIOErrorR0tunlinktwriteR4(R tfnameR ((s+/usr/lib/python2.7/idlelib/configHandler.pytSave{s    ( RRR R%R(R)R+R/R4R;(((s+/usr/lib/python2.7/idlelib/configHandler.pyR#Gs     tIdleConfcBs eZdZdZdZdZddeedZ dZ dZ ddZ dZ d Zd Zeeed Zd Zd ZdZdZdZdZdZdZdZddZdZdZdZdZRS(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(smainR>s highlightskeys(t config_typest defaultCfgtuserCfgtcfgtCreateConfigHandlerst LoadCfgFiles(R ((s+/usr/lib/python2.7/idlelib/configHandler.pyR s      cCstdkr!tjjt}ntjjtjd}|j}i}i}xS|jD]H}tjj |d|d||RbtenableRRt enable_editort enable_shellR_N(tRemoveKeyBindNamesRetappendRaR-R"( R t active_onlyt editor_onlyt shell_onlytextnst userExtnstextnt activeExtnsR((s+/usr/lib/python2.7/idlelib/configHandler.pyt GetExtensions}s.        cCsq|}g}x6|D].}|jdr|j|j|qqW|jdtx|D] }||=q\W|S(s:Return extnNameList with keybinding section names removed.t _bindingst _cfgBindingstreverse(RR(tendswithRtindextsortR-(R t extnNameListtnamestkbNameIndiciesRvR((s+/usr/lib/python2.7/idlelib/configHandler.pyR~s   cCsdd}d|d}xI|jddD]5}x,|j|D]}||kr=|}q=q=Wq'W|S(sReturn the name of the extension binding virtualEvent, or None. virtualEvent - string, name of the virtual event to test for, without the enclosing '<< >>' s<>RiN(R!RtGetExtensionKeys(R t virtualEventtextNametvEventRtevent((s+/usr/lib/python2.7/idlelib/configHandler.pytGetExtnNameForEvents c Cs|d}|j}i}|jdj|r~|jdj|}x3|D](}d|d}||}|||s<>(tGetCurrentKeySetRBRR( R t extensionNametkeysNamet activeKeystextKeyst eventNamest eventNameRtbinding((s+/usr/lib/python2.7/idlelib/configHandler.pyRs    cCs|d}i}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||RRws<>(RBRRRatsplit(R RRRRRRR((s+/usr/lib/python2.7/idlelib/configHandler.pyt__GetRawExtensionKeyss  cCs|d}|j|}|jdj|r|jdj|}xJ|D]?}|jd||ddj}d|d}|||RRws<>(RRBRRRaR(R Rt bindsNametextBindsRRRR((s+/usr/lib/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 '<>'. iiR@RRw(RaR(R t keySetNameteventStrRR((s+/usr/lib/python2.7/idlelib/configHandler.pyt GetKeyBindings !cCs|j|j}tjdkrx[|jD]J\}}g|D]}|jdd^qD}||kr1|||>' s<>(R(R R((s+/usr/lib/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 (RRURKRVR7(R Rt keyBindingsRRR`((s+/usr/lib/python2.7/idlelib/configHandler.pyR,s|                                                      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'. RbR=RsInvalid configSet specifiedt HelpFilest;iRwiitkeycSst|dS(Ni(R(R((s+/usr/lib/python2.7/idlelib/configHandler.pyts( RCRBRRRtfindRtstripRR( R Rct helpSourcesRdRRR.tmenuItemthelpPath((s+/usr/lib/python2.7/idlelib/configHandler.pytGetExtraHelpSourceListys&       cCs |jd|jd}|S(sReturn a list of the details of all additional help sources. Tuples in the list are those of GetExtraHelpSourceList. RRb(R(R tallHelpSources((s+/usr/lib/python2.7/idlelib/configHandler.pytGetAllExtraHelpSourcesLists cCs:x3|jD](}|j|j|j|jq WdS(sLoad all configuration files.N(RBRRC(R R((s+/usr/lib/python2.7/idlelib/configHandler.pyRFscCs)x"|jD]}|j|jq WdS(s2Write all loaded user configuration files to disk.N(RCR;(R R((s+/usr/lib/python2.7/idlelib/configHandler.pytSaveUserCfgFilessN(RRR R RERLR!R-R"RaR/ReRrRkRxRzRR~RRRRRRRRRRRRFR(((s+/usr/lib/python2.7/idlelib/configHandler.pyR<s6   -    @  #       M RGc Cstd|dx|D]}||j}t|t|xf|D]^}||j|}t|t|x.|D]&}t|d||j||q|WqHWqWdS(Ns t=(RUR&RR(RDRR&RRR((s+/usr/lib/python2.7/idlelib/configHandler.pytdumpCfgs       R=RuRv(R t __future__RR0RKRt ExceptionRRRRRR#R<tidleConfRRRBRCRUR(((s+/usr/lib/python2.7/idlelib/configHandler.pyts&  'G"