mirror of
https://github.com/python/cpython.git
synced 2025-10-13 10:23:28 +00:00
Whitespace Normalization
This commit is contained in:
parent
9532298c82
commit
6655e4bc27
23 changed files with 306 additions and 322 deletions
|
@ -5,8 +5,8 @@ Provides access to stored idle configuration information.
|
|||
# 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.
|
||||
# a requested config value, a message is printed to stderr to aid in
|
||||
# configuration problem notification and resolution.
|
||||
|
||||
import os, sys, string
|
||||
from ConfigParser import ConfigParser, NoOptionError, NoSectionError
|
||||
|
@ -26,17 +26,17 @@ class IdleConfParser(ConfigParser):
|
|||
"""
|
||||
self.file=cfgFile
|
||||
ConfigParser.__init__(self,defaults=cfgDefaults)
|
||||
|
||||
|
||||
def Get(self, section, option, type=None, default=None):
|
||||
"""
|
||||
Get an option value for given section/option or return default.
|
||||
If type is specified, return as type.
|
||||
"""
|
||||
if type=='bool':
|
||||
if type=='bool':
|
||||
getVal=self.getboolean
|
||||
elif type=='int':
|
||||
elif type=='int':
|
||||
getVal=self.getint
|
||||
else:
|
||||
else:
|
||||
getVal=self.get
|
||||
if self.has_option(section,option):
|
||||
#return getVal(section, option, raw, vars, default)
|
||||
|
@ -54,11 +54,11 @@ class IdleConfParser(ConfigParser):
|
|||
return []
|
||||
|
||||
def Load(self):
|
||||
"""
|
||||
Load the configuration file from disk
|
||||
"""
|
||||
Load the configuration file from disk
|
||||
"""
|
||||
self.read(self.file)
|
||||
|
||||
|
||||
class IdleUserConfParser(IdleConfParser):
|
||||
"""
|
||||
IdleConfigParser specialised for user configuration handling.
|
||||
|
@ -70,15 +70,15 @@ class IdleUserConfParser(IdleConfParser):
|
|||
"""
|
||||
if not self.has_section(section):
|
||||
self.add_section(section)
|
||||
|
||||
|
||||
def RemoveEmptySections(self):
|
||||
"""
|
||||
remove any sections that have no options
|
||||
"""
|
||||
for section in self.sections():
|
||||
if not self.GetOptionList(section):
|
||||
self.remove_section(section)
|
||||
|
||||
self.remove_section(section)
|
||||
|
||||
def IsEmpty(self):
|
||||
"""
|
||||
Remove empty sections and then return 1 if parser has no sections
|
||||
|
@ -89,7 +89,7 @@ class IdleUserConfParser(IdleConfParser):
|
|||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
||||
def RemoveOption(self,section,option):
|
||||
"""
|
||||
If section/option exists, remove it.
|
||||
|
@ -97,7 +97,7 @@ class IdleUserConfParser(IdleConfParser):
|
|||
"""
|
||||
if self.has_section(section):
|
||||
return self.remove_option(section,option)
|
||||
|
||||
|
||||
def SetOption(self,section,option,value):
|
||||
"""
|
||||
Sets option to value, adding section if required.
|
||||
|
@ -114,14 +114,14 @@ class IdleUserConfParser(IdleConfParser):
|
|||
self.add_section(section)
|
||||
self.set(section,option,value)
|
||||
return 1
|
||||
|
||||
|
||||
def RemoveFile(self):
|
||||
"""
|
||||
Removes the user config file from disk if it exists.
|
||||
"""
|
||||
if os.path.exists(self.file):
|
||||
os.remove(self.file)
|
||||
|
||||
os.remove(self.file)
|
||||
|
||||
def Save(self):
|
||||
"""
|
||||
If config isn't empty, write file to disk. If config is empty,
|
||||
|
@ -154,10 +154,10 @@ class IdleConf:
|
|||
self.CreateConfigHandlers()
|
||||
self.LoadCfgFiles()
|
||||
#self.LoadCfg()
|
||||
|
||||
|
||||
def CreateConfigHandlers(self):
|
||||
"""
|
||||
set up a dictionary of config parsers for default and user
|
||||
set up a dictionary of config parsers for default and user
|
||||
configurations respectively
|
||||
"""
|
||||
#build idle install path
|
||||
|
@ -170,15 +170,15 @@ class IdleConf:
|
|||
defCfgFiles={}
|
||||
usrCfgFiles={}
|
||||
for cfgType in configTypes: #build config file names
|
||||
defCfgFiles[cfgType]=os.path.join(idleDir,'config-'+cfgType+'.def')
|
||||
usrCfgFiles[cfgType]=os.path.join(userDir,'config-'+cfgType+'.cfg')
|
||||
defCfgFiles[cfgType]=os.path.join(idleDir,'config-'+cfgType+'.def')
|
||||
usrCfgFiles[cfgType]=os.path.join(userDir,'config-'+cfgType+'.cfg')
|
||||
for cfgType in configTypes: #create config parsers
|
||||
self.defaultCfg[cfgType]=IdleConfParser(defCfgFiles[cfgType])
|
||||
self.userCfg[cfgType]=IdleUserConfParser(usrCfgFiles[cfgType])
|
||||
|
||||
|
||||
def GetUserCfgDir(self):
|
||||
"""
|
||||
Creates (if required) and returns a filesystem directory for storing
|
||||
Creates (if required) and returns a filesystem directory for storing
|
||||
user config files.
|
||||
"""
|
||||
cfgDir='.idlerc'
|
||||
|
@ -192,23 +192,23 @@ class IdleConf:
|
|||
if userDir=='~': #we still don't have a home directory
|
||||
#traditionally idle has defaulted to os.getcwd(), is this adeqate?
|
||||
userDir = os.getcwd() #hack for no real homedir
|
||||
userDir=os.path.join(userDir,cfgDir)
|
||||
userDir=os.path.join(userDir,cfgDir)
|
||||
if not os.path.exists(userDir):
|
||||
try: #make the config dir if it doesn't exist yet
|
||||
try: #make the config dir if it doesn't exist yet
|
||||
os.mkdir(userDir)
|
||||
except IOError:
|
||||
warn=('\n Warning: unable to create user config directory\n '+
|
||||
userDir+'\n')
|
||||
sys.stderr.write(warn)
|
||||
return userDir
|
||||
|
||||
|
||||
def GetOption(self, configType, section, option, default=None, type=None):
|
||||
"""
|
||||
Get an option value for given config type and given general
|
||||
Get an option value for given config type and given general
|
||||
configuration section/option or return a default. If type is specified,
|
||||
return as type. Firstly the user configuration is checked, with a
|
||||
fallback to the default configuration, and a final 'catch all'
|
||||
fallback to a useable passed-in default if the option isn't present in
|
||||
return as type. Firstly the user configuration is checked, with a
|
||||
fallback to the default configuration, and a final 'catch all'
|
||||
fallback to a useable passed-in default if the option isn't present in
|
||||
either the user or the default configuration.
|
||||
configType must be one of ('main','extensions','highlight','keys')
|
||||
If a default is returned a warning is printed to stderr.
|
||||
|
@ -224,12 +224,12 @@ class IdleConf:
|
|||
' returning default value: '+`default`+'\n')
|
||||
sys.stderr.write(warning)
|
||||
return default
|
||||
|
||||
|
||||
def GetSectionList(self, configSet, configType):
|
||||
"""
|
||||
Get a list of sections from either the user or default config for
|
||||
Get a list of sections from either the user or default config for
|
||||
the given config type.
|
||||
configSet must be either 'user' or 'default'
|
||||
configSet must be either 'user' or 'default'
|
||||
configType must be one of ('main','extensions','highlight','keys')
|
||||
"""
|
||||
if not (configType in ('main','extensions','highlight','keys')):
|
||||
|
@ -241,13 +241,13 @@ class IdleConf:
|
|||
else:
|
||||
raise InvalidConfigSet, 'Invalid configSet specified'
|
||||
return cfgParser.sections()
|
||||
|
||||
|
||||
def GetHighlight(self, theme, element, fgBg=None):
|
||||
"""
|
||||
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.
|
||||
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.
|
||||
"""
|
||||
if self.defaultCfg['highlight'].has_section(theme):
|
||||
themeDict=self.GetThemeDict('default',theme)
|
||||
|
@ -256,7 +256,7 @@ class IdleConf:
|
|||
fore=themeDict[element+'-foreground']
|
||||
if element=='cursor': #there is no config value for cursor bg
|
||||
back=themeDict['normal-background']
|
||||
else:
|
||||
else:
|
||||
back=themeDict[element+'-background']
|
||||
highlight={"foreground": fore,"background": back}
|
||||
if not fgBg: #return dict of both colours
|
||||
|
@ -266,7 +266,7 @@ class IdleConf:
|
|||
return highlight["foreground"]
|
||||
if fgBg == 'bg':
|
||||
return highlight["background"]
|
||||
else:
|
||||
else:
|
||||
raise InvalidFgBg, 'Invalid fgBg specified'
|
||||
|
||||
def GetThemeDict(self,type,themeName):
|
||||
|
@ -275,7 +275,7 @@ class IdleConf:
|
|||
themeName - string, theme name
|
||||
Returns a dictionary which holds {option:value} for each element
|
||||
in the specified theme. Values are loaded over a set of ultimate last
|
||||
fallback defaults to guarantee that all theme elements are present in
|
||||
fallback defaults to guarantee that all theme elements are present in
|
||||
a newly created theme.
|
||||
"""
|
||||
if type == 'user':
|
||||
|
@ -288,15 +288,15 @@ class IdleConf:
|
|||
#(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
|
||||
#generally black and white.
|
||||
theme={ 'normal-foreground':'#000000',
|
||||
'normal-background':'#ffffff',
|
||||
'keyword-foreground':'#000000',
|
||||
'keyword-background':'#ffffff',
|
||||
'comment-foreground':'#000000',
|
||||
'comment-background':'#ffffff',
|
||||
theme={ 'normal-foreground':'#000000',
|
||||
'normal-background':'#ffffff',
|
||||
'keyword-foreground':'#000000',
|
||||
'keyword-background':'#ffffff',
|
||||
'comment-foreground':'#000000',
|
||||
'comment-background':'#ffffff',
|
||||
'string-foreground':'#000000',
|
||||
'string-background':'#ffffff',
|
||||
'definition-foreground':'#000000',
|
||||
'definition-foreground':'#000000',
|
||||
'definition-background':'#ffffff',
|
||||
'hilite-foreground':'#000000',
|
||||
'hilite-background':'gray',
|
||||
|
@ -305,9 +305,9 @@ class IdleConf:
|
|||
'hit-foreground':'#ffffff',
|
||||
'hit-background':'#000000',
|
||||
'error-foreground':'#ffffff',
|
||||
'error-background':'#000000',
|
||||
#cursor (only foreground can be set)
|
||||
'cursor-foreground':'#000000',
|
||||
'error-background':'#000000',
|
||||
#cursor (only foreground can be set)
|
||||
'cursor-foreground':'#000000',
|
||||
#shell window
|
||||
'stdout-foreground':'#000000',
|
||||
'stdout-background':'#ffffff',
|
||||
|
@ -323,22 +323,22 @@ class IdleConf:
|
|||
'\n from theme '+`themeName`+'.\n'+
|
||||
' returning default value: '+`theme[element]`+'\n')
|
||||
sys.stderr.write(warning)
|
||||
colour=cfgParser.Get(themeName,element,default=theme[element])
|
||||
colour=cfgParser.Get(themeName,element,default=theme[element])
|
||||
theme[element]=colour
|
||||
return theme
|
||||
|
||||
|
||||
def CurrentTheme(self):
|
||||
"""
|
||||
Returns the name of the currently active theme
|
||||
Returns the name of the currently active theme
|
||||
"""
|
||||
return self.GetOption('main','Theme','name',default='')
|
||||
|
||||
|
||||
def CurrentKeys(self):
|
||||
"""
|
||||
Returns the name of the currently active key set
|
||||
Returns the name of the currently active key set
|
||||
"""
|
||||
return self.GetOption('main','Keys','name',default='')
|
||||
|
||||
|
||||
def GetExtensions(self, activeOnly=1):
|
||||
"""
|
||||
Gets a list of all idle extensions declared in the config files.
|
||||
|
@ -350,7 +350,7 @@ class IdleConf:
|
|||
self.GetSectionList('user','extensions'))
|
||||
for extn in userExtns:
|
||||
if extn not in extns: #user has added own extension
|
||||
extns.append(extn)
|
||||
extns.append(extn)
|
||||
if activeOnly:
|
||||
activeExtns=[]
|
||||
for extn in extns:
|
||||
|
@ -360,21 +360,21 @@ class IdleConf:
|
|||
activeExtns.append(extn)
|
||||
return activeExtns
|
||||
else:
|
||||
return extns
|
||||
return extns
|
||||
|
||||
def RemoveKeyBindNames(self,extnNameList):
|
||||
#get rid of keybinding section names
|
||||
names=extnNameList
|
||||
kbNameIndicies=[]
|
||||
for name in names:
|
||||
if name.endswith('_bindings') or name.endswith('_cfgBindings'):
|
||||
kbNameIndicies.append(names.index(name))
|
||||
if name.endswith('_bindings') or name.endswith('_cfgBindings'):
|
||||
kbNameIndicies.append(names.index(name))
|
||||
kbNameIndicies.sort()
|
||||
kbNameIndicies.reverse()
|
||||
for index in kbNameIndicies: #delete each keybinding section name
|
||||
for index in kbNameIndicies: #delete each keybinding section name
|
||||
del(names[index])
|
||||
return names
|
||||
|
||||
|
||||
def GetExtnNameForEvent(self,virtualEvent):
|
||||
"""
|
||||
Returns the name of the extension that virtualEvent is bound in, or
|
||||
|
@ -389,7 +389,7 @@ class IdleConf:
|
|||
if event == vEvent:
|
||||
extName=extn
|
||||
return extName
|
||||
|
||||
|
||||
def GetExtensionKeys(self,extensionName):
|
||||
"""
|
||||
returns a dictionary of the configurable keybindings for a particular
|
||||
|
@ -405,8 +405,8 @@ class IdleConf:
|
|||
event='<<'+eventName+'>>'
|
||||
binding=activeKeys[event]
|
||||
extKeys[event]=binding
|
||||
return extKeys
|
||||
|
||||
return extKeys
|
||||
|
||||
def __GetRawExtensionKeys(self,extensionName):
|
||||
"""
|
||||
returns a dictionary of the configurable keybindings for a particular
|
||||
|
@ -422,13 +422,13 @@ class IdleConf:
|
|||
eventName,default='').split()
|
||||
event='<<'+eventName+'>>'
|
||||
extKeys[event]=binding
|
||||
return extKeys
|
||||
|
||||
return extKeys
|
||||
|
||||
def GetExtensionBindings(self,extensionName):
|
||||
"""
|
||||
Returns a dictionary of all the event bindings for a particular
|
||||
extension. The configurable keybindings are returned as they exist in
|
||||
the dictionary returned by GetCurrentKeySet; that is, where re-used
|
||||
the dictionary returned by GetCurrentKeySet; that is, where re-used
|
||||
keybindings are disabled.
|
||||
"""
|
||||
bindsName=extensionName+'_bindings'
|
||||
|
@ -441,14 +441,14 @@ class IdleConf:
|
|||
eventName,default='').split()
|
||||
event='<<'+eventName+'>>'
|
||||
extBinds[event]=binding
|
||||
|
||||
return extBinds
|
||||
|
||||
|
||||
return extBinds
|
||||
|
||||
def GetKeyBinding(self, keySetName, eventStr):
|
||||
"""
|
||||
returns the keybinding for a specific event.
|
||||
keySetName - string, name of key binding set
|
||||
eventStr - string, the virtual event we want the binding for,
|
||||
eventStr - string, the virtual event we want the binding for,
|
||||
represented as a string, eg. '<<event>>'
|
||||
"""
|
||||
eventName=eventStr[2:-2] #trim off the angle brackets
|
||||
|
@ -457,10 +457,10 @@ class IdleConf:
|
|||
|
||||
def GetCurrentKeySet(self):
|
||||
return self.GetKeySet(self.CurrentKeys())
|
||||
|
||||
|
||||
def GetKeySet(self,keySetName):
|
||||
"""
|
||||
Returns a dictionary of: all requested core keybindings, plus the
|
||||
Returns a dictionary of: all requested core keybindings, plus the
|
||||
keybindings for all currently active extensions. If a binding defined
|
||||
in an extension is already in use, that binding is disabled.
|
||||
"""
|
||||
|
@ -483,7 +483,7 @@ class IdleConf:
|
|||
the enclosing '<< >>'
|
||||
"""
|
||||
return ('<<'+virtualEvent+'>>') in self.GetCoreKeys().keys()
|
||||
|
||||
|
||||
def GetCoreKeys(self, keySetName=None):
|
||||
"""
|
||||
returns the requested set of core keybindings, with fallbacks if
|
||||
|
@ -504,7 +504,7 @@ class IdleConf:
|
|||
'<<do-nothing>>': ['<Control-x>'],
|
||||
'<<end-of-file>>': ['<Control-d>'],
|
||||
'<<python-docs>>': ['<F1>'],
|
||||
'<<python-context-help>>': ['<Shift-F1>'],
|
||||
'<<python-context-help>>': ['<Shift-F1>'],
|
||||
'<<history-next>>': ['<Alt-n>'],
|
||||
'<<history-previous>>': ['<Alt-p>'],
|
||||
'<<interrupt-execution>>': ['<Control-c>'],
|
||||
|
@ -527,7 +527,7 @@ class IdleConf:
|
|||
'<<find-selection>>': ['<Control-F3>'],
|
||||
'<<find>>': ['<Control-f>'],
|
||||
'<<replace>>': ['<Control-h>'],
|
||||
'<<goto-line>>': ['<Alt-g>'],
|
||||
'<<goto-line>>': ['<Alt-g>'],
|
||||
'<<smart-backspace>>': ['<Key-BackSpace>'],
|
||||
'<<newline-and-indent>>': ['<Key-Return> <Key-KP_Enter>'],
|
||||
'<<smart-indent>>': ['<Key-Tab>'],
|
||||
|
@ -552,18 +552,18 @@ class IdleConf:
|
|||
' returning default value: '+`keyBindings[event]`+'\n')
|
||||
sys.stderr.write(warning)
|
||||
return keyBindings
|
||||
|
||||
|
||||
def GetExtraHelpSourceList(self,configSet):
|
||||
"""
|
||||
Returns a list of tuples containing the details of any additional
|
||||
help sources configured in the requested configSet ('user' or 'default')
|
||||
, or an empty list if there are none. Returned tuples are of the form
|
||||
form (menu_item , path_to_help_file , option).
|
||||
"""
|
||||
"""
|
||||
helpSources=[]
|
||||
if configSet=='user':
|
||||
cfgParser=self.userCfg['main']
|
||||
elif configSet=='default':
|
||||
elif configSet=='default':
|
||||
cfgParser=self.defaultCfg['main']
|
||||
else:
|
||||
raise InvalidConfigSet, 'Invalid configSet specified'
|
||||
|
@ -583,28 +583,28 @@ class IdleConf:
|
|||
|
||||
def GetAllExtraHelpSourcesList(self):
|
||||
"""
|
||||
Returns a list of tuples containing the details of all additional help
|
||||
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.
|
||||
"""
|
||||
allHelpSources=( self.GetExtraHelpSourceList('default')+
|
||||
"""
|
||||
allHelpSources=( self.GetExtraHelpSourceList('default')+
|
||||
self.GetExtraHelpSourceList('user') )
|
||||
return allHelpSources
|
||||
|
||||
return allHelpSources
|
||||
|
||||
def LoadCfgFiles(self):
|
||||
"""
|
||||
"""
|
||||
load all configuration files.
|
||||
"""
|
||||
for key in self.defaultCfg.keys():
|
||||
self.defaultCfg[key].Load()
|
||||
self.userCfg[key].Load() #same keys
|
||||
self.defaultCfg[key].Load()
|
||||
self.userCfg[key].Load() #same keys
|
||||
|
||||
def SaveUserCfgFiles(self):
|
||||
"""
|
||||
write all loaded user configuration files back to disk
|
||||
"""
|
||||
for key in self.userCfg.keys():
|
||||
self.userCfg[key].Save()
|
||||
self.userCfg[key].Save()
|
||||
|
||||
idleConf=IdleConf()
|
||||
|
||||
|
@ -618,7 +618,7 @@ if __name__ == '__main__':
|
|||
print sections
|
||||
for section in sections:
|
||||
options=cfg[key].options(section)
|
||||
print section
|
||||
print section
|
||||
print options
|
||||
for option in options:
|
||||
print option, '=', cfg[key].Get(section,option)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue