Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@validate('colors')
def _validate_colors(self, proposal):
if type(proposal['value']) is dict or type(self.vertices) is dict:
return proposal['value']
required = self.vertices.size // 3 # (x, y, z) triplet per 1 color
actual = proposal['value'].size
if actual != 0 and required != actual:
raise TraitError('colors has wrong size: %s (%s required)' % (actual, required))
return proposal['value']
@validate('foreground_opacity')
def _validate_foreground_opacity(self, proposal):
if 0 <= proposal['value'] <= 1:
return proposal['value']
else:
raise TraitError('foreground_opacity should be between 0 and 1')
@tl.validate('definition')
def _validate_definition(self, proposal):
definition = proposal['value']
parse_pipeline_definition(definition)
return definition
@validate('port')
def _port_requires_hostname(self, proposal):
value = proposal['value']
if value is not None and self.hostname is None:
raise TraitError("Received port %s but no hostname." % value)
return value
@validate("temp_folder_location")
def _valid_value_temp_folder_location(self, proposal):
try:
if proposal["value"] == "auto":
raise ValueError("cannot be set to auto, after instance is loaded")
except (AttributeError , ValueError) as e:
message = f"The 'temp_folder_location' trait of a {Constants.MAGIC_CLASS_NAME} instance {str(e)}"
raise TraitError(message)
return proposal["value"]
@validate('line_width')
def _validate_linewidth(self, proposal):
if proposal['value'].unit.is_equivalent(u.pixel):
return proposal['value'].to(u.pixel)
else:
raise TraitError('line width must be in pixel equivalent unit')
@validate('course_id')
def _validate_course_id(self, proposal):
if proposal['value'].strip() != proposal['value']:
self.log.warning("course_id '%s' has trailing whitespace, stripping it away", proposal['value'])
return proposal['value'].strip()
@validate('location_longitude')
def _validate_longitude(self, proposal):
if proposal['value'].unit.physical_type == 'angle':
return proposal['value'].to(u.degree)
else:
raise TraitError('location_longitude not in angle units')
@tl.validate("field")
def _validate_field(self, proposed):
f = proposed["value"]
if self.datasource.container == "dataframe" and f is None:
raise ValueError("Field is required when source container is a dataframe")
return f
@validate('current')
def _validate_current(self, proposal):
if proposal.value not in self.values:
raise TraitError("Current value not part of the values.")
return proposal.value