Skip to content

Commit cd05ebb

Browse files
committed
fixed linting errors
Signed-off-by: Helge Wehder <[email protected]>
1 parent 6b84f9b commit cd05ebb

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-459/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ In Python there is two documented ways to create temporary files using the `temp
88

99
`tempfile.mkstemp()` creates a secure file in the most secure fashion allowing only read and write to the user who executed the python script. The function returns a tuple containing a file descriptor and the file path, but since this tuple is not a context manager, it does not directly integrate with the `with` statement, which automatically manages resource cleanup. This means that the user is responsible for deleting the temporary file after use.
1010

11-
1211
`tempfile.NamedTemporaryFile()` is more advanced than the `mkstemp()` method as it returns a file-like object, which acts as a context manager, which works well with the `with` statement, although it creates the file with the same permissions as `mkstemp()`. The default behaviour is to delete the file once the `with` block is finished. If the file is needed outside of the with block, the `delete_on_close parameter` must be set to `false`.
1312

14-
15-
1613
## Non-Compliant Code Example
1714

1815
In the `noncompliant01.py` example, a temporary file is created but is not removed after completion.

docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-459/compliant01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# SPDX-License-Identifier: MIT
33
""" Compliant Code Example """
44
import tempfile
5-
5+
66
with tempfile.NamedTemporaryFile() as temp_file:
77
temp_file.write(b'This temporary file will be deleted.')
88
temp_file_path = temp_file.name
9-
9+
1010
with open(temp_file_path, 'rb') as temp_file:
1111
print(temp_file.read())

docs/Secure-Coding-Guide-for-Python/CWE-664/CWE-459/noncompliant02.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
""" Non-compliant Code Example """
44
import os
55
from tempfile import mkstemp
6-
6+
77
fd, path = mkstemp()
88
with os.fdopen(fd, 'w') as f:
99
f.write('TEST\n')
10-
10+
1111
print(path)

0 commit comments

Comments
 (0)