mirror of
https://github.com/samba-team/samba.git
synced 2025-07-31 20:22:15 +03:00
python: Don't leak file handles
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Noel Power <npower@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
committed by
Andrew Bartlett
parent
9a24d8e491
commit
cde38d36b9
@ -217,7 +217,8 @@ class Ldb(_Ldb):
|
||||
|
||||
:param ldif_path: Path to LDIF file.
|
||||
"""
|
||||
self.add_ldif(open(ldif_path, 'r').read())
|
||||
with open(ldif_path, 'r') as ldif_file:
|
||||
self.add_ldif(ldif_file.read())
|
||||
|
||||
def add_ldif(self, ldif, controls=None):
|
||||
"""Add data based on a LDIF string.
|
||||
@ -279,7 +280,8 @@ def read_and_sub_file(file_name, subst_vars):
|
||||
:param file_name: File to be read (typically from setup directory)
|
||||
param subst_vars: Optional variables to subsitute in the file.
|
||||
"""
|
||||
data = open(file_name, 'r', encoding="utf-8").read()
|
||||
with open(file_name, 'r', encoding="utf-8") as data_file:
|
||||
data = data_file.read()
|
||||
if subst_vars is not None:
|
||||
data = substitute_var(data, subst_vars)
|
||||
check_all_substituted(data)
|
||||
|
@ -294,7 +294,7 @@ def __parse_schema_file(filename, objectClass):
|
||||
out = []
|
||||
|
||||
from io import open
|
||||
f = open(filename, "r", encoding='latin-1')
|
||||
with open(filename, "r", encoding='latin-1') as f:
|
||||
for entry in __read_raw_entries(f):
|
||||
out.append(__write_ldif_one(__transform_entry(entry, objectClass)))
|
||||
|
||||
|
@ -110,8 +110,13 @@ class Schema(object):
|
||||
setup_path('ad-schema/%s' % Schema.base_schemas[base_schema][0]),
|
||||
setup_path('ad-schema/%s' % Schema.base_schemas[base_schema][1]))
|
||||
|
||||
def read_file(file):
|
||||
with open(file, 'rb') as data_file:
|
||||
return data_file.read()
|
||||
|
||||
if files is not None:
|
||||
self.schema_data = "".join(get_string(open(file, 'rb').read()) for file in files)
|
||||
self.schema_data = "".join(get_string(read_file(file))
|
||||
for file in files)
|
||||
|
||||
self.schema_data = substitute_var(self.schema_data,
|
||||
{"SCHEMADN": schemadn})
|
||||
@ -130,7 +135,7 @@ class Schema(object):
|
||||
if override_prefixmap is not None:
|
||||
self.prefixmap_data = override_prefixmap
|
||||
else:
|
||||
self.prefixmap_data = open(setup_path("prefixMap.txt"), 'rb').read()
|
||||
self.prefixmap_data = read_file(setup_path("prefixMap.txt"))
|
||||
|
||||
if additional_prefixmap is not None:
|
||||
self.prefixmap_data += "".join("%s\n" % map for map in additional_prefixmap)
|
||||
|
Reference in New Issue
Block a user