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


Python constructor.ConstructorError方法代码示例

本文整理汇总了Python中yaml.constructor.ConstructorError方法的典型用法代码示例。如果您正苦于以下问题:Python constructor.ConstructorError方法的具体用法?Python constructor.ConstructorError怎么用?Python constructor.ConstructorError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yaml.constructor的用法示例。


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

示例1: test_unsorted

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def test_unsorted(self):
        source = SplitYamlProvider(
            'test', join(dirname(__file__), 'config/split'))

        zone = Zone('unordered.', [])

        with self.assertRaises(ConstructorError):
            source.populate(zone)

        zone = Zone('unordered.', [])

        source = SplitYamlProvider(
            'test', join(dirname(__file__), 'config/split'),
            enforce_order=False)
        # no exception
        source.populate(zone)
        self.assertEqual(2, len(zone.records)) 
开发者ID:github,项目名称:octodns,代码行数:19,代码来源:test_octodns_provider_yaml.py

示例2: test_load_duplicate_keys_top

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def test_load_duplicate_keys_top() -> None:
    from yaml.constructor import ConstructorError

    try:
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            content = """
a:
  b: 1
a:
  b: 2
"""
            fp.write(content.encode("utf-8"))
        with pytest.raises(ConstructorError):
            OmegaConf.load(fp.name)
    finally:
        os.unlink(fp.name) 
开发者ID:omry,项目名称:omegaconf,代码行数:18,代码来源:test_serialization.py

示例3: test_load_duplicate_keys_sub

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def test_load_duplicate_keys_sub() -> None:
    from yaml.constructor import ConstructorError

    try:
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            content = """
a:
  b: 1
  c: 2
  b: 3
"""
            fp.write(content.encode("utf-8"))
        with pytest.raises(ConstructorError):
            OmegaConf.load(fp.name)
    finally:
        os.unlink(fp.name) 
开发者ID:omry,项目名称:omegaconf,代码行数:18,代码来源:test_serialization.py

示例4: construct_mapping

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def construct_mapping(self, node, deep=False):
        if not isinstance(node, yaml.MappingNode):
            raise ConstructorError(None, None,
                    "expected a mapping node, but found %s" % node.id,
                    node.start_mark)
        key_set = set()
        for key_node, value_node in node.value:
            if not isinstance(key_node, yaml.ScalarNode):
                continue
            k = key_node.value
            if k in key_set:
                raise ConstructorError(
                    "while constructing a mapping", node.start_mark,
                    "found duplicate key", key_node.start_mark)
            key_set.add(k)

        return super(DuplicateKeyCheckLoader, self).construct_mapping(node, deep) 
开发者ID:cloud-custodian,项目名称:cloud-custodian,代码行数:19,代码来源:commands.py

示例5: load

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def load(self, config_path):
        """Load a CFNgin config into a context object.

        Args:
            config_path (str): Valid path to a CFNgin config file.

        Returns:
            :class:`runway.cfngin.context.Context`

        """
        LOGGER.debug('%s: loading...', os.path.basename(config_path))
        try:
            config = self._get_config(config_path)
            return self._get_context(config, config_path)
        except ConstructorError as err:
            if err.problem.startswith('could not determine a constructor '
                                      'for the tag \'!'):
                LOGGER.error('"%s" appears to be a CloudFormation template, '
                             'but is located in the top level of a module '
                             'alongside the CloudFormation config files (i.e. '
                             'the file or files indicating the stack names & '
                             'parameters). Please move the template to a '
                             'subdirectory.', config_path)
                sys.exit(1)
            raise 
开发者ID:onicagroup,项目名称:runway,代码行数:27,代码来源:cfngin.py

示例6: test_raise_constructor_error_on_keyword_duplicate_key

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def test_raise_constructor_error_on_keyword_duplicate_key(self):
        """Some keys should never have a duplicate sibling.

        For example we treat `class_path` as a special "keyword" and
        disallow dupes.

        """
        yaml_config = """
        namespace: prod
        stacks:
          - name: vpc
            class_path: blueprints.VPC
            class_path: blueprints.Fake
        """
        with self.assertRaises(ConstructorError):
            parse(yaml_config) 
开发者ID:onicagroup,项目名称:runway,代码行数:18,代码来源:test_config.py

示例7: test_raise_construct_error_on_duplicate_stack_name_dict

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def test_raise_construct_error_on_duplicate_stack_name_dict(self):
        """Some mappings should never have a duplicate children.

        For example we treat `stacks` as a special mapping and disallow
        dupe children keys.

        """
        yaml_config = """
        namespace: prod
        stacks:
          my_vpc:
            class_path: blueprints.VPC1
          my_vpc:
            class_path: blueprints.VPC2
        """
        with self.assertRaises(ConstructorError):
            parse(yaml_config) 
开发者ID:onicagroup,项目名称:runway,代码行数:19,代码来源:test_config.py

示例8: construct_mapping

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def construct_mapping(self, node, deep=False):
        if not isinstance(node, MappingNode):
            raise ConstructorError(None, None,
                    "expected a mapping node, but found %s" % node.id,
                    node.start_mark)
        mapping = {}
        for key_node, value_node in node.value:
            key = self.construct_object(key_node, deep=deep)
            try:
                hash(key)
            except TypeError as exc:
                raise ConstructorError("while constructing a mapping", node.start_mark,
                       "found unacceptable key (%s)" % exc, key_node.start_mark)
            # check for duplicate keys
            if key in mapping:
                raise ConstructorError("while constructing a mapping", node.start_mark,
                       "found duplicate key", key_node.start_mark)
            value = self.construct_object(value_node, deep=deep)
            mapping[key] = value
        return mapping 
开发者ID:StackStorm,项目名称:st2,代码行数:22,代码来源:spec_loader.py

示例9: construct_mapping

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def construct_mapping(self, node, deep=False):
        if not isinstance(node, MappingNode):
            raise ConstructorError(None, None,
                                   "expected a mapping node, but found %s" % node.id,
                                   node.start_mark)
        # UNITY: dict has to be ordered to reproduce nested maps, also save flow style
        mapping = OrderedFlowDict()
        mapping.set_flow_style(node.flow_style)
        for key_node, value_node in node.value:
            key = self.construct_object(key_node, deep=deep)
            if not isinstance(key, collections.abc.Hashable):
                raise ConstructorError("while constructing a mapping", node.start_mark,
                                       "found unhashable key", key_node.start_mark)
            value = self.construct_object(value_node, deep=deep)
            mapping[key] = value
        return mapping 
开发者ID:socialpoint-labs,项目名称:unity-yaml-parser,代码行数:18,代码来源:constructor.py

示例10: construct_mapping

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def construct_mapping(self, node, deep=False):
        """Check for duplicate YAML keys."""
        try:
            key_value_pairs = [
                (self.construct_object(key_node, deep=deep),
                 self.construct_object(value_node, deep=deep))
                for key_node, value_node in node.value]
        except TypeError as err:
            raise ConstructorError('invalid key type: %s' % err)
        mapping = {}
        for key, value in key_value_pairs:
            try:
                if key in mapping:
                    raise ConstructorError('duplicate key: %s' % key)
            except TypeError:
                raise ConstructorError('unhashable key: %s' % key)
            mapping[key] = value
        return mapping 
开发者ID:faucetsdn,项目名称:faucet,代码行数:20,代码来源:config_parser_util.py

示例11: construct_mapping

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def construct_mapping(self, node, deep=False):
        if isinstance(node, MappingNode):
            self.flatten_mapping(node)
        if not isinstance(node, MappingNode):
            raise ConstructorError(None, None,
                                   "expected a mapping node, but found %s" % node.id,
                                   node.start_mark)
        mapping = OrderedDict()
        for key_node, value_node in node.value:
            key = self.construct_object(key_node, deep=deep)
            if not isinstance(key, Hashable):
                raise ConstructorError("while constructing a mapping", node.start_mark,
                                       "found unhashable key", key_node.start_mark)
            value = self.construct_object(value_node, deep=deep)
            mapping[key] = value
        return mapping 
开发者ID:ARM-software,项目名称:workload-automation,代码行数:18,代码来源:serializer.py

示例12: testIfTableIsAMap

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def testIfTableIsAMap(self):

        from yaml.constructor import ConstructorError

        try:
            from yaml import CLoader as Loader
        except ImportError:
            from yaml import Loader

        # Credit https://gist.github.com/pypt/94d747fe5180851196eb
        def no_duplicates_constructor(loader, node, deep=False):
            """Check for duplicate keys."""

            mapping = {}
            for key_node, value_node in node.value:
                key = loader.construct_object(key_node, deep=deep)
                value = loader.construct_object(value_node, deep=deep)
                if key in mapping:
                    raise ConstructorError(
                        "while constructing a mapping", node.start_mark,
                        "found duplicate key (%s)" % key, key_node.start_mark)
                mapping[key] = value

            return loader.construct_mapping(node, deep)

        yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, no_duplicates_constructor)

        file_path = '../translationtable/GLOBAL_TERMS.yaml'
        if os.path.exists(os.path.join(os.path.dirname(__file__), file_path)):
            tt_file = open(os.path.join(os.path.dirname(__file__), file_path), 'r')
            try:
                translation_table = yaml.safe_load(tt_file)
            except yaml.constructor.ConstructorError as e:
                tt_file.close()
                self.assertTrue(False)
                print(e)
            tt_file.close() 
开发者ID:monarch-initiative,项目名称:dipper,代码行数:39,代码来源:test_trtable.py

示例13: _construct

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def _construct(self, node):
        self.flatten_mapping(node)
        ret = self.construct_pairs(node)
        keys = [d[0] for d in ret]
        keys_sorted = sorted(keys, key=_natsort_key)
        for key in keys:
            expected = keys_sorted.pop(0)
            if key != expected:
                raise ConstructorError(None, None, 'keys out of order: '
                                       'expected {} got {} at {}'
                                       .format(expected, key, node.start_mark))
        return dict(ret) 
开发者ID:github,项目名称:octodns,代码行数:14,代码来源:yaml.py

示例14: construct_mapping

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def construct_mapping(self, node, deep=False):
        if isinstance(node, MappingNode):
            self.flatten_mapping(node)
        mapping = FrozenDict()
        for key_node, value_node in node.value:
            key = self.construct_object(key_node, deep=deep)
            if not isinstance(key, Hashable):
                raise ConstructorError(
                    "while constructing a mapping", node.start_mark,
                    "found unhashable key", key_node.start_mark)
            value = self.construct_object(value_node, deep=deep)
            mapping[key] = value
        mapping.freeze()
        return mapping 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:16,代码来源:loader.py

示例15: NoDuplicatesConstructor

# 需要导入模块: from yaml import constructor [as 别名]
# 或者: from yaml.constructor import ConstructorError [as 别名]
def NoDuplicatesConstructor(loader, node, deep=False):
  """Check for duplicate keys."""
  mapping = {}
  for key_node, value_node in node.value:
    key = loader.construct_object(key_node, deep=deep)
    value = loader.construct_object(value_node, deep=deep)
    if key in mapping:
      raise ConstructorError('while constructing a mapping', node.start_mark,
                             'found duplicate key (%s)' % key,
                             key_node.start_mark)
    mapping[key] = value
  return loader.construct_mapping(node, deep) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:14,代码来源:util.py


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