Download src/adware_dashboard/api/utils.py from dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2/resolve/main/src/adware_dashboard/api/utils.py
- Command line
-
hf download hf://spaces/dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2/src/adware_dashboard/api/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/dia-gov/AI-Driven-Zero-Click-Exploit-Deployment-C2/resolve/main/src/adware_dashboard/api/utils.py
1.21 kB
| from functools import wraps | |
| from flask import request, jsonify | |
| from typing import Callable, Type | |
| from marshmallow import Schema, ValidationError | |
| def validate_input(serializer: Type[Schema], partial: bool = False) -> Callable: | |
| """ | |
| Validates the input data using a Marshmallow serializer. | |
| Args: | |
| serializer (Type[Schema]): The Marshmallow serializer to use. | |
| partial (bool, optional): Whether to allow partial updates. Defaults to False. | |
| Returns: | |
| Callable: The decorated function. | |
| """ | |
| def decorator(func): | |
| def wrapper(*args, **kwargs): | |
| try: | |
| data = request.get_json() | |
| if not data: | |
| return jsonify({'error': 'No input data provided'}), 400 | |
| deserialized_data = serializer().load(data, partial=partial) | |
| request.deserialized_data = deserialized_data | |
| return func(*args, **kwargs) | |
| except ValidationError as e: | |
| return jsonify({'error': str(e)}), 400 | |
| except Exception as e: | |
| return jsonify({'error': 'Invalid input data'}), 400 | |
| return wrapper | |
| return decorator | |