Пример #1
0
    def _upload(self, manager, bucket, key):
        """
        Upload stdin using to the specified location.

        :type manager: s3transfer.manager.TransferManager
        :param manager: The transfer manager to use for the upload.

        :type bucket: str
        :param bucket: The bucket to upload the stream to.

        :type key: str
        :param key: The name of the key to upload the stream to.

        :return: A CommandResult representing the upload status.
        """
        expected_size = self.params.get('expected_size', None)
        subscribers = None
        if expected_size is not None:
            # `expected_size` comes in as a string
            expected_size = int(expected_size)

            # set the size of the transfer if we know it ahead of time.
            subscribers = [ProvideSizeSubscriber(expected_size)]

            # TODO: remove when this happens in s3transfer
            # If we have the expected size, we can calculate an appropriate
            # chunksize based on max parts and chunksize limits
            chunksize = find_chunksize(expected_size,
                                       self.config.multipart_chunksize)
        else:
            # TODO: remove when this happens in s3transfer
            # Otherwise, we can still adjust for chunksize limits
            chunksize = adjust_chunksize_to_upload_limits(
                self.config.multipart_chunksize)
        self.config.multipart_chunksize = chunksize

        params = {}
        RequestParamsMapper.map_put_object_params(params, self.params)

        fileobj = NonSeekableStream(binary_stdin)
        with manager:
            future = manager.upload(fileobj=fileobj,
                                    bucket=bucket,
                                    key=key,
                                    extra_args=params,
                                    subscribers=subscribers)

            return self._process_transfer(future)
Пример #2
0
 def test_can_specify_amount_for_nonseekable_stream(self):
     nonseekable_fileobj = NonSeekableStream(StringIO("foobar"))
     self.assertEqual(nonseekable_fileobj.read(3), "foo")
Пример #3
0
 def test_can_make_stream_unseekable(self):
     fileobj = StringIO("foobar")
     self.assertTrue(seekable(fileobj))
     nonseekable_fileobj = NonSeekableStream(fileobj)
     self.assertFalse(seekable(nonseekable_fileobj))
     self.assertEqual(nonseekable_fileobj.read(), "foobar")
 def test_can_specify_amount_for_nonseekable_stream(self):
     nonseekable_fileobj = NonSeekableStream(StringIO('foobar'))
     self.assertEqual(nonseekable_fileobj.read(3), 'foo')
 def test_can_make_stream_unseekable(self):
     fileobj = StringIO('foobar')
     self.assertTrue(seekable(fileobj))
     nonseekable_fileobj = NonSeekableStream(fileobj)
     self.assertFalse(seekable(nonseekable_fileobj))
     self.assertEqual(nonseekable_fileobj.read(), 'foobar')
Пример #6
0
 def _get_filein(self, fileinfo):
     binary_stdin = get_binary_stdin()
     return NonSeekableStream(binary_stdin)