Skip to content

Commit

Permalink
fix: 修复python接口编码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed May 9, 2024
1 parent e5621f7 commit bc59f72
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sample/python/exec_agent/my_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"x": 200,
"y": 100,
}
print(json.dumps(output))
print(json.dumps(output, ensure_ascii=False))

res = input()
print("maafw return:", res)
6 changes: 3 additions & 3 deletions source/binding/Python/maa/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_task(self, task_name: str, task_param: Dict = {}) -> bool:
Library.framework.MaaSyncContextRunTask(
self._handle,
task_name.encode("utf-8"),
json.dumps(task_param).encode("utf-8"),
json.dumps(task_param, ensure_ascii=False).encode("utf-8"),
)
)

Expand Down Expand Up @@ -62,7 +62,7 @@ def run_recognition(
self._handle,
image_buffer.c_handle,
task_name.encode("utf-8"),
json.dumps(task_param).encode("utf-8"),
json.dumps(task_param, ensure_ascii=False).encode("utf-8"),
rect_buffer.c_handle,
detail_buffer.c_handle,
)
Expand Down Expand Up @@ -94,7 +94,7 @@ def run_action(
Library.framework.MaaSyncContextRunAction(
self._handle,
task_name.encode("utf-8"),
json.dumps(task_param).encode("utf-8"),
json.dumps(task_param, ensure_ascii=False).encode("utf-8"),
rect_buffer.c_handle,
cur_rec_detail.encode("utf-8"),
)
Expand Down
6 changes: 3 additions & 3 deletions source/binding/Python/maa/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def __init__(
str(adb_path).encode("utf-8"),
address.encode("utf-8"),
touch_type | key_type | screencap_type,
json.dumps(config).encode("utf-8"),
json.dumps(config, ensure_ascii=False).encode("utf-8"),
str(agent_path).encode("utf-8"),
self._callback_agent.c_callback,
self._callback_agent.c_callback_arg,
Expand Down Expand Up @@ -321,7 +321,7 @@ def __init__(
str(read_path).encode("utf-8"),
str(write_path).encode("utf-8"),
touch_type | key_type | screencap_type,
json.dumps(config).encode("utf-8"),
json.dumps(config, ensure_ascii=False).encode("utf-8"),
self._callback_agent.c_callback,
self._callback_agent.c_callback_arg,
)
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(
type,
host.encode("utf-8"),
port,
json.dumps(config).encode("utf-8"),
json.dumps(config, ensure_ascii=False).encode("utf-8"),
self._callback_agent.c_callback,
self._callback_agent.c_callback_arg,
)
Expand Down
6 changes: 4 additions & 2 deletions source/binding/Python/maa/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def post_task(self, task_type: str, param: Any = {}) -> Future:
"""

maaid = Library.framework.MaaPostTask(
self._handle, task_type.encode("utf-8"), json.dumps(param).encode("utf-8")
self._handle,
task_type.encode("utf-8"),
json.dumps(param, ensure_ascii=False).encode("utf-8"),
)
return TaskFuture(maaid, self._status, self._set_task_param)

Expand Down Expand Up @@ -203,7 +205,7 @@ def _stop_status(self, id: int) -> ctypes.c_int32:

def _set_task_param(self, id: int, param: Dict) -> bool:
return Library.framework.MaaSetTaskParam(
self._handle, id, json.dumps(param).encode("utf-8")
self._handle, id, json.dumps(param, ensure_ascii=False).encode("utf-8")
)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion source/binding/Python/maa/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def init_option(
return bool(
Library.toolkit.MaaToolkitInitOptionConfig(
str(user_path).encode("utf-8"),
json.dumps(default_config).encode("utf-8"),
json.dumps(default_config, ensure_ascii=False).encode("utf-8"),
)
)

Expand Down
2 changes: 1 addition & 1 deletion test/python/binding_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async def main():
"custom_recognition": "MyRec",
"action": "Custom",
"custom_action": "MyAct",
"custom_action_param": "abcdefg",
"custom_action_param": "👋哈哈哈(*´▽`)ノノ😀",
},
},
)
Expand Down

0 comments on commit bc59f72

Please sign in to comment.