How to use the traitlets.validate function in traitlets

To help you get started, we’ve selected a few traitlets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github K3D-tools / K3D-jupyter / k3d / objects.py View on Github external
    @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']
github WorldWideTelescope / pywwt / pywwt / core.py View on Github external
    @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')
github creare-com / podpac / podpac / core / pipeline / pipeline.py View on Github external
    @tl.validate('definition')
    def _validate_definition(self, proposal):
        definition = proposal['value']
        parse_pipeline_definition(definition)
        return definition
github quantopian / serializable-traitlets / straitlets / builtin_models.py View on Github external
    @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
github microsoft / jupyter-Kqlmagic / azure / Kqlmagic / kql_magic.py View on Github external
    @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"]
github WorldWideTelescope / pywwt / pywwt / annotation.py View on Github external
    @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')
github jupyter / nbgrader / nbgrader / coursedir.py View on Github external
    @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()
github WorldWideTelescope / pywwt / pywwt / core.py View on Github external
    @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')
github creare-com / podpac / podpac / datalib / intake_catalog.py View on Github external
    @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
github Irrational-Encoding-Wizardry / yuuno / yuuno_ipython / ipython / apps / chooser.py View on Github external
    @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