Some more stricter type checks and exceptions.
This commit is contained in:
parent
2db1f12bfb
commit
0df556da3f
2 changed files with 14 additions and 4 deletions
|
@ -22,10 +22,14 @@ from . import helpers
|
|||
BAIL = sentinel.Sentinel('BAIL')
|
||||
|
||||
def normalize_db_row(db_row, table):
|
||||
if isinstance(db_row, (list, tuple)):
|
||||
db_row = dict(zip(constants.SQL_COLUMNS[table], db_row))
|
||||
if isinstance(db_row, dict):
|
||||
return db_row
|
||||
|
||||
if isinstance(db_row, (list, tuple)):
|
||||
return dict(zip(constants.SQL_COLUMNS[table], db_row))
|
||||
|
||||
raise TypeError(f'db_row should be {dict}, {list}, or {tuple}, not {type(db_row)}.')
|
||||
|
||||
class ObjectBase:
|
||||
def __init__(self, photodb):
|
||||
super().__init__()
|
||||
|
@ -581,7 +585,7 @@ class Bookmark(ObjectBase):
|
|||
url = url.strip()
|
||||
|
||||
if not url:
|
||||
raise ValueError(f'Invalid URL "{url}".')
|
||||
raise ValueError(f'URL can not be blank.')
|
||||
|
||||
return url
|
||||
|
||||
|
|
|
@ -1210,10 +1210,16 @@ class PDBUserMixin:
|
|||
raise exceptions.UserExists(existing_user)
|
||||
|
||||
def assert_valid_password(self, password):
|
||||
if not isinstance(password, bytes):
|
||||
raise TypeError(f'Password must be {bytes}, not {type(password)}.')
|
||||
|
||||
if len(password) < self.config['user']['min_password_length']:
|
||||
raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length'])
|
||||
|
||||
def assert_valid_username(self, username):
|
||||
if not isinstance(username, str):
|
||||
raise TypeError(f'Username must be {str}, not {type(username)}.')
|
||||
|
||||
if len(username) < self.config['user']['min_username_length']:
|
||||
raise exceptions.UsernameTooShort(
|
||||
username=username,
|
||||
|
@ -1287,7 +1293,7 @@ class PDBUserMixin:
|
|||
be workable but fails.
|
||||
'''
|
||||
if user_obj_or_id is None:
|
||||
author_id = None
|
||||
return None
|
||||
|
||||
elif isinstance(user_obj_or_id, objects.User):
|
||||
if user_obj_or_id.photodb != self:
|
||||
|
|
Loading…
Reference in a new issue