mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 18:21:54 +00:00
26 lines
582 B
Python
26 lines
582 B
Python
|
import asyncio
|
||
|
|
||
|
class BIRDException(Exception):
|
||
|
pass
|
||
|
|
||
|
class Basic:
|
||
|
def __init__(self, bird):
|
||
|
self.bird = bird
|
||
|
self.data = None
|
||
|
|
||
|
def __getattr__(self, name):
|
||
|
if self.data is None:
|
||
|
raise BIRDException(f"Call update() to get data")
|
||
|
|
||
|
if name not in self.data:
|
||
|
raise BIRDException(f"Unknown key {name} in {type(self)}")
|
||
|
|
||
|
return self.data[name]
|
||
|
|
||
|
def __repr__(self):
|
||
|
return f"{type(self).__name__}({self.data})"
|
||
|
|
||
|
async def load(self):
|
||
|
if self.data is None:
|
||
|
await self.update()
|