def validator(trait, value): if value.dtype.kind not in kinds: raise TraitError('Array type not supported for trait %s of class %s: expected a \ array of kind in list %r and got an array of type %s (kind %s)'\ % (trait.name, trait.this_class, list(kinds), value.dtype, value.dtype.kind)) return value
def _validate_value(self, proposal): lower, upper = proposal['value'] if upper < lower: raise TraitError('setting lower > upper') return lower, upper
def _validate_index(self, proposal): "Check the range of each proposed index." if all(0 <= i < len(self._options_labels) for i in proposal.value): return proposal.value else: raise TraitError('Invalid selection: index out of bounds')
def __init__(self, *args, **kwargs): if len(kwargs.get('options', ())) == 0: raise TraitError('options must be nonempty') super(_MultipleSelectionNonempty, self).__init__(*args, **kwargs)
def element_error(self, obj): raise TraitError("Elements in the '{}' trait of an {} instance " "must be Python `logging` handler instances.".format( self.name, obj.__class__.__name__))
def _validate_index(self, proposal): if proposal.value is None or 0 <= proposal.value < len( self._options_labels): return proposal.value else: raise TraitError('Invalid selection: index out of bounds')
def validator(trait, value): if value.shape[0] < minlen: raise TraitError("%s needs have a minimum length of %d, got %d" % (trait.name, minlen, len(value)))
def _validate_interval(self, proposal): if proposal['value'] not in _INTERVAL_TYPES: raise TraitError('Unrecognized type : {}'.format( proposal['value'])) return proposal['value']
def _validate_options(self, proposal): proposal.value = _exhaust_iterable(proposal.value) self._options_full = _make_options(proposal.value) if len(self._options_full) == 0: raise TraitError("Option list must be nonempty") return proposal.value
def __init__(self, *args, **kwargs): if len(kwargs.get('options', ())) == 0: raise TraitError('options must be nonempty') super().__init__(*args, **kwargs)
def validate(self, obj, value): if self.min and V(value) < V(self.min): raise TraitError("bad version: %s < %s" % (value, self.min)) if self.max and (V(value) > V(self.max)): raise TraitError("bad version: %s > %s" % (value, self.max))
def _validate_style_callback(self, proposal): if not callable(proposal.value): raise TraitError( 'style_callback should be callable (functor/function/lambda)') return proposal.value
def _valid_fps(self, proposal): if proposal['value'] is not None and proposal['value'] < 0: raise TraitError('max_fps attribute must be a positive integer') return proposal['value']
def _validate_cmap(self, proposal): value = proposal['value'] if not value in COLORMAPS: raise TraitError('Invalid colormap') return value
def _validate_tz(self, value): if value.tzinfo is None: raise TraitError('%s values needs to be timezone aware' % (self.__class__.__name__, )) return value
def _valid_colorbar(self, proposal): colorbar = proposal['value'] if colorbar not in range(22): raise TraitError('colorbar must be in range 0 to 21 inclusive') return proposal['value']
def _valid_location(self, proposal: Bunch) -> str: if len(proposal["value"]) == 0: raise TraitError("'location' cannot be empty.") return proposal["value"]
def docker_build_host_validate(self, proposal): parts = urlparse(proposal.value) if parts.scheme != 'unix' or parts.netloc != '': raise TraitError("Only unix domain sockets on same node are supported for build_docker_host") return proposal.value
def _valid_default_name(self, proposal: Bunch) -> str: if len(proposal["value"]) == 0: raise TraitError("'default_name' cannot be empty.") return proposal["value"]
def _figure_formats_changed(self, name, old, new): if 'jpg' in new or 'jpeg' in new: if not pil_available(): raise TraitError("Requires PIL/Pillow for JPG figures") self._update_figure_formatters()
def _valid_icon(self, proposal: Bunch) -> str: if proposal["value"] is not None: if SVG_PATTERN.match(proposal["value"]) is None: raise TraitError("'icon' is not a valid SVG.") return proposal["value"]
def _validate_label(self, proposal): if (proposal.value is not None) and (proposal.value not in self._options_labels): raise TraitError('Invalid selection: label not found') return proposal.value
def _valid_template(self, proposal: Bunch) -> str: if proposal["value"] == pathlib.Path(""): raise TraitError("'template' cannot be empty.") return proposal["value"]
def _validate_label(self, proposal): if any(i not in self._options_labels for i in proposal.value): raise TraitError('Invalid selection: label not found') return proposal.value
def _hub_prefix_changed(self, name, old, new): if new == '/': raise TraitError("'/' is not a valid hub prefix") if not new.startswith(self.base_url): self.hub_prefix = url_path_join(self.base_url, new)
def _pre_save_hook_changed(self, name, old, new): if new and isinstance(new, string_types): self.pre_save_hook = import_item(self.pre_save_hook) elif new: if not callable(new): raise TraitError("pre_save_hook must be callable")
def _valid_data(self, proposal): if False: raise TraitError('Invalid XYZ') return proposal['value']