Dictionary populated on first use.
| 14 | |
| 15 | |
| 16 | class LazyDict(DictMixin): |
| 17 | """Dictionary populated on first use.""" |
| 18 | data = None |
| 19 | |
| 20 | def __getitem__(self, key): |
| 21 | if self.data is None: |
| 22 | _fill_lock.acquire() |
| 23 | try: |
| 24 | if self.data is None: |
| 25 | self._fill() |
| 26 | finally: |
| 27 | _fill_lock.release() |
| 28 | return self.data[key.upper()] |
| 29 | |
| 30 | def __contains__(self, key): |
| 31 | if self.data is None: |
| 32 | _fill_lock.acquire() |
| 33 | try: |
| 34 | if self.data is None: |
| 35 | self._fill() |
| 36 | finally: |
| 37 | _fill_lock.release() |
| 38 | return key in self.data |
| 39 | |
| 40 | def __iter__(self): |
| 41 | if self.data is None: |
| 42 | _fill_lock.acquire() |
| 43 | try: |
| 44 | if self.data is None: |
| 45 | self._fill() |
| 46 | finally: |
| 47 | _fill_lock.release() |
| 48 | return iter(self.data) |
| 49 | |
| 50 | def __len__(self): |
| 51 | if self.data is None: |
| 52 | _fill_lock.acquire() |
| 53 | try: |
| 54 | if self.data is None: |
| 55 | self._fill() |
| 56 | finally: |
| 57 | _fill_lock.release() |
| 58 | return len(self.data) |
| 59 | |
| 60 | def keys(self): |
| 61 | if self.data is None: |
| 62 | _fill_lock.acquire() |
| 63 | try: |
| 64 | if self.data is None: |
| 65 | self._fill() |
| 66 | finally: |
| 67 | _fill_lock.release() |
| 68 | return self.data.keys() |
| 69 | |
| 70 | |
| 71 | class LazyList(list): |
nothing calls this directly
no outgoing calls
no test coverage detected