當前位置: 首頁>>代碼示例>>Python>>正文


Python schema.Optional方法代碼示例

本文整理匯總了Python中schema.Optional方法的典型用法代碼示例。如果您正苦於以下問題:Python schema.Optional方法的具體用法?Python schema.Optional怎麽用?Python schema.Optional使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在schema的用法示例。


在下文中一共展示了schema.Optional方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def load(manifest_path: Path) -> Manifest:
    remote_git_server_schema = {"url": str}
    repo_schema = schema.Use(validate_repo)
    group_schema = {"repos": [str], schema.Optional("includes"): [str]}
    # Note: gitlab and github_enterprise_url keys are ignored,
    # and kept here only for backward compatibility reasons
    manifest_schema = schema.Schema(
        {
            "repos": [repo_schema],
            schema.Optional("gitlab"): remote_git_server_schema,
            schema.Optional("github_enterprise"): remote_git_server_schema,
            schema.Optional("groups"): {str: group_schema},
        }
    )
    parsed = tsrc.parse_config(manifest_path, manifest_schema)
    res = Manifest()
    res.apply_config(parsed)
    return res 
開發者ID:TankerHQ,項目名稱:tsrc,代碼行數:20,代碼來源:manifest.py

示例2: _format_tyre_dimensions

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def _format_tyre_dimensions(tyre_dimensions):
    import schema
    frt = schema.Schema({
        schema.Optional('additional_marks'): schema.Use(str),
        schema.Optional('aspect_ratio'): schema.Use(float),
        schema.Optional('carcass'): schema.Use(str),
        'rim_diameter': schema.Use(float),
        schema.Optional('diameter'): schema.Use(float),
        schema.Optional('load_index'): schema.Use(str),
        schema.Optional('load_range'): schema.Use(str),
        'nominal_section_width': schema.Use(float),
        schema.Optional('speed_rating'): schema.Use(str),
        schema.Optional('use'): schema.Use(str),
        schema.Optional('code'): schema.Use(str),
    })
    m = {k: v for k, v in tyre_dimensions.items() if v is not None}
    return frt.validate(m) 
開發者ID:JRCSTU,項目名稱:CO2MPAS-TA,代碼行數:19,代碼來源:wheels.py

示例3: __init__

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def __init__(self):
        self.__validTypes = schema.Schema({'backend': schema.Or('none', 'file', 'http', 'shell', 'azure')},
            ignore_extra_keys=True)
        baseArchive = {
            'backend' : str,
            schema.Optional('flags') : schema.Schema(["download", "upload",
                "nofail", "nolocal", "nojenkins"])
        }
        fileArchive = baseArchive.copy()
        fileArchive["path"] = str
        fileArchive[schema.Optional("fileMode")] = int
        fileArchive[schema.Optional("directoryMode")] = int
        httpArchive = baseArchive.copy()
        httpArchive["url"] = str
        httpArchive[schema.Optional("sslVerify")] = bool
        shellArchive = baseArchive.copy()
        shellArchive.update({
            schema.Optional('download') : str,
            schema.Optional('upload') : str,
        })
        azureArchive = baseArchive.copy()
        azureArchive.update({
            'account' : str,
            'container' : str,
            schema.Optional('key') : str,
            schema.Optional('sasToken"') : str,
        })
        self.__backends = {
            'none' : schema.Schema(baseArchive),
            'file' : schema.Schema(fileArchive),
            'http' : schema.Schema(httpArchive),
            'shell' : schema.Schema(shellArchive),
            'azure' : schema.Schema(azureArchive),
        } 
開發者ID:BobBuildTool,項目名稱:bob,代碼行數:36,代碼來源:input.py

示例4: __init__

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def __init__(self, algo_type):
        """
        Parameters:
        -----------
        algo_type: str
            One of ['tuner', 'assessor', 'advisor'].
            'tuner': This AlgoSchema class create the schema of tuner section.
            'assessor': This AlgoSchema class create the schema of assessor section.
            'advisor': This AlgoSchema class create the schema of advisor section.
        """
        assert algo_type in ['tuner', 'assessor', 'advisor']
        self.algo_type = algo_type
        self.algo_schema = {
            Optional('codeDir'): setPathCheck('codeDir'),
            Optional('classFileName'): setType('classFileName', str),
            Optional('className'): setType('className', str),
            Optional('classArgs'): dict,
            Optional('includeIntermediateResults'): setType('includeIntermediateResults', bool),
            Optional('gpuIndices'): Or(int, And(str, lambda x: len([int(i) for i in x.split(',')]) > 0), error='gpuIndex format error!'),
        }
        self.builtin_keys = {
            'tuner': 'builtinTunerName',
            'assessor': 'builtinAssessorName',
            'advisor': 'builtinAdvisorName'
        }
        self.builtin_name_schema = {}
        for k, n in self.builtin_keys.items():
            self.builtin_name_schema[k] = {Optional(n): setChoice(n, *get_all_builtin_names(k+'s'))}

        self.customized_keys = set(['codeDir', 'classFileName', 'className']) 
開發者ID:microsoft,項目名稱:nni,代碼行數:32,代碼來源:config_schema.py

示例5: __init__

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def __init__(self) -> None:
        self._repos = []  # type: List[tsrc.Repo]
        self.group_list = None  # type:  Optional[tsrc.GroupList[str]] 
開發者ID:TankerHQ,項目名稱:tsrc,代碼行數:5,代碼來源:manifest.py

示例6: get_repos

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def get_repos(
        self, groups: Optional[List[str]] = None, all_: bool = False
    ) -> List[tsrc.Repo]:
        if all_:
            return self._repos

        if not groups:
            if self._has_default_group():
                return self._get_repos_in_groups(["default"])
            else:
                return self._repos

        return self._get_repos_in_groups(groups) 
開發者ID:TankerHQ,項目名稱:tsrc,代碼行數:15,代碼來源:manifest.py

示例7: validate_repo

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def validate_repo(data: Any) -> None:
    copy_schema = {"file": str, schema.Optional("dest"): str}
    symlink_schema = {"source": str, "target": str}
    remote_schema = {"name": str, "url": str}
    repo_schema = schema.Schema(
        {
            "dest": str,
            schema.Optional("branch"): str,
            schema.Optional("copy"): [copy_schema],
            schema.Optional("symlink"): [symlink_schema],
            schema.Optional("sha1"): str,
            schema.Optional("tag"): str,
            schema.Optional("remotes"): [remote_schema],
            schema.Optional("url"): str,
        }
    )
    repo_schema.validate(data)
    url = data.get("url")
    remotes = data.get("remotes")
    if url and remotes:
        raise schema.SchemaError(
            "Repo config cannot contain both an url and a list of remotes"
        )
    if not url and not remotes:
        raise schema.SchemaError(
            "Repo config should contain either a url or a non-empty list of remotes"
        ) 
開發者ID:TankerHQ,項目名稱:tsrc,代碼行數:29,代碼來源:manifest.py

示例8: validate_check_config

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def validate_check_config(check_config):

    class PrettyReprAnd(schema.And):

        def __repr__(self):
            return self._error

    check_name = PrettyReprAnd(
        str,
        lambda val: len(val) > 0,
        lambda val: not any(w in val for w in string.whitespace),
        error='Check name must be a nonzero length string with no whitespace')

    timeout_units = ['ns', 'us', 'µs', 'ms', 's', 'm', 'h']
    timeout = schema.Regex(
        r'^\d+(\.\d+)?({})$'.format('|'.join(timeout_units)),
        error='Timeout must be a string containing an integer or float followed by a unit: {}'.format(
            ', '.join(timeout_units)))

    check_config_schema = schema.Schema({
        schema.Optional('cluster_checks'): {
            check_name: {
                'description': str,
                'cmd': [str],
                'timeout': timeout,
            },
        },
        schema.Optional('node_checks'): {
            'checks': {
                check_name: {
                    'description': str,
                    'cmd': [str],
                    'timeout': timeout,
                    schema.Optional('roles'): schema.Schema(
                        ['master', 'agent'],
                        error='roles must be a list containing master or agent or both',
                    ),
                },
            },
            schema.Optional('prestart'): [check_name],
            schema.Optional('poststart'): [check_name],
        },
    })

    check_config_obj = validate_json_dictionary(check_config)
    try:
        check_config_schema.validate(check_config_obj)
    except schema.SchemaError as exc:
        raise AssertionError(str(exc).replace('\n', ' ')) from exc

    if 'node_checks' in check_config_obj.keys():
        node_checks = check_config_obj['node_checks']
        assert any(k in node_checks.keys() for k in ['prestart', 'poststart']), (
            'At least one of prestart or poststart must be defined in node_checks')
        assert node_checks['checks'].keys() == set(
            node_checks.get('prestart', []) + node_checks.get('poststart', [])), (
            'All node checks must be referenced in either prestart or poststart, or both')

    return check_config_obj 
開發者ID:dcos,項目名稱:dcos,代碼行數:61,代碼來源:calc.py

示例9: define_flags_schema

# 需要導入模塊: import schema [as 別名]
# 或者: from schema import Optional [as 別名]
def define_flags_schema(read=True):
    """
    Define flag schema.

    :param read:
        Schema for reading?
    :type read: bool

    :return:
        Flag schema.
    :rtype: schema.Schema
    """
    string = _string(read=read)
    isfile = _file(read=read)
    isdir = _dir(read=read)
    _bool = _type(type=bool, read=read)

    schema = {
        _compare_str('input_version'): _input_version(read=read),
        _compare_str('model_conf'): isfile,
        _compare_str('encryption_keys'): string,
        _compare_str('encryption_keys_passwords'): string,
        _compare_str('sign_key'): string,

        _compare_str('hard_validation'): _bool,
        _compare_str('enable_selector'): _bool,
        _compare_str('declaration_mode'): _bool,
        _compare_str('only_summary'): _bool,
        _compare_str('augmented_summary'): _bool,
        _compare_str('type_approval_mode'): _bool,

        _compare_str('output_template'): isfile,
        _compare_str('output_folder'): isdir,
    }

    schema = {Optional(k): Or(Empty(), v) for k, v in schema.items()}

    if not read:
        def _f(x):
            return x is sh.NONE

        schema = {k: And(v, Or(_f, Use(str))) for k, v in schema.items()}

    return Schema(schema) 
開發者ID:JRCSTU,項目名稱:CO2MPAS-TA,代碼行數:46,代碼來源:schema.py


注:本文中的schema.Optional方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。