Add constants.USER_ID_CHARACTERS and show that when raising invalid.
This commit is contained in:
parent
b223691107
commit
2db1f12bfb
3 changed files with 8 additions and 3 deletions
|
@ -222,6 +222,8 @@ FILENAME_BADCHARS = '\\/:*?<>|"'
|
||||||
TRUTHYSTRING_TRUE = {s.lower() for s in ('1', 'true', 't', 'yes', 'y', 'on')}
|
TRUTHYSTRING_TRUE = {s.lower() for s in ('1', 'true', 't', 'yes', 'y', 'on')}
|
||||||
TRUTHYSTRING_NONE = {s.lower() for s in ('null', 'none')}
|
TRUTHYSTRING_NONE = {s.lower() for s in ('null', 'none')}
|
||||||
|
|
||||||
|
USER_ID_CHARACTERS = string.digits + string.ascii_uppercase
|
||||||
|
|
||||||
ADDITIONAL_MIMETYPES = {
|
ADDITIONAL_MIMETYPES = {
|
||||||
'7z': 'archive',
|
'7z': 'archive',
|
||||||
'gz': 'archive',
|
'gz': 'archive',
|
||||||
|
|
|
@ -53,12 +53,15 @@ class ObjectBase:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not isinstance(author_id, str):
|
if not isinstance(author_id, str):
|
||||||
raise TypeError(f'Author ID must be string, not {type(author_id)}.')
|
raise TypeError(f'Author ID must be {str}, not {type(author_id)}.')
|
||||||
|
|
||||||
author_id = author_id.strip()
|
author_id = author_id.strip()
|
||||||
if author_id == '':
|
if author_id == '':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if not all(c in constants.USER_ID_CHARACTERS for c in author_id):
|
||||||
|
raise ValueError(f'Author ID must consist only of {constants.USER_ID_CHARACTERS}.')
|
||||||
|
|
||||||
return author_id
|
return author_id
|
||||||
|
|
||||||
def get_author(self):
|
def get_author(self):
|
||||||
|
|
|
@ -1235,9 +1235,9 @@ class PDBUserMixin:
|
||||||
User IDs are randomized instead of integers like the other objects,
|
User IDs are randomized instead of integers like the other objects,
|
||||||
so they get their own method.
|
so they get their own method.
|
||||||
'''
|
'''
|
||||||
possible = string.digits + string.ascii_uppercase
|
length = self.config['id_length']
|
||||||
for retry in range(20):
|
for retry in range(20):
|
||||||
user_id = [random.choice(possible) for x in range(self.config['id_length'])]
|
user_id = (random.choice(constants.USER_ID_CHARACTERS) for x in range(length))
|
||||||
user_id = ''.join(user_id)
|
user_id = ''.join(user_id)
|
||||||
|
|
||||||
user_exists = self.sql_select_one('SELECT 1 FROM users WHERE id == ?', [user_id])
|
user_exists = self.sql_select_one('SELECT 1 FROM users WHERE id == ?', [user_id])
|
||||||
|
|
Loading…
Reference in a new issue