mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
Close all open filehandle (#50544)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
94a1d86d70
commit
db8702cdb8
21 changed files with 81 additions and 47 deletions
|
@ -128,7 +128,8 @@ def assemble_from_fragments(src_path, delimiter=None, compiled_regexp=None, igno
|
|||
fragment = os.path.join(src_path, f)
|
||||
if not os.path.isfile(fragment) or (ignore_hidden and os.path.basename(fragment).startswith('.')):
|
||||
continue
|
||||
fragment_content = open(fragment, 'rb').read()
|
||||
with open(fragment, 'rb') as fragment_fh:
|
||||
fragment_content = fragment_fh.read()
|
||||
|
||||
# always put a newline between fragments if the previous fragment didn't end with a newline.
|
||||
if add_newline:
|
||||
|
|
|
@ -170,7 +170,9 @@ ZIP_FILE_MODE_RE = re.compile(r'([r-][w-][SsTtx-]){3}')
|
|||
|
||||
def crc32(path):
|
||||
''' Return a CRC32 checksum of a file '''
|
||||
return binascii.crc32(open(path, 'rb').read()) & 0xffffffff
|
||||
with open(path, 'rb') as f:
|
||||
file_content = f.read()
|
||||
return binascii.crc32(file_content) & 0xffffffff
|
||||
|
||||
|
||||
def shell_escape(string):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue