From 4ab9369f3c7deabec64d0b5f0f2c434a81f0a16c Mon Sep 17 00:00:00 2001 From: jxhpdt <54163911+jxhpdt@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:29:00 +0800 Subject: [PATCH] style(py): organize style --- python/setup.py | 2 -- python/src/hsocket/hserver.py | 2 +- python/src/hsocket/hsocket.py | 4 ++-- python/tests/file_channel_client_test.py | 2 +- python/tests/file_server_test.py | 2 +- python/tests/tcp_channel_client_test.py | 2 +- python/tests/tcp_reqres_client_test.py | 3 +-- python/tests/tcp_selector_server_test.py | 4 +++- python/tests/tcp_threading_server_test.py | 4 +++- python/tests/udp_channel_client_test.py | 2 +- python/tests/udp_reqres_client_test.py | 3 +-- python/tests/udp_server_test.py | 1 + 12 files changed, 16 insertions(+), 15 deletions(-) diff --git a/python/setup.py b/python/setup.py index 16a7e81..733ff74 100644 --- a/python/setup.py +++ b/python/setup.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from setuptools import setup, find_packages - NAME = "hsocket" VERSION = "1.0.0" DESCRIPTION = "hsocket for python" @@ -9,7 +8,6 @@ AUTHOR_EMAIL = "jxh0615@163.com" URL = "https://github.com/pdt012/HSocket" - setup( name=NAME, version=VERSION, diff --git a/python/src/hsocket/hserver.py b/python/src/hsocket/hserver.py index 087795a..58d26f4 100644 --- a/python/src/hsocket/hserver.py +++ b/python/src/hsocket/hserver.py @@ -292,7 +292,7 @@ def callback_write(self, conn: HTcpSocket): # 主动关闭连接后会进入以下代码段 self.remove(conn) print("connection closed (write): {}".format(addr)) - + def remove(self, conn: HTcpSocket): self.selector.unregister(conn) del self.msgs[conn] diff --git a/python/src/hsocket/hsocket.py b/python/src/hsocket/hsocket.py index 6ad12df..4bf22e9 100644 --- a/python/src/hsocket/hsocket.py +++ b/python/src/hsocket/hsocket.py @@ -134,7 +134,7 @@ def recvFile(self) -> str: return down_path else: return "" - + def sendFiles(self, path_list: BinaryIO, filename_list: str, succeed_path_list_out: list[str]): """发送多个文件 @@ -167,7 +167,7 @@ def sendFiles(self, path_list: BinaryIO, filename_list: str, succeed_path_list_o with fin: self.sendFile(fin, filename) succeed_path_list_out.append(path) - + def recvFiles(self, download_path_list_out: list[str]): """接收多个文件 diff --git a/python/tests/file_channel_client_test.py b/python/tests/file_channel_client_test.py index 5b4b25c..bd84c2e 100644 --- a/python/tests/file_channel_client_test.py +++ b/python/tests/file_channel_client_test.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hclient import HTcpChannelClient from tests.file_client_test import file_test - if __name__ == '__main__': channel_client = HTcpChannelClient() file_test(channel_client) diff --git a/python/tests/file_server_test.py b/python/tests/file_server_test.py index f1817a6..f0ad0ad 100644 --- a/python/tests/file_server_test.py +++ b/python/tests/file_server_test.py @@ -20,7 +20,7 @@ def onMessageReceived(conn: HTcpSocket, msg: Message): print(f"recv files {paths}") case 111: # 下载 paths = server.sendfiles(conn, ["testfile/test1.txt", "testfile/test2.txt"], - ["test1_by_server.txt", "test2_by_server.txt"]) + ["test1_by_server.txt", "test2_by_server.txt"]) print(f"send files {paths}") case _: pass diff --git a/python/tests/tcp_channel_client_test.py b/python/tests/tcp_channel_client_test.py index e0eccfd..90c0055 100644 --- a/python/tests/tcp_channel_client_test.py +++ b/python/tests/tcp_channel_client_test.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hclient import HTcpChannelClient from src.hsocket.hsocket import Message @@ -31,4 +32,3 @@ def onMessageReceived(msg: "Message"): except Exception as e: print(print_exc()) input("press enter to exit") - diff --git a/python/tests/tcp_reqres_client_test.py b/python/tests/tcp_reqres_client_test.py index 84e3503..1218a4c 100644 --- a/python/tests/tcp_reqres_client_test.py +++ b/python/tests/tcp_reqres_client_test.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hclient import HTcpReqResClient from src.hsocket.hsocket import Message from traceback import print_exc - if __name__ == '__main__': client = HTcpReqResClient() client.connect(("127.0.0.1", 40000)) @@ -24,4 +24,3 @@ except Exception as e: print(print_exc()) input("press enter to exit") - diff --git a/python/tests/tcp_selector_server_test.py b/python/tests/tcp_selector_server_test.py index 850b07d..c363232 100644 --- a/python/tests/tcp_selector_server_test.py +++ b/python/tests/tcp_selector_server_test.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hserver import HTcpSelectorServer from src.hsocket.hsocket import HTcpSocket, Message @@ -21,6 +22,7 @@ def disconnect_conn(): sleep(2) print("新的线程中主动断开连接") server.closeconn(conn) + th = Thread(target=disconnect_conn) th.start() return True @@ -43,7 +45,7 @@ def onMessageReceived(conn: HTcpSocket, msg: Message): def onDisconnected(conn: HTcpSocket, addr): print("onDisconnected") - + if __name__ == '__main__': server = HTcpSelectorServer(("127.0.0.1", 40000)) diff --git a/python/tests/tcp_threading_server_test.py b/python/tests/tcp_threading_server_test.py index 369ee4f..8606268 100644 --- a/python/tests/tcp_threading_server_test.py +++ b/python/tests/tcp_threading_server_test.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hserver import HTcpThreadingServer from src.hsocket.hsocket import HTcpSocket, Message @@ -21,6 +22,7 @@ def disconnect_conn(): sleep(2) print("新的线程中主动断开连接") server.closeconn(conn) + th = Thread(target=disconnect_conn) th.start() return True @@ -43,7 +45,7 @@ def onMessageReceived(conn: HTcpSocket, msg: Message): def onDisconnected(conn: HTcpSocket, addr): print("onDisconnected") - + if __name__ == '__main__': server = HTcpThreadingServer(("127.0.0.1", 40000)) diff --git a/python/tests/udp_channel_client_test.py b/python/tests/udp_channel_client_test.py index 522b1d3..73ffd3f 100644 --- a/python/tests/udp_channel_client_test.py +++ b/python/tests/udp_channel_client_test.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hclient import HUdpChannelClient from src.hsocket.hsocket import Message @@ -26,4 +27,3 @@ def onMessageReceived(msg: "Message"): except Exception as e: print(print_exc()) input("press enter to exit") - diff --git a/python/tests/udp_reqres_client_test.py b/python/tests/udp_reqres_client_test.py index 2ac92a2..535db6c 100644 --- a/python/tests/udp_reqres_client_test.py +++ b/python/tests/udp_reqres_client_test.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hclient import HUdpReqResClient from src.hsocket.hsocket import Message from traceback import print_exc - if __name__ == '__main__': client = HUdpReqResClient(("127.0.0.1", 40000)) client.settimeout(5.0) @@ -22,4 +22,3 @@ except Exception as e: print(print_exc()) input("press enter to exit") - diff --git a/python/tests/udp_server_test.py b/python/tests/udp_server_test.py index 9d1203d..1a85819 100644 --- a/python/tests/udp_server_test.py +++ b/python/tests/udp_server_test.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys + sys.path.append("..") from src.hsocket.hserver import HUdpServer from src.hsocket.hsocket import HUdpSocket, Message