From 70afb5d4f3c2efddcded04a00787192074705a5a Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Thu, 12 Dec 2013 10:06:37 -0500 Subject: [PATCH] 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. --- tuf/interposition/updater.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tuf/interposition/updater.py b/tuf/interposition/updater.py index 5d7e148a..8c065479 100644 --- a/tuf/interposition/updater.py +++ b/tuf/interposition/updater.py @@ -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)