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

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Python/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Python/MacOs/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Python/Linux/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Python/MacOs/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Python/Linux/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Python/MacOs/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Python/Linux/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Python/Linux/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Python/MacOs/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Python/MacOs/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Python/Linux/X64/javonet/core/namespaceCache/NamespaceCache.py