Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@bothmethod
def instance(self_or_cls,**params):
"""
Return an instance of this class, copying parameters from any
existing instance provided.
"""
if isinstance (self_or_cls,ParameterizedMetaclass):
cls = self_or_cls
else:
p = params
params = dict(self_or_cls.get_param_values())
params.update(p)
params.pop('name')
cls = self_or_cls.__class__
inst=Parameterized.__new__(cls)
@bothmethod
def get_plot(self_or_cls, obj, renderer=None):
"""
Given a HoloViews Viewable return a corresponding plot instance.
"""
# Initialize DynamicMaps with first data item
initialize_dynamic(obj)
if not isinstance(obj, Plot):
if not displayable(obj):
obj = collate(obj)
initialize_dynamic(obj)
obj = Compositor.map(obj, mode='data', backend=self_or_cls.backend)
if not renderer:
renderer = self_or_cls
if not isinstance(self_or_cls, Renderer):
@bothmethod
def entries(self_or_cls, filename):
with zipfile.ZipFile(filename, 'r') as f:
return [el for el in f.namelist() if el != 'metadata']
@bothmethod
def _save_prefix(self_or_cls, ext):
"Hook to prefix content for instance JS when saving HTML"
return
@bothmethod
def pprint(cls_or_slf, node):
reprval = cls_or_slf.serialize(cls_or_slf.recurse(node))
if sys.version_info.major == 2:
return str(reprval.encode("utf8"))
else:
return str(reprval)
@bothmethod
def shift(cls_or_slf, lines, shift=0):
return [(lvl+shift, line) for (lvl, line) in lines]
@bothmethod
def save(self_or_cls, obj, filename, key={}, info={}, **kwargs):
base_info = {'file-ext': 'hvz', 'mime_type':self_or_cls.mime_type}
key = self_or_cls._merge_metadata(obj, self_or_cls.key_fn, key)
info = self_or_cls._merge_metadata(obj, self_or_cls.info_fn, info, base_info)
compression = zipfile.ZIP_STORED if self_or_cls.compress else zipfile.ZIP_DEFLATED
filename = self_or_cls._filename(filename) if isinstance(filename, str) else filename
with zipfile.ZipFile(filename, 'w', compression=compression) as f:
if isinstance(obj, Layout) and not isinstance(obj, Overlay):
entries = ['.'.join(k) for k in obj.data.keys()]
components = list(obj.data.values())
entries = entries if len(entries) > 1 else [entries[0]+'(L)']
else:
entries = ['%s.%s' % (group_sanitizer(obj.group, False),
label_sanitizer(obj.label, False))]
@bothmethod
def _save_prefix(self_or_cls, ext):
"Hook to prefix content for instance JS when saving HTML"
if ext == 'html':
return '\n'.join(self_or_cls.html_assets()).encode('utf8')
return
@bothmethod
def recurse(cls_or_slf, node, attrpath=None, attrpaths=[], siblings=[], level=0, value_dims=True):
"""
Recursive function that builds up an ASCII tree given an
AttrTree node.
"""
level, lines = cls_or_slf.node_info(node, attrpath, attrpaths, siblings, level, value_dims)
attrpaths = ['.'.join(k) for k in node.keys()] if hasattr(node, 'children') else []
siblings = [node.get(child) for child in attrpaths]
for attrpath in attrpaths:
lines += cls_or_slf.recurse(node.get(attrpath), attrpath, attrpaths=attrpaths,
siblings=siblings, level=level+1, value_dims=value_dims)
return lines
@param.parameterized.bothmethod
def add_aliases(self_or_cls, **kwargs):
"""
Conveniently add new aliases as keyword arguments. For instance
you can add a new alias with add_aliases(short='Longer string')
"""
self_or_cls.aliases.update({v:k for k,v in kwargs.items()})