Make sure auth file is closed during get_localhost_auth

This commit is contained in:
Chase Sterling 2013-05-11 22:45:15 -04:00
parent e263db90ce
commit 502f135b15
1 changed files with 20 additions and 19 deletions

View File

@ -416,24 +416,25 @@ def get_localhost_auth():
from deluge.common import create_localclient_account
create_localclient_account()
for line in open(auth_file):
if line.startswith("#"):
# This is a comment line
continue
line = line.strip()
try:
lsplit = line.split(":")
except Exception, e:
log.error("Your auth file is malformed: %s", e)
continue
with open(auth_file) as auth:
for line in auth:
if line.startswith("#"):
# This is a comment line
continue
line = line.strip()
try:
lsplit = line.split(":")
except Exception, e:
log.error("Your auth file is malformed: %s", e)
continue
if len(lsplit) == 2:
username, password = lsplit
elif len(lsplit) == 3:
username, password, level = lsplit
else:
log.error("Your auth file is malformed: Incorrect number of fields!")
continue
if len(lsplit) == 2:
username, password = lsplit
elif len(lsplit) == 3:
username, password, level = lsplit
else:
log.error("Your auth file is malformed: Incorrect number of fields!")
continue
if username == "localclient":
return (username, password)
if username == "localclient":
return (username, password)