Skip to content

Commit

Permalink
feat: Add special characters to random_string util
Browse files Browse the repository at this point in the history
If you pass argument: special=True, special characters will be added to the generated random string.
Close overhangio#1177
  • Loading branch information
vahid75 committed Dec 15, 2024
1 parent cf536f3 commit aa627fa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tutor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ def ensure_directory_exists(path: str) -> None:
os.makedirs(path)


def random_string(length: int) -> str:
def random_string(length: int, special=False) -> str:
characters = string.ascii_letters + string.digits
if special:
characters += re.sub(r'[\'"]', '', string.punctuation)
return "".join(
[random.choice(string.ascii_letters + string.digits) for _ in range(length)]
[random.choice(characters) for _ in range(length)]
)


Expand Down

0 comments on commit aa627fa

Please sign in to comment.