Add helpers.collapse_whitespace.
This commit is contained in:
parent
1013fb81c1
commit
b223691107
2 changed files with 8 additions and 7 deletions
|
@ -104,6 +104,11 @@ def chunk_sequence(sequence, chunk_length, allow_incomplete=True):
|
|||
if len(chunk) == chunk_length or allow_incomplete:
|
||||
yield chunk
|
||||
|
||||
def collapse_whitespace(s):
|
||||
s = s.strip()
|
||||
s = re.sub(r'\s+', ' ', s)
|
||||
return s
|
||||
|
||||
def comma_space_split(s):
|
||||
'''
|
||||
Split the string apart by commas and spaces, discarding all extra
|
||||
|
|
|
@ -268,9 +268,7 @@ class Album(ObjectBase, GroupableMixin):
|
|||
if not isinstance(title, str):
|
||||
raise TypeError(f'Title must be {str}, not {type(title)}.')
|
||||
|
||||
title = title.strip()
|
||||
for whitespace in string.whitespace:
|
||||
title = title.replace(whitespace, ' ')
|
||||
title = helpers.collapse_whitespace(title)
|
||||
|
||||
return title
|
||||
|
||||
|
@ -565,9 +563,7 @@ class Bookmark(ObjectBase):
|
|||
if not isinstance(title, str):
|
||||
raise TypeError(f'Title must be {str}, not {type(title)}.')
|
||||
|
||||
title = title.strip()
|
||||
for whitespace in string.whitespace:
|
||||
title = title.replace(whitespace, ' ')
|
||||
title = helpers.collapse_whitespace(title)
|
||||
|
||||
return title
|
||||
|
||||
|
@ -1490,7 +1486,7 @@ class User(ObjectBase):
|
|||
if not isinstance(display_name, str):
|
||||
raise TypeError(f'Display name must be string, not {type(display_name)}.')
|
||||
|
||||
display_name = display_name.strip()
|
||||
display_name = helpers.collapse_whitespace(display_name)
|
||||
|
||||
if display_name == '':
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue