How to use the awscli.compat.six function in awscli

To help you get started, we’ve selected a few awscli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cli / tests / unit / customizations / s3 / test_executor.py View on Github external
def assert_expected_output(self, print_task, expected_output, thread,
                               out_file):
        with mock.patch(out_file, new=six.StringIO()) as mock_out:
            self.result_queue.put(print_task)
            self.result_queue.put(ShutdownThreadRequest())
            thread.run()
            self.assertIn(expected_output, mock_out.getvalue())
github aws / aws-cli / tests / functional / cloudtrail / test_validation.py View on Github external
def test_validates_valid_log_files(self):
        key_provider, digest_provider, validator = create_scenario(
            ['gap', 'link', 'link'],
            [[self._logs[2]], [], [self._logs[0], self._logs[1]]])
        self.parsed_responses = [
            {'LocationConstraint': ''},
            {'Body': six.BytesIO(_gz_compress(self._logs[0]['_raw_value']))},
            {'Body': six.BytesIO(_gz_compress(self._logs[1]['_raw_value']))},
            {'Body': six.BytesIO(_gz_compress(self._logs[2]['_raw_value']))},
        ]
        _setup_mock_traverser(self._mock_traverser, key_provider,
                              digest_provider, validator)
        stdout, stderr, rc = self.run_cmd(
            "cloudtrail validate-logs --trail-arn %s --start-time %s --verbose"
            % (TEST_TRAIL_ARN, START_TIME_ARG), 0)
        self.assertIn('s3://1/key1', stdout)
        self.assertIn('s3://1/key2', stdout)
        self.assertIn('s3://1/key3', stdout)
github aws / aws-cli / tests / functional / test_streaming_output.py View on Github external
def test_get_media_streaming_output(self):
        cmdline = (
            'kinesis-video-media get-media --stream-name test-stream '
            '--start-selector StartSelectorType=EARLIEST %s'
        )
        self.parsed_response = {
            'ContentType': 'video/webm',
            'Payload': six.BytesIO(b'testbody')
        }
        outpath = self.files.full_path('outfile')
        params = {
            'StartSelector': {'StartSelectorType': 'EARLIEST'},
            'StreamName': 'test-stream'
        }
        self.assert_params_for_cmd(cmdline % outpath, params)
        with open(outpath, 'rb') as outfile:
            self.assertEqual(outfile.read(), b'testbody')
github aws / aws-cli / tests / functional / s3 / test_cp_command.py View on Github external
def test_cp_fails_with_utime_errors_but_continues(self):
        full_path = self.files.create_file('foo.txt', '')
        cmdline = '%s s3://bucket/key.txt %s' % (self.prefix, full_path)
        self.parsed_responses = [
            {"ContentLength": "100", "LastModified": "00:00:00Z"},
            {'ETag': '"foo-1"', 'Body': six.BytesIO(b'foo')}
        ]
        with mock.patch('os.utime') as mock_utime:
            mock_utime.side_effect = OSError(1, '')
            _, err, _ = self.run_cmd(cmdline, expected_rc=1)
            self.assertIn('attempting to modify the utime', err)
github aws / aws-cli / awscli / utils.py View on Github external
def write_exception(ex, outfile):
    outfile.write("\n")
    outfile.write(six.text_type(ex))
    outfile.write("\n")
github gkrizek / bash-lambda-layer / bin / awscli / customizations / cloudformation / artifact_exporter.py View on Github external
def parse_s3_url(url,
                 bucket_name_property="Bucket",
                 object_key_property="Key",
                 version_property=None):

    if isinstance(url, six.string_types) \
            and url.startswith("s3://"):

        # Python < 2.7.10 don't parse query parameters from URI with custom
        # scheme such as s3://blah/blah. As a workaround, remove scheme
        # altogether to trigger the parser "s3://foo/bar?v=1" =>"//foo/bar?v=1"
        parsed = urlparse.urlparse(url[3:])
        query = urlparse.parse_qs(parsed.query)

        if parsed.netloc and parsed.path:
            result = dict()
            result[bucket_name_property] = parsed.netloc
            result[object_key_property] = parsed.path.lstrip('/')

            # If there is a query string that has a single versionId field,
            # set the object version and return
            if version_property is not None \
github gkrizek / bash-lambda-layer / bin / awscli / argprocess.py View on Github external
def _unpack_cli_arg(argument_model, value, cli_name):
    if is_json_value_header(argument_model):
        return _unpack_json_cli_arg(argument_model, value, cli_name)
    elif argument_model.type_name in SCALAR_TYPES:
        return unpack_scalar_cli_arg(
            argument_model, value, cli_name)
    elif argument_model.type_name in COMPLEX_TYPES:
        return _unpack_complex_cli_arg(
            argument_model, value, cli_name)
    else:
        return six.text_type(value)
github aws / aws-cli / awscli / customizations / history / show.py View on Github external
def _write_output(self, content):
        if isinstance(content, six.text_type):
            content = content.encode('utf-8')
        self._output.write(content)
github aws / aws-cli / awscli / customizations / s3 / transferconfig.py View on Github external
def _convert_human_readable_sizes(self, runtime_config):
        for attr in self.HUMAN_READABLE_SIZES:
            value = runtime_config.get(attr)
            if value is not None and not isinstance(value, six.integer_types):
                runtime_config[attr] = human_readable_to_bytes(value)
github aws / aws-cli / awscli / argprocess.py View on Github external
def _should_parse_as_shorthand(self, cli_argument, value):
        # We first need to make sure this is a parameter that qualifies
        # for simplification.  The first short-circuit case is if it looks
        # like json we immediately return.
        if value and isinstance(value, list):
            check_val = value[0]
        else:
            check_val = value
        if isinstance(check_val, six.string_types) and check_val.strip().startswith(
                ('[', '{')):
            LOG.debug("Param %s looks like JSON, not considered for "
                      "param shorthand.", cli_argument.py_name)
            return False
        model = cli_argument.argument_model
        # The second case is to make sure the argument is sufficiently
        # complex, that is, it's base type is a complex type *and*
        # if it's a list, then it can't be a list of scalar types.
        return _is_complex_shape(model)