Remove redundant else blocks
This commit is contained in:
parent
c0ea23c307
commit
aae65cc5d8
@ -51,9 +51,7 @@ class CollectionWrapper:
|
|||||||
try:
|
try:
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
if exc.errno == errno.EEXIST:
|
if exc.errno != errno.EEXIST:
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
col = anki.storage.Collection(self.path, server=True)
|
col = anki.storage.Collection(self.path, server=True)
|
||||||
|
|||||||
@ -161,7 +161,7 @@ class SyncMediaHandler(anki.sync.MediaSyncer):
|
|||||||
for i in zip_file.infolist():
|
for i in zip_file.infolist():
|
||||||
if i.filename == "_meta": # Ignore previously retrieved metadata.
|
if i.filename == "_meta": # Ignore previously retrieved metadata.
|
||||||
continue
|
continue
|
||||||
else:
|
|
||||||
file_data = zip_file.read(i)
|
file_data = zip_file.read(i)
|
||||||
csum = anki.utils.checksum(file_data)
|
csum = anki.utils.checksum(file_data)
|
||||||
filename = self._normalize_filename(meta[int(i.filename)][0])
|
filename = self._normalize_filename(meta[int(i.filename)][0])
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class SqliteUserManager(SimpleUserManager):
|
|||||||
if not self.auth_db_exists():
|
if not self.auth_db_exists():
|
||||||
raise ValueError("Cannot list users for nonexistent auth db {}."
|
raise ValueError("Cannot list users for nonexistent auth db {}."
|
||||||
.format(self.auth_db_path))
|
.format(self.auth_db_path))
|
||||||
else:
|
|
||||||
conn = sqlite.connect(self.auth_db_path)
|
conn = sqlite.connect(self.auth_db_path)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("SELECT user FROM auth")
|
cursor.execute("SELECT user FROM auth")
|
||||||
@ -69,11 +69,10 @@ class SqliteUserManager(SimpleUserManager):
|
|||||||
if not self.auth_db_exists():
|
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))
|
.format(self.auth_db_path))
|
||||||
else:
|
|
||||||
conn = sqlite.connect(self.auth_db_path)
|
conn = sqlite.connect(self.auth_db_path)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
logging.info("Removing user '{}' from auth db."
|
logging.info("Removing user '{}' from auth db".format(username))
|
||||||
.format(username))
|
|
||||||
cursor.execute("DELETE FROM auth WHERE user=?", (username,))
|
cursor.execute("DELETE FROM auth WHERE user=?", (username,))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -102,12 +101,12 @@ class SqliteUserManager(SimpleUserManager):
|
|||||||
|
|
||||||
def set_password_for_user(self, username, new_password):
|
def set_password_for_user(self, username, new_password):
|
||||||
if not self.auth_db_exists():
|
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))
|
.format(self.auth_db_path))
|
||||||
elif not self.user_exists(username):
|
elif not self.user_exists(username):
|
||||||
raise ValueError("Cannot remove nonexistent user {}."
|
raise ValueError("Cannot remove nonexistent user {}"
|
||||||
.format(username))
|
.format(username))
|
||||||
else:
|
|
||||||
hash = self._create_pass_hash(username, new_password)
|
hash = self._create_pass_hash(username, new_password)
|
||||||
|
|
||||||
conn = sqlite.connect(self.auth_db_path)
|
conn = sqlite.connect(self.auth_db_path)
|
||||||
@ -116,7 +115,7 @@ class SqliteUserManager(SimpleUserManager):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
logging.info("Changed password for user {}.".format(username))
|
logging.info("Changed password for user {}".format(username))
|
||||||
|
|
||||||
def authenticate(self, username, password):
|
def authenticate(self, username, password):
|
||||||
"""Returns True if this username is allowed to connect with this password. False otherwise."""
|
"""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 {}."
|
logging.info("Authentication failed for nonexistent user {}."
|
||||||
.format(username))
|
.format(username))
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
expected_value = str(db_hash[0])
|
expected_value = str(db_hash[0])
|
||||||
salt = self._extract_salt(expected_value)
|
salt = self._extract_salt(expected_value)
|
||||||
|
|
||||||
@ -141,12 +140,10 @@ class SqliteUserManager(SimpleUserManager):
|
|||||||
actual_value = hashobj.hexdigest() + salt
|
actual_value = hashobj.hexdigest() + salt
|
||||||
|
|
||||||
if actual_value == expected_value:
|
if actual_value == expected_value:
|
||||||
logging.info("Authentication succeeded for user {}."
|
logging.info("Authentication succeeded for user {}".format(username))
|
||||||
.format(username))
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logging.info("Authentication failed for user {}."
|
logging.info("Authentication failed for user {}".format(username))
|
||||||
.format(username))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user