def _validateArguments(self): if self._config['resetConfig']: language = self._config['language'] checkForUpdatesAutomatically = self._config['checkForUpdatesAutomatically'] self._config = self._defaultConfig self._config['language'] = language self._config['checkForUpdatesAutomatically'] = checkForUpdatesAutomatically raise InvalidConfigValue("*"+getMessage("config-cleared-notification")) if not isValidLanguage(self._config['language']): self._config['language'] = "" def _isPortValid(varToTest): try: if varToTest == "" or varToTest is None: return False if str(varToTest).isdigit() == False: return False varToTest = int(varToTest) if varToTest > 65535 or varToTest < 1: return False return True except: return False for key in self._boolean: if self._config[key] == "True": self._config[key] = True elif self._config[key] == "False": self._config[key] = False for key in self._serialised: if self._config[key] is None or self._config[key] == "": self._config[key] = {} elif isinstance(self._config[key], (str, unicode)): self._config[key] = ast.literal_eval(self._config[key]) for key in self._tristate: if self._config[key] == "True": self._config[key] = True elif self._config[key] == "False": self._config[key] = False elif self._config[key] == "None": self._config[key] = None for key in self._numeric: self._config[key] = float(self._config[key]) for key in self._required: if key == "playerPath": player = None if self._config["playerPath"]: player = self._playerFactory.getPlayerByPath(self._config["playerPath"]) if player: self._config["playerClass"] = player else: raise InvalidConfigValue(getMessage("player-path-config-error")) playerPathErrors = player.getPlayerPathErrors(self._config["playerPath"], self._config['file'] if self._config['file'] else None) if playerPathErrors: raise InvalidConfigValue(playerPathErrors) elif key == "host": self._config["host"], self._config["port"] = self._splitPortAndHost(self._config["host"]) hostNotValid = (self._config["host"] == "" or self._config["host"] is None) portNotValid = (_isPortValid(self._config["port"]) == False) if hostNotValid: raise InvalidConfigValue(getMessage("no-hostname-config-error")) elif portNotValid: raise InvalidConfigValue(getMessage("invalid-port-config-error")) elif self._config[key] == "" or self._config[key] is None: raise InvalidConfigValue(getMessage("empty-value-config-error").format(key.capitalize()))
def _validateArguments(self): if self._config['resetConfig']: language = self._config['language'] checkForUpdatesAutomatically = self._config[ 'checkForUpdatesAutomatically'] self._config = self._defaultConfig self._config['language'] = language self._config[ 'checkForUpdatesAutomatically'] = checkForUpdatesAutomatically raise InvalidConfigValue("*" + getMessage("config-cleared-notification")) if not isValidLanguage(self._config['language']): self._config['language'] = "" def _isPortValid(varToTest): try: if varToTest == "" or varToTest is None: return False if not str(varToTest).isdigit(): return False varToTest = int(varToTest) if varToTest > 65535 or varToTest < 1: return False return True except: return False for key in self._boolean: if self._config[key] == "True": self._config[key] = True elif self._config[key] == "False": self._config[key] = False for key in self._serialised: if self._config[key] is None or self._config[key] == "": self._config[key] = {} elif isinstance(self._config[key], str): self._config[key] = ast.literal_eval(self._config[key]) for key in self._tristate: if self._config[key] == "True": self._config[key] = True elif self._config[key] == "False": self._config[key] = False elif self._config[key] == "None": self._config[key] = None for key in self._numeric: self._config[key] = float(self._config[key]) for key in self._hexadecimal: match = re.search(r'^#(?:[0-9a-fA-F]){6}$', self._config[key]) if not match: self._config[key] = "#FFFFFF" for key in self._required: if key == "playerPath": player = None if self._config["playerPath"]: player = self._playerFactory.getPlayerByPath( self._config["playerPath"]) if player: self._config["playerClass"] = player else: raise InvalidConfigValue( getMessage("player-path-config-error")) playerPathErrors = player.getPlayerPathErrors( self._config["playerPath"], self._config['file'] if self._config['file'] else None) if playerPathErrors: raise InvalidConfigValue(playerPathErrors) elif key == "host": self._config["host"], self._config[ "port"] = self._splitPortAndHost(self._config["host"]) hostNotValid = (self._config["host"] == "" or self._config["host"] is None) portNotValid = (_isPortValid(self._config["port"]) == False) if hostNotValid: raise InvalidConfigValue( getMessage("no-hostname-config-error")) elif portNotValid: raise InvalidConfigValue( getMessage("invalid-port-config-error")) elif self._config[key] == "" or self._config[key] is None: raise InvalidConfigValue( getMessage("empty-value-config-error").format( key.capitalize()))