def postParse(self, instring, loc, token_list): """Create a list from the tokens :param instring: :param loc: :param token_list: :return: """ cleaned_token_list = [] # Note that a token can be a duration value object: # >>> relativedelta(hours = 1) == '' # False # >>> relativedelta(hours = 1) != '' # False # relativedelta.__eq__() raises NotImplemented if it is compared with # a different object type so Python falls back to identity comparison. # We cannot compare this object to a string object. for token in token_list: if isinstance(token, str) and token == '': # This is the case when there was a trailing comma in the list. # The last token is just an empty string so we can safely ignore # it. continue if isinstance(token, ConfigInclude): cleaned_token_list.extend(token.tokens) else: cleaned_token_list.append(token) config_list = ConfigList(cleaned_token_list) return [config_list]
def postParse(self, instring, loc, token_list): """Create a list from the tokens :param instring: :param loc: :param token_list: :return: """ config_list = ConfigList(token_list) return [config_list]
def postParse(self, instring, loc, token_list): """Create a list from the tokens :param instring: :param loc: :param token_list: :return: """ cleaned_token_list = [token for tokens in (token.tokens if isinstance(token, ConfigInclude) else [token] for token in token_list if token != '') for token in tokens] config_list = ConfigList(cleaned_token_list) return [config_list]
def __generate(value: object, path): if is_dataclass(value): tree = { k: __generate(v, f"{path}.{k}") for k, v in asdict(value).items() } return ConfigTree(tree) if isinstance(value, dict): tree = {k: __generate(v, f"{path}.{k}") for k, v in value.items()} return ConfigTree(tree) if isinstance(value, list): tree = [__generate(e, f"{path}[]") for e in value] return ConfigList(tree) # needs a better impl. # if isinstance(value, timedelta): # if isinstance(value, relativedelta): return value