def Global(name, default=None): ''' Global (per-thread) binding from operator name to implementation, by namespace. ''' # Delay creation to handle circular dependencies. assert name namespace_map = singleton(NamespaceMap) return namespace_map.get(name, default)
def relations(base): # if base is a factory then we want the related type try: base = canonical_matcher_type(base) except MatcherTypeException: pass table = singleton(Relations, dict) if base not in table: table[base] = Relations(base) return table[base]
def singleton(cls): ''' Get a singleton instance. ''' return singleton(cls)