Update sozo_gen.py
Browse files- sozo_gen.py +0 -58
sozo_gen.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# sozo_gen.py
|
| 2 |
-
# sozo_gen.py
|
| 3 |
|
| 4 |
import os
|
| 5 |
import re
|
|
@@ -258,63 +257,6 @@ def concat_media(file_paths: List[str], output_path: Path):
|
|
| 258 |
finally:
|
| 259 |
list_file.unlink(missing_ok=True)
|
| 260 |
|
| 261 |
-
# DROP-IN FIX - requires zero code changes
|
| 262 |
-
import json as _original_json
|
| 263 |
-
|
| 264 |
-
def safe_json_dumps(obj, **kwargs):
|
| 265 |
-
"""Safe JSON dumps that handles non-serializable types."""
|
| 266 |
-
def make_serializable(item):
|
| 267 |
-
if item is None:
|
| 268 |
-
return None
|
| 269 |
-
elif isinstance(item, bool): # Check bool before int since bool is subclass of int
|
| 270 |
-
return item
|
| 271 |
-
elif isinstance(item, (int, float, str)):
|
| 272 |
-
return item
|
| 273 |
-
elif isinstance(item, (list, tuple)):
|
| 274 |
-
return [make_serializable(x) for x in item]
|
| 275 |
-
elif isinstance(item, dict):
|
| 276 |
-
return {str(k): make_serializable(v) for k, v in item.items()}
|
| 277 |
-
else:
|
| 278 |
-
return str(item)
|
| 279 |
-
|
| 280 |
-
try:
|
| 281 |
-
serializable_obj = make_serializable(obj)
|
| 282 |
-
return _original_json.dumps(serializable_obj, **kwargs)
|
| 283 |
-
except Exception:
|
| 284 |
-
return f'"{str(obj)}"'
|
| 285 |
-
|
| 286 |
-
# Patch json.dumps
|
| 287 |
-
_original_json.dumps = safe_json_dumps
|
| 288 |
-
|
| 289 |
-
# Patch Firebase Reference.update to handle error strings safely
|
| 290 |
-
try:
|
| 291 |
-
from firebase_admin import db
|
| 292 |
-
_original_update = db.Reference.update
|
| 293 |
-
|
| 294 |
-
def safe_update(self, value):
|
| 295 |
-
"""Safe wrapper for Firebase update that cleans error strings."""
|
| 296 |
-
if isinstance(value, dict) and 'error' in value:
|
| 297 |
-
try:
|
| 298 |
-
# Clean the error string for Firebase
|
| 299 |
-
error_str = str(value['error'])
|
| 300 |
-
clean_error = ''.join(char for char in error_str if 32 <= ord(char) <= 126 or char in '\n\r\t ')
|
| 301 |
-
if len(clean_error) > 1000:
|
| 302 |
-
clean_error = clean_error[:1000] + "... (truncated)"
|
| 303 |
-
value = dict(value) # Create a copy
|
| 304 |
-
value['error'] = clean_error
|
| 305 |
-
except Exception:
|
| 306 |
-
# If cleaning fails, use a generic error message
|
| 307 |
-
value = dict(value) # Create a copy
|
| 308 |
-
value['error'] = 'An error occurred during processing'
|
| 309 |
-
|
| 310 |
-
return _original_update(self, value)
|
| 311 |
-
|
| 312 |
-
db.Reference.update = safe_update
|
| 313 |
-
|
| 314 |
-
except ImportError:
|
| 315 |
-
# firebase_admin not available, skip patching
|
| 316 |
-
pass
|
| 317 |
-
|
| 318 |
# --- Main Business Logic Functions for Flask ---
|
| 319 |
|
| 320 |
# ADD THIS NEW HELPER FUNCTION SOMEWHERE NEAR THE TOP OF THE FILE
|
|
|
|
| 1 |
# sozo_gen.py
|
|
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import re
|
|
|
|
| 257 |
finally:
|
| 258 |
list_file.unlink(missing_ok=True)
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
# --- Main Business Logic Functions for Flask ---
|
| 261 |
|
| 262 |
# ADD THIS NEW HELPER FUNCTION SOMEWHERE NEAR THE TOP OF THE FILE
|