Пример #1
0
 def _check_for_uri_param(self, param, value):
     if isinstance(value, list) and len(value) == 1:
         value = value[0]
     try:
         return get_paramfile(value, self._prefixes)
     except ResourceLoadingError as e:
         raise ParamError(param.cli_name, six.text_type(e))
Пример #2
0
 def __call__(self, event_name, param, value, **kwargs):
     """Handler that supports param values from local files."""
     if isinstance(value, list) and len(value) == 1:
         value = value[0]
     try:
         return get_paramfile(value, self._prefixes)
     except ResourceLoadingError as e:
         raise ParamError(param.cli_name, six.text_type(e))
Пример #3
0
    def add_to_call_parameters(self, call_parameters, parsed_args, **kwargs):
        arg_value = self._get_arg_value(parsed_args)
        if arg_value is None:
            return

        loaded_params = self._load_parameters(arg_value)
        if not isinstance(loaded_params, dict):
            raise ParamError(
                self.cli_name, "Invalid type: expecting map, "
                "received %s" % type(loaded_params))
        self._update_call_parameters(call_parameters, loaded_params)
Пример #4
0
    def add_to_call_parameters(self, call_parameters, parsed_args,
                               parsed_globals, **kwargs):

        # Check if ``--cli-input-json`` was specified in the command line.
        input_json = getattr(parsed_args, 'cli_input_json', None)
        if input_json is not None:
            # Retrieve the JSON from the file if needed.
            retrieved_json = get_paramfile(input_json, LOCAL_PREFIX_MAP)
            # Nothing was retrieved from the file. So assume the argument
            # is already a JSON string.
            if retrieved_json is None:
                retrieved_json = input_json
            try:
                # Try to load the JSON string into a python dictionary
                input_data = json.loads(retrieved_json)
            except ValueError as e:
                raise ParamError(
                    self.name, "Invalid JSON: %s\nJSON received: %s" %
                    (e, retrieved_json))
            # Add the members from the input JSON to the call parameters.
            self._update_call_parameters(call_parameters, input_data)
Пример #5
0
 def _load_parameters(self, arg_value):
     try:
         return yaml.safe_load(arg_value)
     except YAMLError:
         raise ParamError(self.name, "Invalid YAML received.")
Пример #6
0
 def _load_parameters(self, arg_value):
     try:
         return json.loads(arg_value)
     except ValueError:
         raise ParamError(self.name, "Invalid JSON received.")