Sha256: f755f459b437be1664a8456ce5d68f550539e9f23f3abff76becdb5485d60bf4

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 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

5 entries across 5 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Python/Windows/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Python/Windows/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Python/Windows/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Python/Windows/X64/javonet/core/namespaceCache/NamespaceCache.py
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Python/Windows/X64/javonet/core/namespaceCache/NamespaceCache.py