Exemplo n.º 1
0
class MemoryNamespaceManager(NamespaceManager):
    namespaces = util.SyncDict()

    def __init__(self, namespace, **kwargs):
        NamespaceManager.__init__(self, namespace)
        self.dictionary = MemoryNamespaceManager.namespaces.get(self.namespace,
                                                                dict)
    def get_creation_lock(self, key):
        return NameLock(
            identifier="memorycontainer/funclock/%s/%s" % (self.namespace, key),
            reentrant=True
        )

    def __getitem__(self, key): 
        return self.dictionary[key]

    def __contains__(self, key): 
        return self.dictionary.__contains__(key)

    def has_key(self, key): 
        return self.dictionary.__contains__(key)
        
    def __setitem__(self, key, value):
        self.dictionary[key] = value
    
    def __delitem__(self, key):
        del self.dictionary[key]

    def do_remove(self):
        self.dictionary.clear()
        
    def keys(self):
        return self.dictionary.keys()
Exemplo n.º 2
0
class MemoryNamespaceManager(AbstractDictionaryNSManager):
    namespaces = util.SyncDict()

    def __init__(self, namespace, **kwargs):
        AbstractDictionaryNSManager.__init__(self, namespace)
        self.dictionary = MemoryNamespaceManager.namespaces.get(
            self.namespace, dict)
Exemplo n.º 3
0
class MemoryNamespaceManager(AbstractDictionaryNSManager):
    """:class:`.NamespaceManager` that uses a Python dictionary for storage."""

    namespaces = util.SyncDict()

    def __init__(self, namespace, **kwargs):
        AbstractDictionaryNSManager.__init__(self, namespace)
        self.dictionary = MemoryNamespaceManager.\
                                namespaces.get(self.namespace, dict)
Exemplo n.º 4
0
class MemoryNamespaceManager(NamespaceManager):
    namespaces = util.SyncDict(_threading.Lock(), {})

    def __init__(self, namespace, **kwargs):
        NamespaceManager.__init__(self, namespace, **kwargs)

        self.lock = Synchronizer(
            identifier="memorycontainer/namespacelock/%s" % self.namespace,
            use_files=False)

        self.dictionary = MemoryNamespaceManager.namespaces.get(
            self.namespace, lambda: {})

    def do_acquire_read_lock(self):
        self.lock.acquire_read_lock()

    def do_release_read_lock(self):
        self.lock.release_read_lock()

    def do_acquire_write_lock(self, wait=True):
        return self.lock.acquire_write_lock(wait)

    def do_release_write_lock(self):
        self.lock.release_write_lock()

    # the open and close methods are totally overridden to eliminate
    # the unnecessary "open count" computation involved
    def open(self, *args, **kwargs):
        pass

    def close(self, *args, **kwargs):
        pass

    def __getitem__(self, key):
        return self.dictionary[key]

    def __contains__(self, key):
        return self.dictionary.__contains__(key)

    def has_key(self, key):
        return self.dictionary.__contains__(key)

    def __setitem__(self, key, value):
        self.dictionary[key] = value

    def __delitem__(self, key):
        del self.dictionary[key]

    def do_remove(self):
        self.dictionary.clear()

    def keys(self):
        return self.dictionary.keys()