mirror of
https://github.com/theupdateframework/python-tuf
synced 2026-05-24 10:08:28 +00:00
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:
parent
4eeb8575de
commit
70afb5d4f3
1 changed files with 6 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue