Initial commit
This commit is contained in:
30
Crx/simplenode.py
Normal file
30
Crx/simplenode.py
Normal file
@@ -0,0 +1,30 @@
|
||||
if False:
|
||||
from .connection import Connection
|
||||
|
||||
|
||||
class SimpleNode:
|
||||
def __init__(self, path: str, data: dict, connection: 'Connection'):
|
||||
self.path = path
|
||||
self._data = data
|
||||
self._connection = connection
|
||||
|
||||
def __getitem__(self, item):
|
||||
return getattr(self, item)
|
||||
|
||||
def __getattr__(self, item: str):
|
||||
try:
|
||||
return super(SimpleNode, self).__getattr__(item)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
value = self._data.get(item)
|
||||
except KeyError:
|
||||
raise AttributeError()
|
||||
|
||||
if isinstance(value, dict):
|
||||
return self._connection.get_simple_node(self.path + '/' + item)
|
||||
return value
|
||||
|
||||
def __dir__(self):
|
||||
return super(SimpleNode, self).__dir__() + list(self._data.keys())
|
||||
Reference in New Issue
Block a user