本文整理汇总了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
示例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)
示例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),
}
示例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'])
示例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]]
示例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)
示例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"
)
示例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
示例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)