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


Python yaml.safe_load方法代码示例

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


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

示例1: __init__

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def __init__(self, data_path, imageset = 'train', return_ref = False):
        self.return_ref = return_ref
        with open("semantic-kitti.yaml", 'r') as stream:
            semkittiyaml = yaml.safe_load(stream)
        self.learning_map = semkittiyaml['learning_map']
        self.imageset = imageset
        if imageset == 'train':
            split = semkittiyaml['split']['train']
        elif imageset == 'val':
            split = semkittiyaml['split']['valid']
        elif imageset == 'test':
            split = semkittiyaml['split']['test']
        else:
            raise Exception('Split must be train/val/test')
        
        self.im_idx = []
        for i_folder in split:
            self.im_idx += absoluteFilePaths('/'.join([data_path,str(i_folder).zfill(2),'velodyne'])) 
开发者ID:edwardzhou130,项目名称:PolarSeg,代码行数:20,代码来源:dataset.py

示例2: get_plugin_config

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def get_plugin_config(config_uri):
    """
    Downloads/opens configuration yaml file, returns
    dict of Galaxy plugins
    """
    # Try to open the URI as a URL or fall back to opening local file
    try:
        config_uri_parsed = urlparse(config_uri)
        if config_uri_parsed.scheme in ['https', 'http']:
            url = urlopen(config_uri)
            yaml_data = url.read()
        else:
            with open(config_uri, 'r') as file_data:
                yaml_data = file_data.read()
    except URLError as e:
        print(e)

    # Parse the YAML configuration
    try:
        plugin_data = yaml.safe_load(yaml_data)

        return plugin_data['plugins']
    except yaml.YAMLError as e:
        print(e) 
开发者ID:Slashbunny,项目名称:gog-galaxy-plugin-downloader,代码行数:26,代码来源:download.py

示例3: _parse_package_list

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def _parse_package_list(self, data):
        """Parse data expecting a list of packages to install.

        Expect data to be a bytearray reprsenting a JSON or YAML
        document.

        :param data: A bytearray of data to parse
        """
        try:
            data_string = data.decode('utf-8')
            parsed_data = yaml.safe_load(data_string)

            if isinstance(parsed_data, dict):
                self.package_list = self._extract_package_list(parsed_data)
            else:
                raise errors.InvalidPackageListFormat(
                    "Package data should have a top-level mapping/object.")
        except yaml.YAMLError as ex:
            raise errors.InvalidPackageListFormat(
                "Invalid YAML in package list: %s" % str(ex)) 
开发者ID:airshipit,项目名称:drydock,代码行数:22,代码来源:bootaction.py

示例4: _test_validate

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def _test_validate(self, schema, expect_failure, input_files, input):
        """validates input yaml against schema.

        :param schema: schema yaml file
        :param expect_failure: should the validation pass or fail.
        :param input_files: pytest fixture used to access the test input files
        :param input: test input yaml doc filename"""
        schema_dir = pkg_resources.resource_filename('drydock_provisioner',
                                                     'schemas')
        schema_filename = os.path.join(schema_dir, schema)
        schema_file = open(schema_filename, 'r')
        schema = yaml.safe_load(schema_file)

        input_file = input_files.join(input)
        instance_file = open(str(input_file), 'r')
        instance = yaml.safe_load(instance_file)

        if expect_failure:
            with pytest.raises(ValidationError):
                jsonschema.validate(instance['spec'], schema['data'])
        else:
            jsonschema.validate(instance['spec'], schema['data']) 
开发者ID:airshipit,项目名称:drydock,代码行数:24,代码来源:test_schema_validation.py

示例5: _wait_for_status

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def _wait_for_status(self, batch_id, wait, result):
        '''Wait until transaction status is not PENDING (COMMITTED or error).

           'wait' is time to wait for status, in seconds.
        '''
        if wait and wait > 0:
            waited = 0
            start_time = time.time()
            while waited < wait:
                result = self._send_to_rest_api("batch_statuses?id={}&wait={}"
                                               .format(batch_id, wait))
                status = yaml.safe_load(result)['data'][0]['status']
                waited = time.time() - start_time

                if status != 'PENDING':
                    return result
            return "Transaction timed out after waiting {} seconds." \
               .format(wait)
        else:
            return result 
开发者ID:danintel,项目名称:sawtooth-cookiejar,代码行数:22,代码来源:cookiejar_client.py

示例6: load_profiles

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def load_profiles():
    """
    Load in all the profiles from the profile folder (file-per-profile)
    """
    profiles_raw = {}
    profiles_dir = os.path.dirname(__file__) + "/../data/profile/"
    for profile_fn in os.listdir(profiles_dir):
        if not profile_fn[-3:] == 'yml':
            continue

        profile_dict = yaml.safe_load(open(profiles_dir + profile_fn).read())
        # One item per file
        assert len(profile_dict) == 1, "{}: expected one entry, got {}" \
        .format(profile_fn, len(profile_dict))
        # Item must match filename
        profile_name, profile_val = profile_dict.popitem()
        assert profile_name + ".yml" == profile_fn, \
                "{}: Expected to find profile named the same as file, got {}" \
                .format(profile_fn, profile_name)
        profiles_raw[profile_name] = profile_val
    return profiles_raw 
开发者ID:receipt-print-hq,项目名称:escpos-printer-db,代码行数:23,代码来源:collate.py

示例7: reconfigure

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def reconfigure(ctx):
    """
    Reconfigure the chute without rebuilding.
    """
    url = ctx.obj['chute_url'] + "/config"

    if not os.path.exists("paradrop.yaml"):
        raise Exception("No paradrop.yaml file found in working directory.")

    with open("paradrop.yaml", "r") as source:
        data = yaml.safe_load(source)
        config = data.get('config', {})

    res = router_request("PUT", url, json=config)
    data = res.json()
    ctx.invoke(watch, change_id=data['change_id']) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:18,代码来源:device.py

示例8: create_version

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def create_version(ctx):
    """
    Push a new version of the chute to the store.
    """
    if not os.path.exists("paradrop.yaml"):
        raise Exception("No paradrop.yaml file found in working directory.")

    with open('paradrop.yaml', 'r') as source:
        chute = yaml.safe_load(source)

    name = chute_find_field(chute, 'name')
    source = chute_find_field(chute, 'source')
    config = chute.get('config', {})

    chute_resolve_source(source, config)

    client = ControllerClient()
    result = client.find_chute(name)
    if result is None:
        raise Exception("Could not find ID for chute {} - is it registered?".format(name))

    result = client.create_version(name, config)
    click.echo(util.format_result(result))
    return result 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:26,代码来源:store.py

示例9: get_folder_semver

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def get_folder_semver(folder_path: str):
    for item in os.listdir(folder_path):
        item_path = os.path.join(folder_path, item)
        if not os.path.isfile(item_path) or not is_yaml_file(item_path):
            continue

        with open(item_path, 'r') as f:
            file_content = f.read()

        if identify.get_operator_artifact_type(file_content) == 'ClusterServiceVersion':
            try:
                csv_version = safe_load(file_content)['spec']['version']
            except MarkedYAMLError:
                msg = f'{item} is not a valid YAML file.'
                logger.error(msg)
                raise OpCourierBadYaml(msg)
            except KeyError:
                msg = f'{item} is not a valid CSV file as "spec.version" ' \
                      f'field is required'
                logger.error(msg)
                raise OpCourierBadBundle(msg, {})
            return csv_version

    return None 
开发者ID:operator-framework,项目名称:operator-courier,代码行数:26,代码来源:flatten.py

示例10: get_operator_artifact_type

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def get_operator_artifact_type(operatorArtifactString):
    """get_operator_artifact_type takes a yaml string and determines if it is
    one of the expected bundle types.

    :param operatorArtifactString: Yaml string to type check
    """

    # Default to unknown file unless identified
    artifact_type = UNKNOWN_FILE

    try:
        operatorArtifact = safe_load(operatorArtifactString)
    except MarkedYAMLError:
        msg = "Courier requires valid input YAML files"
        logger.error(msg)
        raise OpCourierBadYaml(msg)
    else:
        if isinstance(operatorArtifact, dict):
            if "packageName" in operatorArtifact:
                artifact_type = PKG_STR
            elif operatorArtifact.get("kind") in {CRD_STR, CSV_STR}:
                artifact_type = operatorArtifact["kind"]
        return artifact_type 
开发者ID:operator-framework,项目名称:operator-courier,代码行数:25,代码来源:identify.py

示例11: _YamlReader

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def _YamlReader(path: Text) -> Text:
  """Read a configuration file and return the contents.

  Can be overloaded to read configs from different sources.

  Args:
    path: The config file name (eg build.yaml).

  Returns:
    The parsed content of the yaml file.
  """
  try:
    with open(path, 'r') as yaml_file:
      yaml_config = yaml.safe_load(yaml_file)
  except IOError as e:
    raise Error('Could not read yaml file %s: %s' % (path, str(e)))
  return yaml_config 
开发者ID:google,项目名称:glazier,代码行数:19,代码来源:files.py

示例12: testReleasePath

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def testReleasePath(self, comp_os, read):
    read.return_value = yaml.safe_load(_VERSION_INFO)
    comp_os.return_value = 'windows-7-stable'
    expected = 'https://glazier-server.example.com/stable/'
    self.assertEqual(self.buildinfo.ReleasePath(), expected)
    self.buildinfo.ComputerOs.cache_clear()
    comp_os.return_value = 'windows-10-unstable'
    expected = 'https://glazier-server.example.com/unstable/'
    self.assertEqual(self.buildinfo.ReleasePath(), expected)
    self.buildinfo.ComputerOs.cache_clear()
    # no os
    comp_os.return_value = None
    self.assertRaises(buildinfo.Error, self.buildinfo.ReleasePath)
    self.buildinfo.ComputerOs.cache_clear()
    # invalid os
    comp_os.return_value = 'invalid-os-string'
    self.assertRaises(buildinfo.Error, self.buildinfo.ReleasePath) 
开发者ID:google,项目名称:glazier,代码行数:19,代码来源:buildinfo_test.py

示例13: testSerialize

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def testSerialize(self):
    mock_b = mock.Mock(spec_set=self.buildinfo)
    mock_b._chooser_responses = {
        'USER_choice_one': 'value1',
        'USER_choice_two': 'value2'
    }
    mock_b._timers.GetAll.return_value = {
        'timer_1': datetime.datetime.utcnow()
    }
    mock_b.Serialize = buildinfo.BuildInfo.Serialize.__get__(mock_b)
    mock_b.Serialize('/build_info.yaml')
    parsed = yaml.safe_load(buildinfo.open('/build_info.yaml'))
    self.assertIn('branch', parsed['BUILD'])
    self.assertIn('Model', parsed['BUILD'])
    self.assertIn('SerialNumber', parsed['BUILD'])
    self.assertIn('USER_choice_two', parsed['BUILD'])
    self.assertIn('TIMER_timer_1', parsed['BUILD'])
    self.assertEqual(parsed['BUILD']['USER_choice_two'], 'value2') 
开发者ID:google,项目名称:glazier,代码行数:20,代码来源:buildinfo_test.py

示例14: extract_yaml

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def extract_yaml(yaml_files):
    """
    Take a list of yaml_files and load them to return back
    to the testing program
    """
    loaded_yaml = []
    for yaml_file in yaml_files:
        try:
            with io.open(yaml_file, encoding='utf-8') as fd:
                loaded_yaml.append(yaml.safe_load(fd))
        except IOError as e:
            print('Error reading file', yaml_file)
            raise e
        except yaml.YAMLError as e:
            print('Error parsing file', yaml_file)
            raise e
        except Exception as e:
            print('General error')
            raise e
    return loaded_yaml 
开发者ID:CRS-support,项目名称:ftw,代码行数:22,代码来源:util.py

示例15: test_write

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import safe_load [as 别名]
def test_write(self):
    expected_dict = {
        'project_id': 'test_project',
        'client_id': 'test_client_id',
        'client_secret': 'test_client_secret',
        'bucket': 'test_project.appspot.com',
    }
    self.fs.CreateFile('/this/config/file.yaml', contents=_EMPTY_CONFIG)
    test_config = common.ProjectConfig(
        'asdf', 'test_project', 'test_client_id', 'test_client_secret', None,
        '/this/config/file.yaml',
    )
    test_config.write()
    with open('/this/config/file.yaml') as config_file:
      config = yaml.safe_load(config_file)
    self.assertEqual(config['asdf'], expected_dict) 
开发者ID:google,项目名称:loaner,代码行数:18,代码来源:common_test.py


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