From 502f135b1578f8666c5bda2af47fc35c08fb572f Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Sat, 11 May 2013 22:45:15 -0400 Subject: [PATCH] Make sure auth file is closed during get_localhost_auth --- deluge/ui/common.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 795fdcda8..af78d0b59 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -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)