예제 #1
0
 def _inject_content_type(self, params):
     if not self.parameters['guess_mime_type']:
         return
     filename = self.src
     # Add a content type param if we can guess the type.
     guessed_type = guess_content_type(filename)
     if guessed_type is not None:
         params['ContentType'] = guessed_type
예제 #2
0
 def _inject_content_type(self, params, filename):
     # Add a content type param if we can guess the type.
     try:
         guessed_type = guess_content_type(filename)
         if guessed_type is not None:
             params['ContentType'] = guessed_type
     # This catches a bug in the mimetype libary where some MIME types
     # specifically on windows machines cause a UnicodeDecodeError
     # because the MIME type in the Windows registery has an encoding
     # that cannot be properly encoded using the default system encoding.
     # https://bugs.python.org/issue9291
     #
     # So instead of hard failing, just log the issue and fall back to the
     # default guessed content type of None.
     except UnicodeDecodeError:
         LOGGER.debug(
             'Unable to guess content type for %s due to '
             'UnicodeDecodeError: ', filename, exc_info=True
         )
예제 #3
0
파일: fileinfo.py 프로젝트: eludom/aws-cli
 def _inject_content_type(self, params, filename):
     # Add a content type param if we can guess the type.
     try:
         guessed_type = guess_content_type(filename)
         if guessed_type is not None:
             params['ContentType'] = guessed_type
     # This catches a bug in the mimetype libary where some MIME types
     # specifically on windows machines cause a UnicodeDecodeError
     # because the MIME type in the Windows registery has an encoding
     # that cannot be properly encoded using the default system encoding.
     # https://bugs.python.org/issue9291
     #
     # So instead of hard failing, just log the issue and fall back to the
     # default guessed content type of None.
     except UnicodeDecodeError:
         LOGGER.debug(
             'Unable to guess content type for %s due to '
             'UnicodeDecodeError: ',
             filename,
             exc_info=True)
예제 #4
0
 def on_queued(self, future, **kwargs):
     guessed_type = utils.guess_content_type(self._get_filename(future))
     if guessed_type is not None:
         future.meta.call_args.extra_args['ContentType'] = guessed_type
예제 #5
0
파일: test_utils.py 프로젝트: aws/aws-cli
 def test_guess_content_type_with_unicode_error_returns_no_match(self):
     with mock.patch("mimetypes.guess_type") as guess_type_patch:
         # This should throw a UnicodeDecodeError.
         guess_type_patch.side_effect = lambda x: b"\xe2".decode("ascii")
         self.assertEqual(guess_content_type("foo.txt"), None)
예제 #6
0
파일: test_utils.py 프로젝트: aws/aws-cli
 def test_guess_content_type_with_no_valid_matches(self):
     self.assertEqual(guess_content_type("no-extension"), None)
예제 #7
0
파일: test_utils.py 프로젝트: aws/aws-cli
 def test_guess_content_type(self):
     self.assertEqual(guess_content_type("foo.txt"), "text/plain")
 def test_guess_content_type_with_unicode_error_returns_no_match(self):
     with mock.patch('mimetypes.guess_type') as guess_type_patch:
         # This should throw a UnicodeDecodeError.
         guess_type_patch.side_effect = lambda x: b'\xe2'.decode('ascii')
         self.assertEqual(guess_content_type('foo.txt'), None)
 def test_guess_content_type_with_no_valid_matches(self):
     self.assertEqual(guess_content_type('no-extension'), None)
 def test_guess_content_type(self):
     self.assertEqual(guess_content_type('foo.txt'), 'text/plain')
예제 #11
0
 def test_guess_content_type_with_unicode_error_returns_no_match(self):
     with mock.patch('mimetypes.guess_type') as guess_type_patch:
         # This should throw a UnicodeDecodeError.
         guess_type_patch.side_effect = lambda x: b'\xe2'.decode('ascii')
         self.assertEqual(guess_content_type('foo.txt'), None)
예제 #12
0
 def test_guess_content_type(self):
     self.assertEqual(guess_content_type('foo.txt'), 'text/plain')
예제 #13
0
 def _inject_content_type(self, params, filename):
     # Add a content type param if we can guess the type.
     guessed_type = guess_content_type(filename)
     if guessed_type is not None:
         params['ContentType'] = guessed_type