35 lines
690 B
Python
35 lines
690 B
Python
"""
|
|
Miscellaneous utilities.
|
|
|
|
---
|
|
|
|
(C) 2020-2025 Sakuragasaki46.
|
|
See LICENSE for copying info.
|
|
"""
|
|
|
|
import re
|
|
from suou import deprecated
|
|
|
|
from .constants import SLUG_RE
|
|
|
|
@deprecated('use suou.makelist() instead')
|
|
def makelist(l):
|
|
if isinstance(l, (str, bytes, bytearray)):
|
|
return [l]
|
|
elif hasattr(l, '__iter__'):
|
|
return list(l)
|
|
elif l:
|
|
return [l]
|
|
else:
|
|
return []
|
|
|
|
|
|
|
|
def parse_tag_list(s: str) -> list[str]:
|
|
l = [x.strip().lower().replace(' ', '-').replace('_', '-').lstrip('#')
|
|
for x in s.split(',') if x]
|
|
if any(not re.fullmatch(SLUG_RE, x) for x in l):
|
|
raise ValueError('illegal characters in tags')
|
|
return l
|
|
|
|
|