當前位置: 首頁>>代碼示例>>Python>>正文


Python jsonschema.exceptions方法代碼示例

本文整理匯總了Python中jsonschema.exceptions方法的典型用法代碼示例。如果您正苦於以下問題:Python jsonschema.exceptions方法的具體用法?Python jsonschema.exceptions怎麽用?Python jsonschema.exceptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jsonschema的用法示例。


在下文中一共展示了jsonschema.exceptions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _validate_data

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_data(self, data: dict):
        """
        Validates data against provider schema. Raises :class:`~notifiers.exceptions.BadArguments` if relevant

        :param data: Data to validate
        :raises: :class:`~notifiers.exceptions.BadArguments`
        """
        log.debug("validating provided data")
        e = best_match(self.validator.iter_errors(data))
        if e:
            custom_error_key = f"error_{e.validator}"
            msg = (
                e.schema[custom_error_key]
                if e.schema.get(custom_error_key)
                else e.message
            )
            raise BadArguments(validation_error=msg, provider=self.name, data=data) 
開發者ID:liiight,項目名稱:notifiers,代碼行數:19,代碼來源:core.py

示例2: notify

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def notify(self, raise_on_errors: bool = False, **kwargs) -> Response:
        """
        The main method to send notifications. Prepares the data via the
        :meth:`~notifiers.core.SchemaResource._prepare_data` method and then sends the notification
        via the :meth:`~notifiers.core.Provider._send_notification` method

        :param kwargs: Notification data
        :param raise_on_errors: Should the :meth:`~notifiers.core.Response.raise_on_errors` be invoked immediately
        :return: A :class:`~notifiers.core.Response` object
        :raises: :class:`~notifiers.exceptions.NotificationError` if ``raise_on_errors`` is set to True and response
         contained errors
        """
        data = self._process_data(**kwargs)
        rsp = self._send_notification(data)
        if raise_on_errors:
            rsp.raise_on_errors()
        return rsp 
開發者ID:liiight,項目名稱:notifiers,代碼行數:19,代碼來源:core.py

示例3: validate_output_parser

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def validate_output_parser(cls, value):
        OPTIONS_VALIDATORS = {
            'delimited': cls._validate_delimited_output_parser_options
        }

        schema = {
            "type": "object",
            "properties": {"type": {"type": "string",
                                    "enum": ["delimited"]},
                           "options": {"type": "object"}
            },
            "required": ["type"]
        }
        try:
            jsonschema.validate(value, schema)
        except jsonschema.exceptions.ValidationError as e:
            raise ValidationError(e.message)
    
        # Validate options specific to parser_type
        if value.get('options'):
            validate_options = OPTIONS_VALIDATORS[value.get('type')]
            validate_options(value.get('options')) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:24,代碼來源:validators.py

示例4: _validate_and_cache_nonfile

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_and_cache_nonfile(self, data):
        value = data.get('_value_info')
        type = data.get('type')
        try:
            self._cached_data_object = DataObject.objects.get(
                uuid=data.get('uuid'))
            self._do_create_new_data_object=False
            self._verify_data_object_matches_data(self._cached_data_object, data)
            return data
        except DataObject.DoesNotExist:
            pass
        self._cached_data_object = DataObjectSerializer\
            .Meta.model.get_by_value(value, type)
        self._do_create_new_data_object=False # already saved
        try:
            self._cached_data_object.full_clean()
        except django.core.exceptions.ValidationError as e:
            raise serializers.ValidationError(e.message_dict)
        return data 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:21,代碼來源:data_objects.py

示例5: _create_file

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _create_file(self, validated_data):
        value = validated_data.pop('_value_info')
        try:
            self._cached_data_object.save()
            # If file belongs to TaskAttemptLogFile, make the connection
            log_file = self.context.get('task_attempt_log_file')
            if log_file:
                log_file.setattrs_and_save_with_retries({
                    'data_object': self._cached_data_object})
            resource_init_args = copy.copy(value)
            if self.context.get('task_attempt'):
                resource_init_args['task_attempt'] = self.context.get(
                    'task_attempt')
            resource_init_args['data_object'] = self._cached_data_object
            file_resource = FileResource.initialize(**resource_init_args)
            try:
                file_resource.full_clean()
            except django.core.exceptions.ValidationError as e:
                raise serializers.ValidationError(e.message_dict)
            file_resource.save()
            return self._cached_data_object
        except Exception as e:
            self._cleanup(self._cached_data_object)
            raise 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:26,代碼來源:data_objects.py

示例6: update

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def update(self, instance, validated_data):
        # The only time a DataObject should be updated by the client
        # is to change upload_status of a file.
        value_data = validated_data.get('_value_info')
        if value_data:
            if not instance.type == 'file':
                raise serializers.ValidationError(
                    'Updating value is not allowed on DataObject '\
                    'with type "%s"' % instance.type)
            if not instance.value:
                raise serializers.ValidationError(
                    "Failed to update DataObject because FileResource is missing")
            try:
                instance.value.setattrs_and_save_with_retries({
                    'upload_status': value_data.get('upload_status')})
            except django.core.exceptions.ValidationError as e:
                raise serializers.ValidationError(e.messages)
        return instance 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:20,代碼來源:data_objects.py

示例7: raise_on_errors

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def raise_on_errors(self):
        """
        Raises a :class:`~notifiers.exceptions.NotificationError` if response hold errors

        :raises: :class:`~notifiers.exceptions.NotificationError`: If response has errors
        """
        if self.errors:
            raise NotificationError(
                provider=self.provider,
                data=self.data,
                errors=self.errors,
                response=self.response,
            ) 
開發者ID:liiight,項目名稱:notifiers,代碼行數:15,代碼來源:core.py

示例8: _validate_schema

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_schema(self):
        """
        Validates provider schema for syntax issues. Raises :class:`~notifiers.exceptions.SchemaError` if relevant

        :raises: :class:`~notifiers.exceptions.SchemaError`
        """
        try:
            log.debug("validating provider schema")
            self.validator.check_schema(self.schema)
        except jsonschema.SchemaError as e:
            raise SchemaError(
                schema_error=e.message, provider=self.name, data=self.schema
            ) 
開發者ID:liiight,項目名稱:notifiers,代碼行數:15,代碼來源:core.py

示例9: _validate_data_dependencies

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_data_dependencies(self, data: dict) -> dict:
        """
        Validates specific dependencies based on the content of the data, as opposed to its structure which can be
        verified on the schema level

        :param data: Data to validate
        :return: Return data if its valid
        :raises: :class:`~notifiers.exceptions.NotifierException`
        """
        return data 
開發者ID:liiight,項目名稱:notifiers,代碼行數:12,代碼來源:core.py

示例10: test_valid_modification

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def test_valid_modification():
    # Calls to validate() in this function should not raise exceptions
    mod_types = ['Phosphorylation', 'Dephosphorylation', 'Ubiquitination',
                 'Deubiquitination', 'Sumoylation', 'Desumoylation',
                 'Hydroxylation', 'Dehydroxylation', 'Acetylation',
                 'Deacetylation', 'Glycosylation', 'Deglycosylation',
                 'Farnesylation', 'Defarnesylation', 'Geranylgeranylation',
                 'Degeranylgeranylation', 'Palmitoylation', 'Depalmitoylation',
                 'Myristoylation', 'Demyristoylation', 'Ribosylation',
                 'Deribosylation', 'Methylation', 'Demethylation',
                 'Activation', 'Inhibition', 'IncreaseAmount',
                 'DecreaseAmount']

    for mod_type in mod_types:
        s = {'enz': valid_agent1, 'sub': valid_agent2,
             'type': mod_type, 'id': '5'}
        jsonschema.validate([s], schema)

        s['enz'] = agent_mod
        jsonschema.validate([s], schema)

        s['enz'] = agent_mut
        jsonschema.validate([s], schema)

        s['enz'] = agent_act
        jsonschema.validate([s], schema)

        if mod_type not in ['Activation', 'Inhibition', 'IncreaseAmount',
                            'DecreaseAmount']:
            s['residue'] = 'S'
            jsonschema.validate([s], schema)

            s['position'] = '10'
            jsonschema.validate([s], schema) 
開發者ID:sorgerlab,項目名稱:indra,代碼行數:36,代碼來源:test_json_schema.py

示例11: _validate_boolean_data

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_boolean_data(cls, value):
        schema = {"type": "object",
                  "properties": {"value": {"type": "boolean"}},
                  "required": ["value"]}
        try:
            jsonschema.validate(value, schema)
        except jsonschema.exceptions.ValidationError as e:
            raise ValidationError(e.message) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:10,代碼來源:validators.py

示例12: _validate_float_data

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_float_data(cls, value):
        schema = {"type": "object",
                  "properties": {"value": {"type": "number"}},
                  "required": ["value"]}
        try:
            jsonschema.validate(value, schema)
        except jsonschema.exceptions.ValidationError as e:
            raise ValidationError(e.message) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:10,代碼來源:validators.py

示例13: _validate_integer_data

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_integer_data(cls, value):
        schema = {"type": "object",
                  "properties": {"value": {"type": "number"}},
                  "required": ["value"]}
        try:
            jsonschema.validate(value, schema)
        except jsonschema.exceptions.ValidationError as e:
            raise ValidationError(e.message) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:10,代碼來源:validators.py

示例14: _validate_string_data

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def _validate_string_data(cls, value):
        schema = {"type": "object",
                  "properties": {"value": {"type": "string"}},
                  "required": ["value"]}
        try:
            jsonschema.validate(value, schema)
        except jsonschema.exceptions.ValidationError as e:
            raise ValidationError(e.message) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:10,代碼來源:validators.py

示例15: validate_environment

# 需要導入模塊: import jsonschema [as 別名]
# 或者: from jsonschema import exceptions [as 別名]
def validate_environment(value):
    schema = {
        "type": "object",
        "properties": {"docker_image": {"type": "string"}},
        "required": ["docker_image"]
    }

    try:
        jsonschema.validate(value, schema)
    except jsonschema.exceptions.ValidationError as e:
        raise ValidationError(e.message) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:13,代碼來源:validators.py


注:本文中的jsonschema.exceptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。