flask_more_smorest.utils
Utility functions for Flask-Smorest CRUD operations.
This module provides common utility functions for password hashing and string case conversion.
Functions
|
Check if a password matches a bcrypt hash. |
|
Convert CamelCase string to snake_case. |
|
Convert snake_case string to CamelCase. |
|
Generate a secure bcrypt hash for a password. |
- flask_more_smorest.utils.generate_password_hash(password)[source]
Generate a secure bcrypt hash for a password.
- Parameters:
password (
str|bytes) – The password to hash (string or bytes)- Return type:
- Returns:
The hashed password as bytes
Example
>>> hashed = generate_password_hash("my_secure_password") >>> isinstance(hashed, bytes) True
- flask_more_smorest.utils.check_password_hash(password, hashed)[source]
Check if a password matches a bcrypt hash.
- Parameters:
- Return type:
- Returns:
True if the password matches the hash, False otherwise
Example
>>> hashed = generate_password_hash("password123") >>> check_password_hash("password123", hashed) True >>> check_password_hash("wrong", hashed) False
- flask_more_smorest.utils.convert_snake_to_camel(word)[source]
Convert snake_case string to CamelCase.
- Parameters:
word (
str) – Snake case string to convert- Return type:
- Returns:
CamelCase version of the input string
Example
>>> convert_snake_to_camel("user_profile") 'UserProfile' >>> convert_snake_to_camel("simple") 'simple'
- flask_more_smorest.utils.convert_camel_to_snake(word)[source]
Convert CamelCase string to snake_case.
- Parameters:
word (
str) – CamelCase string to convert- Return type:
- Returns:
snake_case version of the input string
Example
>>> convert_camel_to_snake("UserProfile") 'user_profile' >>> convert_camel_to_snake("APIKey") 'api_key'