Skip to content

Commit 6ce07c9

Browse files
author
James William Pye
committed
Use with blocks to close out the objects.
1 parent c553ec0 commit 6ce07c9

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

postgresql/configfile.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ def __delitem__(self, k):
245245
self._save()
246246

247247
def __getitem__(self, k):
248-
return read_config(
249-
self._open(self.path),
250-
selector = k.__eq__
251-
)[k]
248+
with self._open(self.path) as cfo:
249+
return read_config(
250+
cfo,
251+
selector = k.__eq__
252+
)[k]
252253

253254
def __setitem__(self, k, v):
254255
self.update({k : v})
@@ -279,9 +280,8 @@ def __exit__(self, exc, val, tb):
279280
return exc is None
280281

281282
def get(self, k, alt = None):
282-
return read_config(
283-
self._open(self.path), selector = k.__eq__
284-
).get(k, alt)
283+
with self._open(self.path) as cf:
284+
return read_config(cf, selector = k.__eq__).get(k, alt)
285285

286286
def keys(self):
287287
return read_config(self._open(self.path)).keys()
@@ -307,12 +307,13 @@ def getset(self, keys):
307307
Returns a dictionary of those keys.
308308
"""
309309
keys = set(keys)
310-
cfg = read_config(
311-
self._open(self.path),
312-
selector = keys.__contains__
313-
)
314-
for x in (keys - set(cfg.keys())):
315-
cfg[x] = None
316-
return cfg
310+
with self._open(self.path) as cfo:
311+
cfg = read_config(
312+
cfo,
313+
selector = keys.__contains__
314+
)
315+
for x in (keys - set(cfg.keys())):
316+
cfg[x] = None
317+
return cfg
317318
##
318319
# vim: ts=3:sw=3:noet:

postgresql/installation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def get_command_output(exe, *args):
3131
shell = False
3232
)
3333
p.stdin.close()
34+
p.stderr.close()
3435
while True:
3536
try:
3637
rv = p.wait()
@@ -40,7 +41,8 @@ def get_command_output(exe, *args):
4041
raise
4142
if rv != 0:
4243
return None
43-
return io.TextIOWrapper(p.stdout).read()
44+
with p.stdout, io.TextIOWrapper(p.stdout) as txt:
45+
return txt.read()
4446

4547
def pg_config_dictionary(*pg_config_path):
4648
"""

0 commit comments

Comments
 (0)