[Python-checkins] cpython (2.7): Update 2.7 idlelib.configHandler and reduce differences from 3.4 code.

terry.reedy python-checkins at python.org
Mon Oct 6 07:32:36 CEST 2014


https://hg.python.org/cpython/rev/d34258ab2ad4
changeset: 92834:d34258ab2ad4
branch: 2.7
user: Terry Jan Reedy <tjreedy at udel.edu>
date: Mon Oct 06 01:32:21 2014 -0400
summary:
 Update 2.7 idlelib.configHandler and reduce differences from 3.4 code.
files:
 Lib/idlelib/configHandler.py | 36 ++++++++++++-----------
 1 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py
--- a/Lib/idlelib/configHandler.py
+++ b/Lib/idlelib/configHandler.py
@@ -15,11 +15,12 @@
 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.
+
 """
 from __future__ import print_function
 import os
 import sys
-import string
+
 from ConfigParser import ConfigParser
 
 class InvalidConfigType(Exception): pass
@@ -36,7 +37,7 @@
 cfgFile - string, fully specified configuration file name
 """
 self.file=cfgFile
- ConfigParser.__init__(self,defaults=cfgDefaults)
+ ConfigParser.__init__(self, defaults=cfgDefaults)
 
 def Get(self, section, option, type=None, default=None, raw=False):
 """
@@ -144,7 +145,8 @@
 except IOError:
 os.unlink(fname)
 cfgFile = open(fname, 'w')
- self.write(cfgFile)
+ with cfgFile:
+ self.write(cfgFile)
 else:
 self.RemoveFile()
 
@@ -284,13 +286,13 @@
 configType must be one of ('main','extensions','highlight','keys')
 """
 if not (configType in ('main','extensions','highlight','keys')):
- raise InvalidConfigType, 'Invalid configType specified'
+ raise InvalidConfigType('Invalid configType specified')
 if configSet == 'user':
 cfgParser=self.userCfg[configType]
 elif configSet == 'default':
 cfgParser=self.defaultCfg[configType]
 else:
- raise InvalidConfigSet, 'Invalid configSet specified'
+ raise InvalidConfigSet('Invalid configSet specified')
 return cfgParser.sections()
 
 def GetHighlight(self, theme, element, fgBg=None):
@@ -318,7 +320,7 @@
 if fgBg == 'bg':
 return highlight["background"]
 else:
- raise InvalidFgBg, 'Invalid fgBg specified'
+ raise InvalidFgBg('Invalid fgBg specified')
 
 def GetThemeDict(self,type,themeName):
 """
@@ -334,7 +336,7 @@
 elif type == 'default':
 cfgParser=self.defaultCfg['highlight']
 else:
- raise InvalidTheme, 'Invalid theme type specified'
+ raise InvalidTheme('Invalid theme type specified')
 #foreground and background values are provded for each theme element
 #(apart from cursor) even though all these values are not yet used
 #by idle, to allow for their use in the future. Default values are
@@ -368,7 +370,7 @@
 'stderr-background':'#ffffff',
 'console-foreground':'#000000',
 'console-background':'#ffffff' }
- for element in theme.keys():
+ for element in theme:
 if not cfgParser.has_option(themeName,element):
 #we are going to return a default, print warning
 warning=('\n Warning: configHandler.py - IdleConf.GetThemeDict'
@@ -452,7 +454,7 @@
 extName=None
 vEvent='<<'+virtualEvent+'>>'
 for extn in self.GetExtensions(active_only=0):
- for event in self.GetExtensionKeys(extn).keys():
+ for event in self.GetExtensionKeys(extn):
 if event == vEvent:
 extName=extn
 return extName
@@ -550,7 +552,7 @@
 for extn in activeExtns:
 extKeys=self.__GetRawExtensionKeys(extn)
 if extKeys: #the extension defines keybindings
- for event in extKeys.keys():
+ for event in extKeys:
 if extKeys[event] in keySet.values():
 #the binding is already in use
 extKeys[event]='' #disable this binding
@@ -563,7 +565,7 @@
 virtualEvent - string, name of the virtual event to test for, without
 the enclosing '<< >>'
 """
- return ('<<'+virtualEvent+'>>') in self.GetCoreKeys().keys()
+ return ('<<'+virtualEvent+'>>') in self.GetCoreKeys()
 
 def GetCoreKeys(self, keySetName=None):
 """
@@ -626,7 +628,7 @@
 '<<del-word-right>>': ['<Control-Key-Delete>']
 }
 if keySetName:
- for event in keyBindings.keys():
+ for event in keyBindings:
 binding=self.GetKeyBinding(keySetName,event)
 if binding:
 keyBindings[event]=binding
@@ -658,7 +660,7 @@
 elif configSet=='default':
 cfgParser=self.defaultCfg['main']
 else:
- raise InvalidConfigSet, 'Invalid configSet specified'
+ raise InvalidConfigSet('Invalid configSet specified')
 options=cfgParser.GetOptionList('HelpFiles')
 for option in options:
 value=cfgParser.Get('HelpFiles',option,default=';')
@@ -666,7 +668,7 @@
 menuItem='' #make these empty
 helpPath='' #so value won't be added to list
 else: #config entry contains ';' as expected
- value=string.split(value,';')
+ value=value.split(';')
 menuItem=value[0].strip()
 helpPath=value[1].strip()
 if menuItem and helpPath: #neither are empty strings
@@ -688,7 +690,7 @@
 """
 load all configuration files.
 """
- for key in self.defaultCfg.keys():
+ for key in self.defaultCfg:
 self.defaultCfg[key].Load()
 self.userCfg[key].Load() #same keys
 
@@ -696,7 +698,7 @@
 """
 write all loaded user configuration files back to disk
 """
- for key in self.userCfg.keys():
+ for key in self.userCfg:
 self.userCfg[key].Save()
 
 idleConf=IdleConf()
@@ -705,7 +707,7 @@
 if __name__ == '__main__':
 def dumpCfg(cfg):
 print('\n', cfg, '\n')
- for key in cfg.keys():
+ for key in cfg:
 sections=cfg[key].sections()
 print(key)
 print(sections)
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /