From ad3a608acd7c5f740293addf03f3325d93fae163 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Jul 2025 19:40:25 +0800 Subject: [PATCH] fix --- python_core/ai_video/video_generator.py | 12 +--- test_encoding.py | 84 +++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 test_encoding.py diff --git a/python_core/ai_video/video_generator.py b/python_core/ai_video/video_generator.py index 9fd8d3b..340614f 100644 --- a/python_core/ai_video/video_generator.py +++ b/python_core/ai_video/video_generator.py @@ -391,21 +391,11 @@ def main(): args = parser.parse_args() - print("Parsed arguments successfully") - print(f"Action: {args.action}") - print(f"Image: {args.image}") - print(f"Output: {args.output}") - sys.stdout.flush() - try: - print("Creating VideoGenerator instance...") - sys.stdout.flush() generator = VideoGenerator() - print("VideoGenerator created successfully") - sys.stdout.flush() def progress_callback(message): - ... + print("VideoGenerator created successfully") if args.action == "single": if not args.image or not args.prompt or not args.output: diff --git a/test_encoding.py b/test_encoding.py new file mode 100644 index 0000000..ca36878 --- /dev/null +++ b/test_encoding.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Test script to verify encoding handling between Python and Rust +""" + +import sys +import json +import os + +def test_encoding(): + """Test various encoding scenarios""" + + # Configure encoding + if os.name == 'nt': # Windows + try: + import subprocess + subprocess.run(['chcp', '65001'], shell=True, capture_output=True) + except: + pass + + if hasattr(sys.stdout, 'reconfigure'): + try: + sys.stdout.reconfigure(encoding='utf-8') + sys.stderr.reconfigure(encoding='utf-8') + except: + pass + + # Test cases with various characters + test_cases = [ + {"type": "ascii", "text": "Hello World"}, + {"type": "chinese", "text": "你好世界"}, + {"type": "japanese", "text": "こんにちは"}, + {"type": "emoji", "text": "🎉🚀✅"}, + {"type": "mixed", "text": "Hello 你好 🎉"}, + {"type": "special", "text": "Special chars: àáâãäåæçèéêë"}, + ] + + print("Testing encoding compatibility...") + + for i, test_case in enumerate(test_cases): + # Test regular print + print(f"Test {i+1}: {test_case['type']} - {test_case['text']}") + + # Test JSON-RPC format with ensure_ascii=True + jsonrpc_response = { + "jsonrpc": "2.0", + "id": i, + "result": { + "status": True, + "message": test_case['text'], + "type": test_case['type'] + } + } + + json_str = json.dumps(jsonrpc_response, ensure_ascii=True, separators=(',', ':')) + output_line = f"JSONRPC:{json_str}" + + if hasattr(sys.stdout, 'buffer'): + sys.stdout.buffer.write(output_line.encode('utf-8')) + sys.stdout.buffer.write(b'\n') + sys.stdout.buffer.flush() + else: + print(output_line) + sys.stdout.flush() + + # Test final result + final_result = { + "status": True, + "message": "编码测试完成 - Encoding test completed 🎉", + "test_count": len(test_cases) + } + + result_json = json.dumps(final_result, ensure_ascii=True, indent=2) + if hasattr(sys.stdout, 'buffer'): + sys.stdout.buffer.write(result_json.encode('utf-8')) + sys.stdout.buffer.write(b'\n') + sys.stdout.buffer.flush() + else: + print(result_json) + sys.stdout.flush() + +if __name__ == "__main__": + test_encoding()