-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
183 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import re | ||
from typing import Optional | ||
|
||
|
||
def safe_name(text: Optional[str]) -> str: | ||
"""Sanitizes a human-readable "friendly" name to a safe string. | ||
For example, "Joe's Collection" becomes "joe_s_collection". | ||
Args: | ||
text (Optional[str]): Unsafe text with non-underscore symbols and spaces. | ||
Returns: | ||
str: Sanitized lowercase string with underscores. | ||
""" | ||
return re.sub(r"[^\w]", "_", text or "").lower() | ||
|
||
|
||
def safe_description(text: Optional[str]) -> str: | ||
"""Sanitizes a human-readable long text, such as description. | ||
Args: | ||
text (Optional[str]): Unsafe long text with Jinja syntax. | ||
Returns: | ||
str: Sanitized string with escaped Jinja syntax. | ||
""" | ||
return re.sub(r"{{(.*)}}", r"\1", text or "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.