Skip to content

Commit

Permalink
Replaced use of sanitize_identifier with calls to label/group sanitizer
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Dec 1, 2015
1 parent b870948 commit dbcc80d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions holoviews/core/dimension.py
Expand Up @@ -801,11 +801,11 @@ def __call__(self, options=None, **kwargs):
raise Exception("Cannot mix target specification keys such as 'Image' with non-target keywords.")
elif not any(targets):
# Not targets specified - add current object as target
sanitized_group = sanitize_identifier(self.group)
sanitized_group = group_sanitizer(self.group)
if self.label:
identifier = ('%s.%s.%s' % (self.__class__.__name__,
sanitized_group,
sanitize_identifier(self.label)))
label_sanitizer(self.label)))
elif sanitized_group != self.__class__.__name__:
identifier = '%s.%s' % (self.__class__.__name__, sanitized_group)
else:
Expand Down
6 changes: 3 additions & 3 deletions holoviews/core/io.py
Expand Up @@ -28,7 +28,7 @@
from .layout import Layout
from .ndmapping import OrderedDict, NdMapping, UniformNdMapping
from .options import Store
from .util import unique_iterator, sanitize_identifier
from .util import unique_iterator, sanitize_identifier, group_sanitizer, label_sanitizer


class Reference(param.Parameterized):
Expand Down Expand Up @@ -336,8 +336,8 @@ def save(self_or_cls, obj, filename, key={}, info={}, **kwargs):
components = list(obj.data.values())
entries = entries if len(entries) > 1 else [entries[0]+'(L)']
else:
entries = ['%s.%s' % (sanitize_identifier(obj.group, False),
sanitize_identifier(obj.label, False))]
entries = ['%s.%s' % (group_sanitizer(obj.group, False),
label_sanitizer(obj.label, False))]
components = [obj]

for component, entry in zip(components, entries):
Expand Down
6 changes: 3 additions & 3 deletions holoviews/core/layout.py
Expand Up @@ -15,7 +15,7 @@
from .dimension import Dimension, Dimensioned, ViewableElement
from .ndmapping import OrderedDict, NdMapping, UniformNdMapping
from .tree import AttrTree
from .util import int_to_roman, sanitize_identifier
from .util import int_to_roman, sanitize_identifier, group_sanitizer, label_sanitizer
from . import traversal


Expand Down Expand Up @@ -384,9 +384,9 @@ def from_values(cls, val):
return cls._from_values(val)
elif collection:
val = val[0]
group = sanitize_identifier(val.group)
group = group_sanitizer(val.group)
group = ''.join([group[0].upper(), group[1:]])
label = sanitize_identifier(val.label if val.label else 'I')
label = label_sanitizer(val.label if val.label else 'I')
label = ''.join([label[0].upper(), label[1:]])
return cls(items=[((group, label), val)])

Expand Down
11 changes: 6 additions & 5 deletions holoviews/core/options.py
Expand Up @@ -39,7 +39,7 @@

import param
from .tree import AttrTree
from .util import sanitize_identifier
from .util import sanitize_identifier, group_sanitizer,label_sanitizer
from .pprint import InfoPrinter

class OptionError(Exception):
Expand Down Expand Up @@ -479,8 +479,9 @@ def closest(self, obj, group):
In addition, closest supports custom options by checking the
object
"""
components = (obj.__class__.__name__, sanitize_identifier(obj.group),
sanitize_identifier(obj.label))
components = (obj.__class__.__name__,
group_sanitizer(obj.group),
label_sanitizer(obj.label))
return self.find(components).options(group)


Expand Down Expand Up @@ -700,12 +701,12 @@ def _slice_match_level(self, overlay_items):
level += 1 # Types match
if len(spec) == 1: continue

group = [el.group, sanitize_identifier(el.group, escape=False)]
group = [el.group, group_sanitizer(el.group, escape=False)]
if spec[1] in group: level += 1 # Values match
else: return None

if len(spec) == 3:
group = [el.label, sanitize_identifier(el.label, escape=False)]
group = [el.label, label_sanitizer(el.label, escape=False)]
if (spec[2] in group):
level += 1 # Labels match
else:
Expand Down
6 changes: 3 additions & 3 deletions holoviews/core/pprint.py
Expand Up @@ -16,7 +16,7 @@
import re
# IPython not required to import ParamPager
from param.ipython import ParamPager
from holoviews.core.util import sanitize_identifier
from holoviews.core.util import sanitize_identifier, group_sanitizer, label_sanitizer



Expand Down Expand Up @@ -88,8 +88,8 @@ def info(cls, obj, ansi=False, backend='matplotlib'):
@classmethod
def get_target(cls, obj):
objtype=obj.__class__.__name__
group = sanitize_identifier(obj.group)
label = ('.'+sanitize_identifier(obj.label) if obj.label else '')
group = group_sanitizer(obj.group)
label = ('.' + label_sanitizer(obj.label) if obj.label else '')
target = '{objtype}.{group}{label}'.format(objtype=objtype,
group=group,
label=label)
Expand Down
4 changes: 2 additions & 2 deletions holoviews/core/util.py
Expand Up @@ -418,8 +418,8 @@ def match_spec(element, specification):
match_tuple = ()
match = specification.get((), {})
for spec in [type(element).__name__,
sanitize_identifier(element.group, escape=False),
sanitize_identifier(element.label, escape=False)]:
group_sanitizer(element.group, escape=False),
label_sanitizer(element.label, escape=False)]:
match_tuple += (spec,)
if match_tuple in specification:
match = specification[match_tuple]
Expand Down
5 changes: 3 additions & 2 deletions holoviews/operation/element.py
Expand Up @@ -10,7 +10,7 @@

from ..core import (ElementOperation, NdOverlay, Overlay, GridMatrix,
HoloMap, Columns, Element)
from ..core.util import find_minmax, sanitize_identifier
from ..core.util import find_minmax, sanitize_identifier, group_sanitizer, label_sanitizer
from ..element.chart import Histogram, Curve, Scatter
from ..element.raster import Raster, Image, RGB, QuadMesh
from ..element.path import Contours, Polygons
Expand Down Expand Up @@ -204,9 +204,10 @@ def _match(cls, el, spec):
if not isinstance(el, Image) or spec_dict['type'] != 'Image':
raise NotImplementedError("Only Image currently supported")

sanitizers = {'group':group_sanitizer, 'label':label_sanitizer}
strength = 1
for key in ['group', 'label']:
attr_value = sanitize_identifier(getattr(el, key))
attr_value = sanitizers[key](getattr(el, key))
if key in spec_dict:
if spec_dict[key] != attr_value: return None
strength += 1
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/plot.py
Expand Up @@ -314,8 +314,8 @@ def _get_norm_opts(self, obj):
norm_opts = {}

# Get all elements' type.group.label specs and ids
type_val_fn = lambda x: (x.id, (type(x).__name__, util.sanitize_identifier(x.group, escape=False),
util.sanitize_identifier(x.label, escape=False))) \
type_val_fn = lambda x: (x.id, (type(x).__name__, util.group_sanitizer(x.group, escape=False),
util.label_sanitizer(x.label, escape=False))) \
if isinstance(x, Element) else None
element_specs = {(idspec[0], idspec[1]) for idspec in obj.traverse(type_val_fn)
if idspec is not None}
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/widgets/__init__.py
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from ...core import OrderedDict, NdMapping
from ...core.options import Store
from ...core.util import (sanitize_identifier, safe_unicode, basestring,
from ...core.util import (dimension_sanitizer, safe_unicode, basestring,
unique_iterator)
from ...core.traversal import hierarchical

Expand Down Expand Up @@ -259,7 +259,7 @@ def get_widgets(self):
dim_vals = repr([v for v in dim_vals if v is not None])
dim_str = safe_unicode(dim.name)
visibility = 'visibility: visible' if len(dim_vals) > 1 else 'visibility: hidden; height: 0;'
widget_data = dict(dim=sanitize_identifier(dim_str), dim_label=dim_str,
widget_data = dict(dim=dimension_sanitizer(dim_str), dim_label=dim_str,
dim_idx=idx, vals=dim_vals, type=widget_type,
visibility=visibility, step=step, next_dim=next_dim,
next_vals=next_vals)
Expand Down

0 comments on commit dbcc80d

Please sign in to comment.