Added some comments and basic write support

This commit is contained in:
2019-02-14 23:19:09 +01:00
parent e3319908a1
commit 6e7ee89148
5 changed files with 191 additions and 22 deletions

View File

@@ -8,6 +8,8 @@ LOGGER = Logger(__name__)
class SimpleNode:
_normal_attrs = ['path', '_data', '_connection']
def __init__(self, path: str, data: dict, connection: 'Connection'):
self.path = path
self._data = data
@@ -16,13 +18,37 @@ class SimpleNode:
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
size = self._data.get(':' + key)
if not isinstance(size, int):
LOGGER.warning("Size is not present")
# 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 __setitem__(self, key, value):
return self.__setattr__(key, value)
def __setattr__(self, key, value):
if key in self._normal_attrs:
return super(SimpleNode, self).__setattr__(key, value)
if (':' + key) in self._data:
value_type = self._data[':' + key]
if isinstance(value_type, int):
value_type = 'Binary'
else:
if isinstance(value, str):
value_type = 'String'
elif isinstance(value, int):
value_type = 'Long'
elif isinstance(value, bool):
value_type = 'Boolean'
else:
raise ValueError(f"Unknown value type {type(value)!r}")
self._connection._patch_builder.set_value(self.path + '/' + key, value, value_type)
def __getattr__(self, item: str):
try:
return super(SimpleNode, self).__getattr__(item)