当前位置: 首页>>代码示例>>Python>>正文


Python gettextutils._函数代码示例

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


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

示例1: properties

 def properties(self):
     props = []
     properties = self.node_type.get_value(PROPERTIES, self.node_template)
     requiredprop = []
     for p in self.node_type.properties_def:
         if p.required:
             requiredprop.append(p.name)
     if properties:
         #make sure it's not missing any property required by a node type
         missingprop = []
         for r in requiredprop:
             if r not in properties.keys():
                 missingprop.append(r)
         if missingprop:
             raise ValueError(_("Node template %(tpl)s is missing "
                                "one or more required properties %(prop)s")
                              % {'tpl': self.name, 'prop': missingprop})
         for name, value in properties.items():
             for p in self.node_type.properties_def:
                 if p.name == name:
                     prop = Property(name, value, p.schema)
                     props.append(prop)
     else:
         if requiredprop:
             raise ValueError(_("Node template %(tpl)s is missing"
                                "one or more required properties %(prop)s")
                              % {'tpl': self.name, 'prop': requiredprop})
     return props
开发者ID:s-mukai,项目名称:heat-translator,代码行数:28,代码来源:nodetemplate.py

示例2: _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:
             raise KeyError(_(
                 "Property '{0}' not found in capability '{1}' of node"
                 " template '{2}' referenced from node template"
                 " '{3}'.").format(property_name,
                                   capability_name,
                                   node_template.name,
                                   self.context.name))
         return property
     msg = _("Requirement/Capability '{0}' referenced from '{1}' node "
             "template not found in '{2}' node template.").format(
                 capability_name,
                 self.context.name,
                 node_template.name)
     raise KeyError(msg)
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:27,代码来源:functions.py

示例3: __init__

    def __init__(self, property_name, property_type, constraint):
        super(InRange, self).__init__(property_name, property_type, constraint)
        if not isinstance(self.constraint_value, collections.Sequence) or (len(constraint[self.IN_RANGE]) != 2):
            raise InvalidSchemaError(message=_("in_range must be a list."))

        for value in self.constraint_value:
            if not isinstance(value, self.valid_types):
                raise InvalidSchemaError(_("in_range value must " "be comparable."))

        self.min = self.constraint_value[0]
        self.max = self.constraint_value[1]
开发者ID:ckauf,项目名称:heat-translator,代码行数:11,代码来源:constraints.py

示例4: validate_scalar_unit

 def validate_scalar_unit(self):
     regex = re.compile('([0-9.]+)\s*(\w+)')
     try:
         result = regex.match(str(self.value)).groups()
         validateutils.str_to_num(result[0])
     except Exception:
         raise ValueError(_('"%s" is not a valid scalar-unit')
                          % self.value)
     if result[1].upper() in self.SCALAR_UNIT_DICT.keys():
         return self.value
     raise ValueError(_('"%s" is not a valid scalar-unit') % self.value)
开发者ID:micafer,项目名称:heat-translator,代码行数:11,代码来源:scalarunit.py

示例5: __new__

    def __new__(cls, property_name, property_type, constraint):
        if cls is not Constraint:
            return super(Constraint, cls).__new__(cls)

        if not isinstance(constraint, collections.Mapping) or len(constraint) != 1:
            raise InvalidSchemaError(message=_("Invalid constraint schema."))

        for type in constraint.keys():
            ConstraintClass = get_constraint_class(type)
            if not ConstraintClass:
                msg = _('Invalid constraint type "%s".') % type
                raise InvalidSchemaError(message=msg)

        return ConstraintClass(property_name, property_type, constraint)
开发者ID:ckauf,项目名称:heat-translator,代码行数:14,代码来源:constraints.py

示例6: get_scalarunit_value

def get_scalarunit_value(type, value, unit=None):
    if type in ScalarUnit.SCALAR_UNIT_TYPES:
        ScalarUnit_Class = get_scalarunit_class(type)
        return (ScalarUnit_Class(value).
                get_num_from_scalar_unit(unit))
    else:
        raise TypeError(_('"%s" is not a valid scalar-unit type') % type)
开发者ID:micafer,项目名称:heat-translator,代码行数:7,代码来源:scalarunit.py

示例7: _err_msg

 def _err_msg(self, value):
     allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value)
     return (_('%(pname)s: %(pvalue)s is not an valid '
               'value "%(cvalue)s".') %
             dict(pname=self.property_name,
                  pvalue=value,
                  cvalue=allowed))
开发者ID:micafer,项目名称:heat-translator,代码行数:7,代码来源:constraints.py

示例8: _translate_inputs

    def _translate_inputs(self):
        hot_inputs = []
        hot_default = None
        for input in self.inputs:
            hot_input_type = TOSCA_TO_HOT_INPUT_TYPES[input.type]

            if input.name in self.parsed_params:
                DataEntity.validate_datatype(hot_input_type,
                                             self.parsed_params[input.name])
                hot_default = self.parsed_params[input.name]
            elif input.default is not None:
                hot_default = input.default
            else:
                raise Exception(_("Need to specify a value "
                                  "for input {0}").format(input.name))
            hot_constraints = []
            if input.constraints:
                for constraint in input.constraints:
                    constraint.validate(
                        int(hot_default) if hot_input_type == "number"
                        else hot_default)
                    hc, hvalue = self._translate_constraints(
                        constraint.constraint_key, constraint.constraint_value)
                    hot_constraints.append({hc: hvalue})

            hot_inputs.append(HotParameter(name=input.name,
                                           type=hot_input_type,
                                           description=input.description,
                                           default=hot_default,
                                           constraints=hot_constraints))
        return hot_inputs
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:31,代码来源:translate_inputs.py

示例9: _err_msg

 def _err_msg(self, value):
     return _("%(pname)s: %(pvalue)s is out of range " "(min:%(vmin)s, max:%(vmax)s).") % dict(
         pname=self.property_name,
         pvalue=self.value_msg,
         vmin=self.constraint_value_msg[0],
         vmax=self.constraint_value_msg[1],
     )
开发者ID:ckauf,项目名称:heat-translator,代码行数:7,代码来源:constraints.py

示例10: validate

 def validate(self):
     if len(self.args) < 2 or len(self.args) > 3:
         raise ValueError(_(
             'Expected arguments: [node-template-name, req-or-cap '
             '(optional), property name.'))
     if len(self.args) == 2:
         prop = self._find_property(self.args[1]).value
         if not isinstance(prop, Function):
             get_function(self.tosca_tpl, self.context, prop)
     elif len(self.args) == 3:
         get_function(self.tosca_tpl,
                      self.context,
                      self._find_req_or_cap_property(self.args[1],
                                                     self.args[2]))
     else:
         raise NotImplementedError(_(
             'Nested properties are not supported.'))
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:17,代码来源:functions.py

示例11: _find_node_template

 def _find_node_template(self, node_template_name):
     if node_template_name == SELF:
         return self.context
     for node_template in self.tosca_tpl.nodetemplates:
         if node_template.name == node_template_name:
             return node_template
     raise KeyError(_(
         'No such node template: {0}.').format(node_template_name))
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:8,代码来源:functions.py

示例12: __init__

 def __init__(self, ntype):
     super(NodeType, self).__init__()
     if ntype not in list(self.TOSCA_DEF.keys()):
         raise ValueError(_('Node type %(ntype)s is not a valid type.')
                          % {'ntype': ntype})
     self.defs = self.TOSCA_DEF[ntype]
     self.type = ntype
     self.related = {}
开发者ID:s-mukai,项目名称:heat-translator,代码行数:8,代码来源:nodetype.py

示例13: _find_property

 def _find_property(self, property_name):
     node_tpl = self._find_node_template(self.args[0])
     props = node_tpl.get_properties()
     found = [props[property_name]] if property_name in props else []
     if len(found) == 0:
         raise KeyError(_(
             "Property: '{0}' not found in node template: {1}.").format(
                 property_name, node_tpl.name))
     return found[0]
开发者ID:jiangyaoguo,项目名称:heat-translator,代码行数:9,代码来源:functions.py

示例14: validate_boolean

    def validate_boolean(value):
        if isinstance(value, bool):
            return value

        if isinstance(value, str):
            normalised = value.lower()
            if normalised in ["true", "false"]:
                return normalised == "true"
        raise ValueError(_('"%s" is not a boolean') % value)
开发者ID:ckauf,项目名称:heat-translator,代码行数:9,代码来源:constraints.py

示例15: __init__

    def __init__(self, **kwargs):
        try:
            self.message = self.msg_fmt % kwargs
        except KeyError:
            exc_info = sys.exc_info()
            log.exception(_('Exception in string format operation: %s')
                          % exc_info[1])

            if TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS:
                raise exc_info[0]
开发者ID:hurf,项目名称:heat-translator,代码行数:10,代码来源:exception.py


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