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)