Sha256: 7864304c7fc7295d5c3fad93d3a06677a216e7c0d9a0fdb8880eeb7850ec11bf
Contents?: true
Size: 1.25 KB
Versions: 19
Compression:
Stored size: 1.25 KB
Contents
import re import types import threading class NamespaceCache(object): _instance = None namespace_cache = list() _lock = threading.Lock() def __new__(cls): if cls._instance is None: with cls._lock: if cls._instance is None: cls._instance = super(NamespaceCache, cls).__new__(cls) return cls._instance def cache_namespace(self, namespace_regex): with self._lock: self.namespace_cache.append(namespace_regex) def is_namespace_cache_empty(self): with self._lock: return len(self.namespace_cache) == 0 def is_type_allowed(self, type_to_check): with self._lock: for pattern in self.namespace_cache: if isinstance(type_to_check, types.ModuleType): if re.match(pattern, type_to_check.__name__): return True else: if re.match(pattern, type_to_check.__module__): return True return False def get_cached_namespaces(self): with self._lock: return self.namespace_cache[:] def clear_cache(self): with self._lock: self.namespace_cache.clear() return 0
Version data entries
19 entries across 14 versions & 1 rubygems