aws/aws-cli — pull request #890 by spazm (2014-08-21 05:35:13+00:00)
Title:  #814 - open compressed files with binary mode

A possible fix for #814 (introduced with fix for #765?)

We need to open binary files with 'b' flag and not attempt to translate the encoding to avoid:

'utf8' codec can't decode byte 0x8b in position 1: invalid start byte

```python
>>> import mimetypes
>>> mimetypes.guess_type('foo.json')
('application/json', None)
>>> mimetypes.guess_type('foo.txt')
('text/plain', None)
>>> mimetypes.guess_type('foo.txt.gz')
('text/plain', 'gzip')
>>> mimetypes.guess_type('foo.txt.tar')
('application/x-tar', None)
>>> mimetypes.guess_type('foo.txt.tar.gz')
('application/x-tar', 'gzip')
>>> mimetypes.guess_type('foo.txt')
('text/plain', None)
>>> mimetypes.guess_type('foo.bar')
(None, None)
```

* for .gzip and .Z files, `mimetypes.guess_type` will return a non-None encoding.
* .tar: `'application/x-tar'`
* .txt extensions: 'text/*' ctype
* for no extension and unknown extension: `(None, None)`
* json will return `'application/json'`

Open to suggestions here. We definitely want Non-None encoding to trigger binary treatment. Less sure about the other cases.