def _configParserToDict(self, parser): out = dict() for section in parser.sections(): s = dict() for opt in parser.options(section): value = str(parser.get(section, opt)) test = value.lower() if test.startswith('"') and test.endswith('"'): value = value[1:-1] elif value.startswith(ConfigReader._VECTOR_PREFIX): value = Vector3D.fromConfig(value[len(ConfigReader._VECTOR_PREFIX):-1]) elif value.startswith(ConfigReader._JSON_PREFIX): value = json.loads(value[len(ConfigReader._JSON_PREFIX):]) elif isinstance(value, basestring) and (value in ['None', 'none', '']): value = None elif test in ['on', 'true', 'yes']: value = True elif test in ['off', 'false', 'no']: value = False elif ConfigReader._NUMERIC_REGEX.match(test): try: value = float(value) if test.find('.') else int(value) except Exception, err: pass s[opt] = value out[section] = s
def _fromSerializedDict(cls, src): out = dict() for n,v in src.iteritems(): if isinstance(v, dict): if 'objectType' in v: if v['objectType'] == Vector3D.__name__: v = Vector3D.fromSerialDict(v) else: v = cls._fromSerializedDict(v) out[n] = v return out