Skip to content

Commit 3193702

Browse files
author
James William Pye
committed
Use with statement.
1 parent c7db270 commit 3193702

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

postgresql/pgpassfile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def parse(data):
2222
]
2323

2424
def lookup_password(words, uhpd):
25-
"""lookup_password(words, (user, host, port, database)) -> password
25+
"""
26+
lookup_password(words, (user, host, port, database)) -> password
2627
2728
Where 'words' is the output from pgpass.parse()
2829
"""
@@ -36,11 +37,8 @@ def lookup_password(words, uhpd):
3637

3738
def lookup_password_file(path, t):
3839
'like lookup_password, but takes a file path'
39-
f = open(path)
40-
try:
40+
with open(path) as f:
4141
return lookup_password(parse(f), t)
42-
finally:
43-
f.close()
4442

4543
def lookup_pgpass(d, passfile):
4644
# If the password file exists, lookup the password

0 commit comments

Comments
 (0)