Spaces:
No application file
No application file
File size: 1,172 Bytes
2875866 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import json
import re
import sqlparse
def verify_json_format(text):
"""Check if the text is a valid JSON"""
try:
json.loads(text)
return True
except json.JSONDecodeError:
return False
def verify_sql_query(text):
"""Check if the text is a valid SQL query using sqlparse"""
try:
parsed = sqlparse.parse(text)
if not parsed:
return False
# Basic validation: Check for common SQL commands
tokens = [token.ttype for token in parsed[0].tokens if not token.is_whitespace]
sql_keywords = ["SELECT", "INSERT", "UPDATE", "DELETE", "CREATE", "DROP", "ALTER"]
return any(keyword in text.upper() for keyword in sql_keywords)
except Exception:
return False
def verify_regex(text, pattern):
"""Check if the text matches the given regex pattern"""
try:
return bool(re.search(pattern, text))
except re.error:
return False # Invalid regex pattern
def verify_contains(text, substring):
"""Check if the text contains the given substring (case-insensitive)"""
return substring.lower() in text.lower()
|