當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。