Remove redundant else blocks

This commit is contained in:
flan 2017-11-08 13:23:48 +01:00
parent c0ea23c307
commit aae65cc5d8
3 changed files with 49 additions and 54 deletions

View File

@ -51,9 +51,7 @@ class CollectionWrapper:
try:
os.makedirs(dirname)
except OSError as exc:
if exc.errno == errno.EEXIST:
pass
else:
if exc.errno != errno.EEXIST:
raise
col = anki.storage.Collection(self.path, server=True)

View File

@ -161,7 +161,7 @@ class SyncMediaHandler(anki.sync.MediaSyncer):
for i in zip_file.infolist():
if i.filename == "_meta": # Ignore previously retrieved metadata.
continue
else:
file_data = zip_file.read(i)
csum = anki.utils.checksum(file_data)
filename = self._normalize_filename(meta[int(i.filename)][0])

View File

@ -51,7 +51,7 @@ class SqliteUserManager(SimpleUserManager):
if not self.auth_db_exists():
raise ValueError("Cannot list users for nonexistent auth db {}."
.format(self.auth_db_path))
else:
conn = sqlite.connect(self.auth_db_path)
cursor = conn.cursor()
cursor.execute("SELECT user FROM auth")
@ -69,11 +69,10 @@ class SqliteUserManager(SimpleUserManager):
if not self.auth_db_exists():
raise ValueError("Cannot remove user from nonexistent auth db {}."
.format(self.auth_db_path))
else:
conn = sqlite.connect(self.auth_db_path)
cursor = conn.cursor()
logging.info("Removing user '{}' from auth db."
.format(username))
logging.info("Removing user '{}' from auth db".format(username))
cursor.execute("DELETE FROM auth WHERE user=?", (username,))
conn.commit()
conn.close()
@ -102,12 +101,12 @@ class SqliteUserManager(SimpleUserManager):
def set_password_for_user(self, username, new_password):
if not self.auth_db_exists():
raise ValueError("Cannot remove user from nonexistent auth db {}."
raise ValueError("Cannot remove user from nonexistent auth db {}"
.format(self.auth_db_path))
elif not self.user_exists(username):
raise ValueError("Cannot remove nonexistent user {}."
raise ValueError("Cannot remove nonexistent user {}"
.format(username))
else:
hash = self._create_pass_hash(username, new_password)
conn = sqlite.connect(self.auth_db_path)
@ -116,7 +115,7 @@ class SqliteUserManager(SimpleUserManager):
conn.commit()
conn.close()
logging.info("Changed password for user {}.".format(username))
logging.info("Changed password for user {}".format(username))
def authenticate(self, username, password):
"""Returns True if this username is allowed to connect with this password. False otherwise."""
@ -132,7 +131,7 @@ class SqliteUserManager(SimpleUserManager):
logging.info("Authentication failed for nonexistent user {}."
.format(username))
return False
else:
expected_value = str(db_hash[0])
salt = self._extract_salt(expected_value)
@ -141,12 +140,10 @@ class SqliteUserManager(SimpleUserManager):
actual_value = hashobj.hexdigest() + salt
if actual_value == expected_value:
logging.info("Authentication succeeded for user {}."
.format(username))
logging.info("Authentication succeeded for user {}".format(username))
return True
else:
logging.info("Authentication failed for user {}."
.format(username))
logging.info("Authentication failed for user {}".format(username))
return False
@staticmethod