"""
Contains various helper functions for common tasks.
"""
import uuid
import logging
logger = logging.getLogger(__name__)
def generate_unique_id() -> str:
"""
Generates a universally unique identifier (UUID).
"""
unique_id = str(uuid.uuid4())
logger.debug(f"Generated unique ID: {unique_id}")
return unique_id
def sanitize_input_string(input_str: str) -> str:
"""
A placeholder for input sanitization.
In a real application, this would involve more robust cleaning
to prevent injection attacks or unexpected data. [15, 33]
"""
if not isinstance(input_str, str):
logger.warning(f"Non-string input provided for sanitization: {type(input_str)}")
return str(input_str) # Convert to string defensively
sanitized_str = input_str.strip()
# Example: Remove potentially harmful characters or sequences
# sanitized_str = sanitized_str.replace("<script>", "")
logger.debug(f"Sanitized input: '{input_str}' -> '{sanitized_str}'")
return sanitized_str
# Example usage (for testing within this module)
if __name__ == "__main__":
print("Generated ID:", generate_unique_id())
print(
"Sanitized string:",
sanitize_input_string(" Hello World! <script>alert('xss')</script> "),
)
print("Sanitized non-string:", sanitize_input_string(123))