class QueryMap(ConfigParser.ConfigParser): ''' classdocs ''' delimitor = " " def __init__(self, _querymapfile=comoonics.cluster.querymapfile, _clusterinfo=None): ''' Constructor ''' ConfigParser.ConfigParser.__init__(self) if isinstance(_clusterinfo, RedHatClusterInfo): self.mainsection = "redhatcluster" else: self.mainsection = "unknown" self.read(_querymapfile) def get(self, section, option, raw=True): if not section: section = self.mainsection self._defaults["param0"] = "%(param0)s" self._defaults["param1"] = "%(param1)s" self._defaults["param2"] = "%(param2)s" self._defaults["param3"] = "%(param3)s" self._defaults["param4"] = "%(param4)s" result = ConfigParser.ConfigParser.get(self, section, option, raw) if result.find(self.delimitor) > 0: return result.split(self.delimitor) else: return result def array2params(self, _array, suffix="param%s"): _params = {} for _index in range(len(_array)): _params[suffix % _index] = _array[_index] return _params def _interpolate(self, section, option, rawval, _vars): # do the string interpolation value = rawval depth = ConfigParser.MAX_INTERPOLATION_DEPTH while depth: # Loop through this until it's done depth -= 1 if "%(" in value: value = self._KEYCRE.sub(self._interpolation_replace, value) try: value = value % _vars except KeyError, e: raise ConfigParser.InterpolationMissingOptionError( option, section, rawval, e[0]) else: break if not "%(param" in value and "%" in value: raise ConfigParser.InterpolationDepthError(option, section, rawval) return value
def test_interpolationdeptherror(self): import pickle e1 = ConfigParser.InterpolationDepthError('option', 'section', 'rawval') pickled = pickle.dumps(e1) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.section, e2.section) self.assertEqual(e1.option, e2.option) self.assertEqual(repr(e1), repr(e2))
def test_interpolationdeptherror(self): import pickle e1 = ConfigParser.InterpolationDepthError('option', 'section', 'rawval') for proto in range(pickle.HIGHEST_PROTOCOL + 1): pickled = pickle.dumps(e1, proto) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.section, e2.section) self.assertEqual(e1.option, e2.option) self.assertEqual(repr(e1), repr(e2))