Skip to content

Instantly share code, notes, and snippets.

View noize-e's full-sized avatar

noiz-e noize-e

View GitHub Profile
@noize-e
noize-e / normalize_str.py
Created February 13, 2019 06:44
Normalize a given string to fit the data it contains, like simple test, or email to a password
def normalize(obj, dict_key=None, regx="text"):
""" This function cleans and normalize a given string. It performs three
main operations: Sets to lower case, strips any trailing whitespace and
finally substracts any character that isn't allowed in the string type
regex, the character is replaced with an empty string.
:param obj: this object can be 'str' or 'dict' instance type.
:type obj:str It performs a directly normalization
:type obj:dict It expects a key ( from 'dict_key' arg ) string
to extract the string to be normalize, otherwise returns None.