Skip to content

Commit

Permalink
Removed config.validateConfig, config.conf.validator now uses Validat…
Browse files Browse the repository at this point in the history
…or constructor. re nvaccess#6846, nvaccess#667.

As there's no need to store a module-level validator, validator class instanciation will be done from config.ConfigManager constructor.
  • Loading branch information
josephsl committed Feb 12, 2017
1 parent aabbbd7 commit c92cb3c
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions source/config/__init__.py
Expand Up @@ -29,39 +29,6 @@
import profileUpgrader
from .configSpec import confspec

def validateConfig(configObj,validator,validationResult=None,keyList=None):
"""
@deprecated: Add-ons which need this should provide their own implementation.
"""
import warnings
warnings.warn("config.validateConfig deprecated. Callers should provide their own implementation.",
DeprecationWarning, 2)
if validationResult is None:
validationResult=configObj.validate(validator,preserve_errors=True)
if validationResult is True:
return None #No errors
if validationResult is False:
return "Badly formed configuration file"
errorStrings=[]
for k,v in validationResult.iteritems():
if v is True:
continue
newKeyList=list(keyList) if keyList is not None else []
newKeyList.append(k)
if isinstance(v,dict):
errorStrings.extend(validateConfig(configObj[k],validator,v,newKeyList))
else:
#If a key is invalid configObj does not record its default, thus we need to get and set the default manually
defaultValue=validator.get_default_value(configObj.configspec[k])
configObj[k]=defaultValue
if k not in configObj.defaults:
configObj.defaults.append(k)
errorStrings.append("%s: %s, defaulting to %s"%(k,v,defaultValue))
return errorStrings

#: @deprecated: Use C{conf.validator} instead.
val = Validator()

#: The active configuration, C{None} if it has not yet been loaded.
#: @type: ConfigObj
conf = None
Expand Down Expand Up @@ -103,7 +70,6 @@ def isInstalledCopy():
except WindowsError:
return False


def getInstalledUserConfigPath():
try:
return os.path.join(shlobj.SHGetFolderPath(0, shlobj.CSIDL_APPDATA), "nvda")
Expand Down Expand Up @@ -335,7 +301,7 @@ def __init__(self):
#: Whether profile triggers are enabled (read-only).
#: @type: bool
self.profileTriggersEnabled = True
self.validator = val
self.validator = Validator()
self.rootSection = None
self._shouldHandleProfileSwitch = True
self._pendingHandleProfileSwitch = False
Expand Down

0 comments on commit c92cb3c

Please sign in to comment.