Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b57e217d authored by IMBERT Matthieu's avatar IMBERT Matthieu
Browse files

[execo_engine] add an optional separator to slugify

parent 52983ca5
No related branches found
No related tags found
No related merge requests found
Pipeline #941572 passed
......@@ -89,9 +89,8 @@ def copy_outputs(stdout_filename, stderr_filename):
# and 0 as the buffer size (unbuffered)
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1 if sys.version_info >= (3,) else 0)
def slugify(value):
"""
Normalizes string representation, converts to lowercase, removes
def slugify(value, separator='-'):
"""Normalizes string representation, converts to lowercase, removes
non-alpha characters, and converts spaces to hyphens.
Intended to convert any object having a relevant string
......@@ -99,15 +98,22 @@ def slugify(value):
more or less inspired / copy pasted from django (see
http://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename-in-python)
:param value: the object to slugify
:param separator: a character to use as separator in the string
output, instead of the default '-'. Be careful to only use one
character and only characters which don't have special meaning
in regular expressions.
"""
if sys.version_info >= (3,):
value = str(value)
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub('[^\w\s-]', '', value).strip().lower()
value = re.sub('[-\s]+', '-', value)
value = re.sub('[' + separator + '\s]+', separator, value)
else:
value = unicode(str(value))
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
value = unicode(re.sub('[-\s]+', '-', value))
value = unicode(re.sub('[' + separator + '\s]+', separator, value))
return value
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment