from logging import Logger if False: from .connection import Connection LOGGER = Logger(__name__) class SimpleNode: def __init__(self, path: str, data: dict, connection: 'Connection'): self.path = path self._data = data self._connection = connection def download(self, key: str = 'jcr:data') -> bytes: if ':' + key not in self._data: LOGGER.warning(f"Key :{key} is not present, binary probably not available") # TODO value of the :{key} must be an int # TODO value denotes file size, warn/deny large files? return self._connection.download_binary(self.path + '/' + key) 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())