facebook/tornado — pull request #669 by mleonhard (2013-01-21 00:59:13+00:00)
Title: Fix s3server.py to stop truncating downloads of images and other non-text files

I'm using s3server.py to develop a JavaScript app to run from an S3 bucket. It works fine when serving HTML and CSS files, but my images were getting truncated. When serving a GET request, the script opens the file with mode "r" which asks Python to interpret the file as text. Python on Windows will choke on the file data when certain characters are encountered. Changing the mode to "rb" makes Python read plain bytes, solving the problem.

C:\Users\Michael\Desktop\s3blog\s3server-buckets\s3blog>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> len(open('spinner.gif', 'r').read())
965
>>> len(open('spinner.gif', 'rb').read())
17517
>>>