• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python exception.ExceptionCollector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中toscaparser.common.exception.ExceptionCollector的典型用法代码示例。如果您正苦于以下问题:Python ExceptionCollector类的具体用法?Python ExceptionCollector怎么用?Python ExceptionCollector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ExceptionCollector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: validate

 def validate(self):
     if len(self.args) < 2:
         ExceptionCollector.appendException(
             ValueError(_('Expected arguments: "node-template-name", "req-or-cap" ' '(optional), "property name".'))
         )
         return
     if len(self.args) == 2:
         found_prop = self._find_property(self.args[1])
         if not found_prop:
             return
         prop = found_prop.value
         if not isinstance(prop, Function):
             get_function(self.tosca_tpl, self.context, prop)
     elif len(self.args) >= 3:
         # do not use _find_property to avoid raise KeyError
         # if the prop is not found
         # First check if there is property with this name
         node_tpl = self._find_node_template(self.args[0])
         props = node_tpl.get_properties() if node_tpl else []
         index = 2
         found = [props[self.args[1]]] if self.args[1] in props else []
         if found:
             property_value = found[0].value
         else:
             index = 3
             # then check the req or caps
             property_value = self._find_req_or_cap_property(self.args[1], self.args[2])
         if len(self.args) > index:
             for elem in self.args[index:]:
                 if isinstance(property_value, list):
                     int_elem = int(elem)
                     property_value = self._get_index_value(property_value, int_elem)
                 else:
                     property_value = self._get_attribute_value(property_value, elem)
开发者ID:openstack,项目名称:tosca-parser,代码行数:34,代码来源:functions.py


示例2: _common_validate_properties

 def _common_validate_properties(self, entitytype, properties):
     allowed_props = []
     required_props = []
     for p in entitytype.get_properties_def_objects():
         allowed_props.append(p.name)
         if p.required:
             required_props.append(p.name)
     if properties:
         self._common_validate_field(properties, allowed_props,
                                     'properties')
         # make sure it's not missing any property required by a tosca type
         missingprop = []
         for r in required_props:
             if r not in properties.keys():
                 missingprop.append(r)
         if missingprop:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
                     what='"properties" of template "%s"' % self.name,
                     required=missingprop))
     else:
         if required_props:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
                     what='"properties" of template "%s"' % self.name,
                     required=missingprop))
开发者ID:semk,项目名称:tosca-parser,代码行数:26,代码来源:entity_template.py


示例3: __init__

    def __init__(self, name, value=None, schema=None):
        self.name = name
        self.value = value
        self.schema = schema

        try:
            self.schema['type']
        except KeyError:
            msg = (_('Schema definition of "%(pname)s" must have a "type" '
                     'attribute.') % dict(pname=self.name))
            ExceptionCollector.appendException(
                InvalidSchemaError(message=msg))

        if 'required' in self.schema:
            required = self.schema['required']
            if not isinstance(required, bool):
                if required.lower() not in self.VALID_REQUIRED_VALUES:
                    valid_values = ', '.join(self.VALID_REQUIRED_VALUES)
                    msg = (_('Schema definition of "%(propname)s" has '
                             '"required" attribute with invalid value '
                             '"%(value1)s". The value must be one of '
                             '"%(value2)s".') % {"propname": self.name,
                                                 "value1": required,
                                                 "value2": valid_values})
                    ExceptionCollector.appendException(
                        InvalidSchemaError(message=msg))
开发者ID:semk,项目名称:tosca-parser,代码行数:26,代码来源:property_definition.py


示例4: validate_range

def validate_range(range):
    # list class check
    validate_list(range)
    # validate range list has a min and max
    if len(range) != 2:
        ExceptionCollector.appendException(
            ValueError(_('"%s" is not a valid range.') % range))
    # validate min and max are numerics or the keyword UNBOUNDED
    min_test = max_test = False
    if not range[0] == RANGE_UNBOUNDED:
        min = validate_numeric(range[0])
    else:
        min_test = True
    if not range[1] == RANGE_UNBOUNDED:
        max = validate_numeric(range[1])
    else:
        max_test = True
    # validate the max > min (account for UNBOUNDED)
    if not min_test and not max_test:
        # Note: min == max is allowed
        if min > max:
            ExceptionCollector.appendException(
                ValueError(_('"%s" is not a valid range.') % range))

    return range
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:25,代码来源:validateutils.py


示例5: _validate_and_load_imports

    def _validate_and_load_imports(self):
        imports_names = set()

        if not self.importslist:
            msg = _('"imports" keyname is defined without including '
                    'templates.')
            log.error(msg)
            ExceptionCollector.appendException(ValidationError(message=msg))
            return

        for import_def in self.importslist:
            if isinstance(import_def, dict):
                for import_name, import_uri in import_def.items():
                    if import_name in imports_names:
                        msg = (_('Duplicate import name "%s" was found.') %
                               import_name)
                        log.error(msg)
                        ExceptionCollector.appendException(
                            ValidationError(message=msg))
                    imports_names.add(import_name)

                    custom_type = self._load_import_template(import_name,
                                                             import_uri)
                    namespace_prefix = None
                    if isinstance(import_uri, dict):
                        namespace_prefix = import_uri.get(
                            self.NAMESPACE_PREFIX)

                    self._update_custom_def(custom_type, namespace_prefix)
            else:  # old style of imports
                custom_type = self._load_import_template(None,
                                                         import_def)
                if custom_type:
                    self._update_custom_def(custom_type, None)
开发者ID:semk,项目名称:tosca-parser,代码行数:34,代码来源:imports.py


示例6: _validate_fields

 def _validate_fields(self):
     if self.defs:
         for name in self.defs.keys():
             if name not in self.SECTIONS:
                 ExceptionCollector.appendException(
                     UnknownFieldError(what='Group Type %s'
                                       % self.grouptype, field=name))
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:7,代码来源:grouptype.py


示例7: __init__

 def __init__(self, property_name, property_type, constraint):
     super(Pattern, self).__init__(property_name, property_type, constraint)
     if not isinstance(self.constraint_value, self.valid_types):
         ExceptionCollector.appendException(
             InvalidSchemaError(message=_('The property "pattern" '
                                          'expects a string.')))
     self.match = re.compile(self.constraint_value).match
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:7,代码来源:constraints.py


示例8: validate

 def validate(self):
     if len(self.args) != 2:
         ExceptionCollector.appendException(
             ValueError(_('Illegal arguments for function "{0}". Expected '
                          'arguments: "node-template-name", '
                          '"attribute-name"').format(GET_ATTRIBUTE)))
     self._find_node_template_containing_attribute()
开发者ID:semk,项目名称:tosca-parser,代码行数:7,代码来源:functions.py


示例9: _validate_requirements_keys

 def _validate_requirements_keys(self, requirement):
     for key in requirement.keys():
         if key not in self.REQUIREMENTS_SECTION:
             ExceptionCollector.appendException(
                 UnknownFieldError(
                     what='"requirements" of template "%s"' % self.name,
                     field=key))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:7,代码来源:nodetemplate.py


示例10: _validate_keys

 def _validate_keys(self):
     if self.defs:
         for key in self.defs.keys():
             if key not in self.SECTIONS:
                 ExceptionCollector.appendException(
                     UnknownFieldError(what='Nodetype"%s"' % self.ntype,
                                       field=key))
开发者ID:santhoshkmr64,项目名称:santhosh,代码行数:7,代码来源:nodetype.py


示例11: _validate_requirements

    def _validate_requirements(self):
        type_requires = self.type_definition.get_all_requirements()
        allowed_reqs = ["template"]
        if type_requires:
            for treq in type_requires:
                for key, value in treq.items():
                    allowed_reqs.append(key)
                    if isinstance(value, dict):
                        for key in value:
                            allowed_reqs.append(key)

        requires = self.type_definition.get_value(self.REQUIREMENTS,
                                                  self.entity_tpl)
        if requires:
            if not isinstance(requires, list):
                ExceptionCollector.appendException(
                    TypeMismatchError(
                        what='"requirements" of template "%s"' % self.name,
                        type='list'))
            for req in requires:
                for r1, value in req.items():
                    if isinstance(value, dict):
                        self._validate_requirements_keys(value)
                        self._validate_requirements_properties(value)
                        allowed_reqs.append(r1)
                self._common_validate_field(req, allowed_reqs, 'requirements')
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:26,代码来源:nodetemplate.py


示例12: _validate_type_version

 def _validate_type_version(self, version):
     if version not in self.VALID_TEMPLATE_VERSIONS:
         ExceptionCollector.appendException(
             InvalidTemplateVersion(
                 what=version + " in " + self.import_def, valid_versions=", ".join(self.VALID_TEMPLATE_VERSIONS)
             )
         )
开发者ID:neogoku,项目名称:nfv_api,代码行数:7,代码来源:tosca_type_validation.py


示例13: _validate_interfaces

 def _validate_interfaces(self):
     ifaces = self.type_definition.get_value(self.INTERFACES,
                                             self.entity_tpl)
     if ifaces:
         for name, value in ifaces.items():
             if name in (LIFECYCLE, LIFECYCLE_SHORTNAME):
                 self._common_validate_field(
                     value, InterfacesDef.
                     interfaces_node_lifecycle_operations,
                     'interfaces')
             elif name in (CONFIGURE, CONFIGURE_SHORTNAME):
                 self._common_validate_field(
                     value, InterfacesDef.
                     interfaces_relationship_configure_operations,
                     'interfaces')
             elif name in self.type_definition.interfaces.keys():
                 self._common_validate_field(
                     value,
                     self._collect_custom_iface_operations(name),
                     'interfaces')
             else:
                 ExceptionCollector.appendException(
                     UnknownFieldError(
                         what='"interfaces" of template "%s"' %
                         self.name, field=name))
开发者ID:openstack,项目名称:tosca-parser,代码行数:25,代码来源:nodetemplate.py


示例14: _get_capability_property

 def _get_capability_property(self,
                              node_template,
                              capability_name,
                              property_name):
     """Gets a node template capability property."""
     caps = node_template.get_capabilities()
     if caps and capability_name in caps.keys():
         cap = caps[capability_name]
         property = None
         props = cap.get_properties()
         if props and property_name in props.keys():
             property = props[property_name].value
         if not property:
             ExceptionCollector.appendException(
                 KeyError(_('Property "%(prop)s" was not found in '
                            'capability "%(cap)s" of node template '
                            '"%(ntpl1)s" referenced from node template '
                            '"%(ntpl2)s".') % {'prop': property_name,
                                               'cap': capability_name,
                                               'ntpl1': node_template.name,
                                               'ntpl2': self.context.name}))
         return property
     msg = _('Requirement/Capability "{0}" referenced from node template '
             '"{1}" was not found in node template "{2}".').format(
                 capability_name,
                 self.context.name,
                 node_template.name)
     ExceptionCollector.appendException(KeyError(msg))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:28,代码来源:functions.py


示例15: _get_capability_attribute

 def _get_capability_attribute(self,
                               node_template,
                               capability_name,
                               attr_name):
     """Gets a node template capability attribute."""
     caps = node_template.get_capabilities()
     if caps and capability_name in caps.keys():
         cap = caps[capability_name]
         attribute = None
         attrs = cap.definition.get_attributes_def()
         if attrs and attr_name in attrs.keys():
             attribute = attrs[attr_name]
         if not attribute:
             ExceptionCollector.appendException(
                 KeyError(_('Attribute "%(attr)s" was not found in '
                            'capability "%(cap)s" of node template '
                            '"%(ntpl1)s" referenced from node template '
                            '"%(ntpl2)s".') % {'attr': attr_name,
                                               'cap': capability_name,
                                               'ntpl1': node_template.name,
                                               'ntpl2': self.context.name}))
         return attribute
     msg = _('Requirement/Capability "{0}" referenced from node template '
             '"{1}" was not found in node template "{2}".').format(
                 capability_name,
                 self.context.name,
                 node_template.name)
     ExceptionCollector.appendException(KeyError(msg))
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:28,代码来源:functions.py


示例16: __init__

 def __init__(self, node_type, interfacetype,
              node_template=None, name=None, value=None):
     self.ntype = node_type
     self.node_template = node_template
     self.type = interfacetype
     self.name = name
     self.value = value
     self.implementation = None
     self.inputs = None
     self.defs = {}
     if interfacetype == LIFECYCLE_SHORTNAME:
         interfacetype = LIFECYCLE
     if interfacetype == CONFIGURE_SHORTNAME:
         interfacetype = CONFIGURE
     if node_type:
         self.defs = self.TOSCA_DEF[interfacetype]
     if value:
         if isinstance(self.value, dict):
             for i, j in self.value.items():
                 if i == IMPLEMENTATION:
                     self.implementation = j
                 elif i == INPUTS:
                     self.inputs = j
                 else:
                     what = ('"interfaces" of template "%s"' %
                             self.node_template.name)
                     ExceptionCollector.appendException(
                         UnknownFieldError(what=what, field=i))
         else:
             self.implementation = value
开发者ID:MatMaul,项目名称:tosca-parser,代码行数:30,代码来源:interfaces.py


示例17: validate_additional_req

    def validate_additional_req(properties, prop_name, custom_def=None, ):
        try:
            source = properties.get(PortSpec.SOURCE)
            source_range = properties.get(PortSpec.SOURCE_RANGE)
            target = properties.get(PortSpec.TARGET)
            target_range = properties.get(PortSpec.TARGET_RANGE)

            # verify one of the specified values is set
            if source is None and source_range is None and \
                    target is None and target_range is None:
                ExceptionCollector.appendException(
                    InvalidTypeAdditionalRequirementsError(
                        type=PortSpec.TYPE_URI))
            # Validate source value is in specified range
            if source and source_range:
                validateutils.validate_value_in_range(source, source_range,
                                                      PortSpec.SOURCE)
            else:
                from toscaparser.dataentity import DataEntity
                portdef = DataEntity('PortDef', source, None, PortSpec.SOURCE)
                portdef.validate()
            # Validate target value is in specified range
            if target and target_range:
                validateutils.validate_value_in_range(target, target_range,
                                                      PortSpec.TARGET)
            else:
                from toscaparser.dataentity import DataEntity
                portdef = DataEntity('PortDef', source, None, PortSpec.TARGET)
                portdef.validate()
        except Exception:
            msg = _('"%(value)s" do not meet requirements '
                    'for type "%(type)s".') \
                % {'value': properties, 'type': PortSpec.SHORTNAME}
            ExceptionCollector.appendException(
                ValueError(msg))
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:35,代码来源:portspectype.py


示例18: _validate_keys

 def _validate_keys(self):
     """validate the keys of substitution mappings."""
     for key in self.sub_mapping_def.keys():
         if key not in self.SECTIONS:
             ExceptionCollector.appendException(
                 UnknownFieldError(what='SubstitutionMappings',
                                   field=key))
开发者ID:indigo-dc,项目名称:tosca-parser,代码行数:7,代码来源:substitution_mappings.py


示例19: _common_validate_properties

 def _common_validate_properties(self, entitytype, properties):
     allowed_props = []
     required_props = []
     for p in entitytype.get_properties_def_objects():
         allowed_props.append(p.name)
         # If property is 'required' and has no 'default' value then record
         if p.required and p.default is None:
             required_props.append(p.name)
     # validate all required properties have values
     if properties:
         req_props_no_value_or_default = []
         self._common_validate_field(properties, allowed_props,
                                     'properties')
         # make sure it's not missing any property required by a tosca type
         for r in required_props:
             if r not in properties.keys():
                 req_props_no_value_or_default.append(r)
         # Required properties found without value or a default value
         if req_props_no_value_or_default:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
                     what='"properties" of template "%s"' % self.name,
                     required=req_props_no_value_or_default))
     else:
         # Required properties in schema, but not in template
         if required_props:
             ExceptionCollector.appendException(
                 MissingRequiredFieldError(
                     what='"properties" of template "%s"' % self.name,
                     required=required_props))
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:30,代码来源:entity_template.py


示例20: _validate_capabilities_properties

    def _validate_capabilities_properties(self, capabilities):
        for cap, props in capabilities.items():
            capability = self.get_capability(cap)
            if not capability:
                continue
            capabilitydef = capability.definition
            self._common_validate_properties(capabilitydef,
                                             props[self.PROPERTIES])

            # validating capability properties values
            for prop in self.get_capability(cap).get_properties_objects():
                prop.validate()

                # TODO(srinivas_tadepalli): temporary work around to validate
                # default_instances until standardized in specification
                if cap == "scalable" and prop.name == "default_instances":
                    prop_dict = props[self.PROPERTIES]
                    min_instances = prop_dict.get("min_instances")
                    max_instances = prop_dict.get("max_instances")
                    default_instances = prop_dict.get("default_instances")
                    if not (min_instances <= default_instances
                            <= max_instances):
                        err_msg = ('"properties" of template "%s": '
                                   '"default_instances" value is not between '
                                   '"min_instances" and "max_instances".' %
                                   self.name)
                        ExceptionCollector.appendException(
                            ValidationError(message=err_msg))
开发者ID:jphilip09,项目名称:tosca-parser,代码行数:28,代码来源:entity_template.py



注:本文中的toscaparser.common.exception.ExceptionCollector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dataentity.DataEntity类代码示例发布时间:2022-05-27
下一篇:
Python paths.find_root函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap