class Scope(object): __shared_state = {} __current_function = None __functions = {} def __init__(self): self.__dict__ = self.__shared_state def new(self, name, symbols = []): if getattr(self.__functions, name, None): raise ScopeError("multiple definitions of %s" % name) self.__functions[name] = [] self.__current_function = name self.add(symbols) def add(self, symbols): if type(symbols) != type([]): symbols = [symbols] for symbol in symbols: if symbol not in self.__functions[self.__current_function]: self.__functions[self.__current_function].append(symbol) def contains(self, name): return name in self.__functions[self.__current_function] def __str__(self): return "" % str(self.__functions)