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