Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def type_cast_value(self, ctx, value):
try:
if value is not None and not isinstance(value, Undefined):
return ast.literal_eval(value)
return value
except:
print("shit")
print(traceback.format_exc())
raise click.BadParameter(value)
def validate_server_address(ctx, param, address_string):
if ':' in address_string:
host, port_string = address_string.split(':', 1)
try:
port = int(port_string)
except ValueError:
msg = "port '{}' in address '{}' is not an integer".format(port_string, address_string)
raise click.BadParameter(msg)
return (host, port)
else:
return (address_string, 3306)
def callback(ctx, param, value):
fields = [f.strip() for f in value.split(',')]
for f in fields:
if f not in self.allowed_fields:
raise click.BadParameter('Invalid choice: {0}.'.format(f))
return [f for f in self.fields if f.name in fields]
def validate_command(ctx, param, value):
if value is None:
return None
parts = shlex.split(value)
command = parts[0]
if os.path.exists(command):
command = os.path.abspath(command)
else:
what = which(command)
if what is None:
raise click.BadParameter("%s: command not found" % (command,))
command = os.path.abspath(what)
return [command] + parts[1:]
def __main(directory, config, filename):
"""
The main entry point.
"""
base_directory, config = load_config_from_options(directory, config)
definitions = config["types"] or []
if len(filename.split(".")) < 2 or (
filename.split(".")[-1] not in definitions
and filename.split(".")[-2] not in definitions
):
raise click.BadParameter(
"Expected filename '{}' to be of format '{{name}}.{{type}}', "
"where '{{name}}' is an arbitrary slug and '{{type}}' is "
"one of: {}".format(filename, ", ".join(definitions))
)
if config.get("directory"):
fragments_directory = os.path.abspath(
os.path.join(base_directory, config["directory"])
)
else:
fragments_directory = os.path.abspath(
os.path.join(
base_directory,
config["package_dir"],
config["package"],
"newsfragments",
def _validate_python_option(input_value):
if int(input_value) not in {1, 2}:
raise BadParameter(
message="invalid choice: {}. (choose from 1, 2)".format(str(input_value))
)
return int(input_value)
'"{path_pair}" is not in the format '
'/absolute/local/path:/remote/path.'
).format(path_pair=path_pair)
raise click.BadParameter(message=message)
if not local_path.exists():
message = '"{local_path}" does not exist.'.format(
local_path=local_path,
)
raise click.BadParameter(message=message)
if not remote_path.is_absolute():
message = '"{remote_path} is not an absolute path.'.format(
remote_path=remote_path,
)
raise click.BadParameter(message=message)
result.append((local_path, remote_path))
return result
def validate_resolve_type(ctx, param, value):
if value in ['json', 'yaml']:
return value
else:
raise click.BadParameter('type need to be json or yaml.')
geometries = [f['geometry'] for f in geojson['features']]
elif 'geometry' in geojson:
geometries = (geojson['geometry'], )
else:
raise click.BadParameter('Invalid GeoJSON', param=input,
param_hint='input')
with rasterio.open(input) as src:
try:
out_image, out_transform = mask_tool(src, geometries,
crop=crop, invert=invert,
all_touched=all_touched)
except ValueError as e:
if e.args[0] == 'Input shapes do not overlap raster.':
if crop:
raise click.BadParameter('not allowed for GeoJSON '
'outside the extent of the '
'input raster',
param=crop,
param_hint='--crop')
else: # pragma: no cover
raise e
profile = src.profile
profile.update(**creation_options)
profile.update({
'driver': driver,
'height': out_image.shape[1],
'width': out_image.shape[2],
'transform': out_transform
})
def validate_max_comments(ctx, param, value):
'''
Validates the max_comments option.
Parameter {click.core.Context} ctx: the Click command's context.
Parameter {click.core.Option} param: the Click command's option.
Parameter {any} param: the value passed to the Click command's option.
'''
if value is not None and value < -1:
raise click.BadParameter(
'{} is invalid. Enter an integer greater-than-or-equal-to zero.'
.format(value)
)