Add comment to the open() call in tuf.interposition.updater.py

Add link and explain why 'rb' mode is used rather than 'r'.  Prevent newcomers, or future edits, from mistakenly/accidently opening files in text mode.
This commit is contained in:
Vladimir Diaz 2013-12-12 10:06:37 -05:00
parent 4eeb8575de
commit 70afb5d4f3

View file

@ -132,10 +132,15 @@ def get_target_filepath(self, source_url):
def open(self, url, data=None):
filename, headers = self.retrieve(url, data=data)
# TUF should always open files in binary mode and remain transparent to the
# software updater. Opening files in text mode slightly alters the
# end-of-line characters and prevents binary files from properly loading on
# Windows.
# http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files
# TODO: like tempfile, ensure file is deleted when closed?
temporary_file = open(filename, 'rb')
# extend temporary_file with info(), getcode(), geturl()
# Extend temporary_file with info(), getcode(), geturl()
# http://docs.python.org/2/library/urllib.html#urllib.urlopen
response = urllib.addinfourl(temporary_file, headers, url, code=200)