Support normalising str and Iterable[str] as well
This commit is contained in:
parent
0d696114b2
commit
baa444f25e
@ -1,6 +1,7 @@
|
|||||||
from os.path import basename, dirname
|
from os.path import basename, dirname
|
||||||
from os.path import join as joinpath
|
from os.path import join as joinpath
|
||||||
from re import sub
|
from re import sub
|
||||||
|
from collections.abc import Iterable
|
||||||
|
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
@ -29,8 +30,19 @@ class Normalisename:
|
|||||||
def whitelist(self):
|
def whitelist(self):
|
||||||
return self._whitelist.union({self.separator})
|
return self._whitelist.union({self.separator})
|
||||||
|
|
||||||
def __call__(self, paths):
|
def __call__(self, path_or_paths):
|
||||||
|
if isinstance(path_or_paths, str):
|
||||||
|
self.normalise(path_or_paths)
|
||||||
|
elif isinstance(path_or_paths, Iterable):
|
||||||
|
self.normalise_all(path_or_paths)
|
||||||
|
else:
|
||||||
|
raise ValueError('Argument must be str Iterable[str]!')
|
||||||
|
|
||||||
|
def normalise_all(self, paths):
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
self.normalise(path)
|
||||||
|
|
||||||
|
def normalise(self, path):
|
||||||
directory = dirname(path)
|
directory = dirname(path)
|
||||||
filename = basename(path)
|
filename = basename(path)
|
||||||
normalpath = joinpath(directory, self.normalname(filename))
|
normalpath = joinpath(directory, self.normalname(filename))
|
||||||
|
Loading…
Reference in New Issue
Block a user