d2o_librarian.py 418 Bytes
Newer Older
theos's avatar
theos committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# -*- coding: utf-8 -*-

from weakref import WeakValueDictionary as weakdict


class _d2o_librarian(object):

    def __init__(self):
        self.library = weakdict()
        self.counter = 0

    def register(self, d2o):
        self.counter += 1
        self.library[self.counter] = d2o
        return self.counter

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

d2o_librarian = _d2o_librarian()