Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _tree_level(level, raw=False, settings={}):
if isinstance(level, tables.Group):
if _sns and (level._v_title.startswith('SimpleNamespace:') or
DEEPDISH_IO_ROOT_IS_SNS in level._v_attrs):
node = SimpleNamespaceNode()
else:
node = DictNode()
for grp in level:
node.add(grp._v_name, _tree_level(grp, raw=raw, settings=settings))
for name in level._v_attrs._f_list():
v = level._v_attrs[name]
if name == DEEPDISH_IO_VERSION_STR:
node.header['dd_io_version'] = v
if name == DEEPDISH_IO_UNPACK:
node.header['dd_io_unpack'] = v
if name.startswith(DEEPDISH_IO_PREFIX):
continue
if isinstance(v, np.ndarray):
omitted = N-2 * ABRIDGE_SHOW_EACH_SIDE
info = paint('{} omitted ({} in total)'.format(omitted, N),
'darkgray', colorize=colorize)
print_row('...', info,
level=level,
parent=parent,
unpack=self.header.get('dd_io_unpack'),
colorize=colorize, file=file,
key_color='darkgray',
settings=settings)
continue
v = self.children[k]
final = level+1 == max_level
if (not settings.get('leaves-only') or
not isinstance(v, DictNode)):
print_row(k,
v.info(colorize=colorize, final_level=final),
level=level,
parent=parent,
unpack=self.header.get('dd_io_unpack'),
colorize=colorize, file=file,
settings=settings)
v.print(level=level+1, parent='{}{}/'.format(parent, k),
colorize=colorize, max_level=max_level, file=file,
settings=settings)
def print(self, level=0, parent='/', colorize=True, max_level=None,
file=sys.stdout):
if level == 0 and not self.header.get('dd_io_unpack'):
print_row('', self.info(colorize=colorize,
final_level=(0 == max_level)),
level=level, parent=parent, unpack=False,
colorize=colorize, file=file)
DictNode.print(self, level, parent, colorize, max_level, file)
v.print(level=level+1, parent='{}{}/'.format(parent, k),
colorize=colorize, max_level=max_level, file=file,
settings=settings)
def info(self, colorize=True, final_level=False):
return container_info('dict', size=len(self.children),
colorize=colorize,
type_color='purple',
final_level=final_level)
def __repr__(self):
s = ['{}={}'.format(k, repr(v)) for k, v in self.children.items()]
return 'DictNode({})'.format(', '.join(s))
class SimpleNamespaceNode(DictNode):
def info(self, colorize=True, final_level=False):
return container_info('SimpleNamespace', size=len(self.children),
colorize=colorize,
type_color='purple',
final_level=final_level)
def print(self, level=0, parent='/', colorize=True, max_level=None,
file=sys.stdout):
if level == 0 and not self.header.get('dd_io_unpack'):
print_row('', self.info(colorize=colorize,
final_level=(0 == max_level)),
level=level, parent=parent, unpack=False,
colorize=colorize, file=file)
DictNode.print(self, level, parent, colorize, max_level, file)
def __repr__(self):