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