Skip to content

Commit

Permalink
style(py): organize style
Browse files Browse the repository at this point in the history
  • Loading branch information
pdt012 committed Mar 14, 2023
1 parent b73e504 commit 4ab9369
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 15 deletions.
2 changes: 0 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
from setuptools import setup, find_packages


NAME = "hsocket"
VERSION = "1.0.0"
DESCRIPTION = "hsocket for python"
AUTHOR = "pdt012"
AUTHOR_EMAIL = "[email protected]"
URL = "https://github.com/pdt012/HSocket"


setup(
name=NAME,
version=VERSION,
Expand Down
2 changes: 1 addition & 1 deletion python/src/hsocket/hserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions python/src/hsocket/hsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
"""发送多个文件
Expand Down Expand Up @@ -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]):
"""接收多个文件
Expand Down
2 changes: 1 addition & 1 deletion python/tests/file_channel_client_test.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/tests/file_server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/tests/tcp_channel_client_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys

sys.path.append("..")
from src.hsocket.hclient import HTcpChannelClient
from src.hsocket.hsocket import Message
Expand Down Expand Up @@ -31,4 +32,3 @@ def onMessageReceived(msg: "Message"):
except Exception as e:
print(print_exc())
input("press enter to exit")

3 changes: 1 addition & 2 deletions python/tests/tcp_reqres_client_test.py
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -24,4 +24,3 @@
except Exception as e:
print(print_exc())
input("press enter to exit")

4 changes: 3 additions & 1 deletion python/tests/tcp_selector_server_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +22,7 @@ def disconnect_conn():
sleep(2)
print("新的线程中主动断开连接")
server.closeconn(conn)

th = Thread(target=disconnect_conn)
th.start()
return True
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion python/tests/tcp_threading_server_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +22,7 @@ def disconnect_conn():
sleep(2)
print("新的线程中主动断开连接")
server.closeconn(conn)

th = Thread(target=disconnect_conn)
th.start()
return True
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion python/tests/udp_channel_client_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import sys

sys.path.append("..")
from src.hsocket.hclient import HUdpChannelClient
from src.hsocket.hsocket import Message
Expand All @@ -26,4 +27,3 @@ def onMessageReceived(msg: "Message"):
except Exception as e:
print(print_exc())
input("press enter to exit")

3 changes: 1 addition & 2 deletions python/tests/udp_reqres_client_test.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -22,4 +22,3 @@
except Exception as e:
print(print_exc())
input("press enter to exit")

1 change: 1 addition & 0 deletions python/tests/udp_server_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4ab9369

Please sign in to comment.