Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
f"not a string or dict"
)
if self.type == "command" and isinstance(self.value, dict):
value_keys = self.value.keys()
for required_key in ("command", "system", "version"):
if required_key not in value_keys:
raise ModelValidationError(
f"Can not save choices '{self}': specifying value as a "
f"dictionary requires a '{required_key}' item"
)
try:
if self.details == {}:
if isinstance(self.value, six.string_types):
self.details = parse(self.value)
elif isinstance(self.value, dict):
self.details = parse(self.value["command"])
except (LarkError, ParseError):
raise ModelValidationError(
f"Can not save choices '{self}': Unable to parse"
)
else:
raise ModelValidationError(
"Unable to validate choices for parameter '%s' - Choices value"
" must be a list or dictionary " % command_parameter.key
)
elif choices.type == "url":
parsed_value = parse(choices.value, parse_as="url")
query_params = map_param_values(parsed_value["args"])
raw_allowed = json.loads(
self._session.get(parsed_value["address"], params=query_params).text
)
elif choices.type == "command":
if isinstance(choices.value, six.string_types):
parsed_value = parse(choices.value, parse_as="func")
choices_request = Request(
system=request.system,
system_version=request.system_version,
instance_name=request.instance_name,
command=parsed_value["name"],
parameters=map_param_values(parsed_value["args"]),
)
elif isinstance(choices.value, dict):
parsed_value = parse(choices.value["command"], parse_as="func")
choices_request = Request(
system=choices.value.get("system"),
system_version=choices.value.get("version"),
instance_name=choices.value.get("instance_name", "default"),
command=parsed_value["name"],
parameters=map_param_values(parsed_value["args"]),
self._session.get(parsed_value["address"], params=query_params).text
)
elif choices.type == "command":
if isinstance(choices.value, six.string_types):
parsed_value = parse(choices.value, parse_as="func")
choices_request = Request(
system=request.system,
system_version=request.system_version,
instance_name=request.instance_name,
command=parsed_value["name"],
parameters=map_param_values(parsed_value["args"]),
)
elif isinstance(choices.value, dict):
parsed_value = parse(choices.value["command"], parse_as="func")
choices_request = Request(
system=choices.value.get("system"),
system_version=choices.value.get("version"),
instance_name=choices.value.get("instance_name", "default"),
command=parsed_value["name"],
parameters=map_param_values(parsed_value["args"]),
)
else:
raise ModelValidationError(
"Unable to validate choices for parameter '%s' - Choices value"
" must be a string or dictionary " % command_parameter.key
)
response = process_request(
choices_request, wait_timeout=self._command_timeout
)
if self.type == "command" and isinstance(self.value, dict):
value_keys = self.value.keys()
for required_key in ("command", "system", "version"):
if required_key not in value_keys:
raise ModelValidationError(
f"Can not save choices '{self}': specifying value as a "
f"dictionary requires a '{required_key}' item"
)
try:
if self.details == {}:
if isinstance(self.value, six.string_types):
self.details = parse(self.value)
elif isinstance(self.value, dict):
self.details = parse(self.value["command"])
except (LarkError, ParseError):
raise ModelValidationError(
f"Can not save choices '{self}': Unable to parse"
)