def validate_hex_string(ctx, param, value):
"""
Ensure that a value is valid hex
:param ctx:<class 'click.core.Context'>
:param param:<class 'click.core.Option'>
:param value:str
:return:str
"""
try:
int(value, 16)
except ValueError:
raise click.BadParameter('\'{}\' is not a valid hex string.'.format(value))
return value
python类BadParameter()的实例源码
def validate_options(ctx, param, value):
possible_values = ['verbose', 'host']
if value and value not in possible_values:
raise click.BadParameter(
"Value `{}` is not supported, must one of the value {}".format(value, possible_values))
return value
def _validate_global_params(ctx, *params):
for param in params:
if ctx.obj[param] is None:
raise click.BadParameter(str(ctx.obj[param]), param_hint=param)
def _validate_project_image(image):
project_images = utils.get_images_from_dockerfiles()
if image not in project_images:
raise click.BadParameter("'%s' is not an image of this project, try %s" % (image, project_images), param_hint='image')
def test_subcommand_without_global_params(self):
subcmd_params_map = {
'push': [IMAGE],
'run': ['ls' '-l'],
'make': ['-f', 'Makefile', 'all'],
}
for subcmd, subcmd_params in six.iteritems(subcmd_params_map):
result = self._invoke_cli(
global_params=None,
subcmd=subcmd,
subcmd_params=subcmd_params,
)
self.assertIsInstance(result.exception, click.BadParameter)
self.assertEqual(result.exit_code, -1)
def test_validate_project_image(self):
result = self._invoke_cli(
global_params=self.global_params,
subcmd='rmi',
subcmd_params=['-r', 'non-project-image', TAG]
)
self.assertIsInstance(result.exception, click.BadParameter)
makeShorterClassII.py 文件源码
项目:icing
作者: NationalGenomicsInfrastructure
项目源码
文件源码
阅读 52
收藏 0
点赞 0
评论 0
def validate_locus(ctx,param,value):
try:
assert value in ["HLA-DMA", "HLA-DMB", "HLA-DOA", "HLA-DOB", "HLA-DPA1", "HLA-DPB1", "HLA-DPB2", "HLA-DQA1", "HLA-DQB1", "HLA-DRA", "HLA-DRB1", "HLA-DRB2", "HLA-DRB3", "HLA-DRB4", "HLA-DRB5", "HLA-DRB6", "HLA-DRB7", "HLA-DRB8", "HLA-DRB9", "HLA-E", "HLA-F", "HLA-G", "HLA-H", "HLA-HFE", "HLA-J", "HLA-K", "HLA-L", "HLA-P", "HLA-V", "HLA-Y"]
except:
raise click.BadParameter('Please define locus as HLA-A, HLA-B, HLA-DRB1 ... as you can find in awk -F[\*\ ] \'/^DE/ && /HLA/ {print $4}\' hla.dat|sort -u')
return value
def validate_locus(ctx,param,value):
try:
assert value in ["HLA-A","HLA-B", "HLA-C", "HLA-DPA1", "HLA-DPB1", "HLA-DQA1", "HLA-DQB1", "HLA-DRA", "HLA-DRB1", "HLA-DRB3", "HLA-DRB4", "HLA-DRB5", "HLA-DRB6", "HLA-DRB7", "HLA-DRB8", "HLA-DRB9"]
except:
raise click.BadParameter('Please define locus as HLA-A, HLA-B, HLA-DRB1 ... as you can find in awk -F[\*\ ] \'/^DE/ && /HLA/ {print $4}\' hla.dat|sort -u')
return value
def validate_locus(ctx,param,value):
try:
assert value in ["HLA-A","HLA-B", "HLA-C", "HLA-DMA", "HLA-DMB", "HLA-DOA", "HLA-DOB", "HLA-DPA1", "HLA-DPB1", "HLA-DPB2", "HLA-DQA1", "HLA-DQB1", "HLA-DRA", "HLA-DRB1", "HLA-DRB2", "HLA-DRB3", "HLA-DRB4", "HLA-DRB5", "HLA-DRB6", "HLA-DRB7", "HLA-DRB8", "HLA-DRB9", "HLA-E", "HLA-F", "HLA-G", "HLA-H", "HLA-HFE", "HLA-J", "HLA-K", "HLA-L", "HLA-P", "HLA-V", "HLA-Y"]
except:
raise click.BadParameter('Please define locus as HLA-A, HLA-B, HLA-DRB1 ... as you can find in awk -F[\*\ ] \'/^DE/ && /HLA/ {print $4}\' hla.dat|sort -u')
return value
def test_get_credentials(self):
assert get_credentials(insecure=True) == (None, None)
assert get_credentials(apikey='apikey') == ('apikey', ' ')
assert get_credentials(
username='user', password='pass') == ('user', 'pass')
with pytest.raises(click.BadParameter):
get_credentials(username='user')
assert get_credentials(target_apikey='tapikey') == ('tapikey', ' ')
def run_python(interpreter, imported_objects):
for name, _run_python in interpreters.items():
if interpreter == name:
_run_python(imported_objects)
else:
click.BadParameter('Please select from ' + ', '.join(interpreters.keys()))
def validate_taxdump(value, method):
if (os.path.isfile("%s/%s" % (value, "names.dmp")) and
os.path.isfile("%s/%s" % (value, "nodes.dmp")) and
os.path.isfile("%s/%s" % (value, "merged.dmp")) and
os.path.isfile("%s/%s" % (value, "delnodes.dmp"))):
return value
else:
with click.Context(method) as ctx:
click.echo(ctx.get_help())
raise click.BadParameter("Could not find names.dmp in taxdump, specify a value or make sure the files are present")
def validate_ip(ctx, param, value):
try:
ipaddress.ip_address(value)
return value
except ValueError as ex:
raise click.BadParameter("Invalid IP: %s" % ex)
def validate_token(ctx, param, value):
token_len = len(value)
if token_len != 32:
raise click.BadParameter("Token length != 32 chars: %s" % token_len)
return value
def validate_ip(ctx, param, value):
if value is None:
return value
try:
ipaddress.ip_address(value)
return value
except ValueError as ex:
raise click.BadParameter("Invalid IP: %s" % ex)
def validate_token(ctx, param, value):
if value is None:
return value
token_len = len(value)
if token_len != 32:
raise click.BadParameter("Token length != 32 chars: %s" % token_len)
return value
def validate_percentage(ctx, param, value):
value = int(value)
if value < 1 or value > 100:
raise click.BadParameter('Should be a positive int between 1-100.')
return value
def validate_scene(ctx, param, value):
value = int(value)
if value < 1 or value > 4:
raise click.BadParameter('Should be a positive int between 1-4.')
return value
def validate_token(ctx, param, value):
token_len = len(value)
if token_len != 32:
raise click.BadParameter("Token length != 32 chars: %s" % token_len)
return value