Skip to content

Commit 5e83f18

Browse files
committed
fixed linting and formatting and added type information to proxy
1 parent cf02da4 commit 5e83f18

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

proxies/proxy.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import sys
33
import threading
44

5-
HEX_FILTER = "".join([(len(repr(chr(i))) == 3) and chr(i) or "." for i in range(256)])
5+
HEX_FILTER: str = "".join(
6+
[(len(repr(chr(i))) == 3) and chr(i) or "." for i in range(256)]
7+
)
68

79

8-
def hexdump(src: bytes, length=16, show=True) -> (list | None):
10+
def hexdump(src: bytes | str, length=16, show=True) -> (list | None):
911
if isinstance(src, bytes):
1012
src = src.decode()
1113
results = list()
@@ -51,8 +53,11 @@ def response_handler(buffer: bytes) -> bytes:
5153

5254

5355
def proxy_handler(
54-
client_socket: socket.socket, remote_host: str, remote_port: int, receive_first
55-
):
56+
client_socket: socket.socket,
57+
remote_host: str,
58+
remote_port: int,
59+
receive_first: bool,
60+
) -> None:
5661
remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5762
remote_socket.connect((remote_host, remote_port))
5863

@@ -88,7 +93,13 @@ def proxy_handler(
8893
break
8994

9095

91-
def server_loop(local_host, local_port, remote_host, remote_port, receive_first):
96+
def server_loop(
97+
local_host: str,
98+
local_port: int,
99+
remote_host: str,
100+
remote_port: int,
101+
receive_first: bool,
102+
):
92103
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
93104
try:
94105
server.bind((local_host, local_port))
@@ -102,6 +113,7 @@ def server_loop(local_host, local_port, remote_host, remote_port, receive_first)
102113
server.listen(5)
103114
while True:
104115
client_socket, addr = server.accept()
116+
# print out the local connection information
105117
print("> Received incoming connection from %s:%d" & (addr[0], addr[1]))
106118

107119
proxy_thread = threading.Thread(
@@ -113,7 +125,7 @@ def server_loop(local_host, local_port, remote_host, remote_port, receive_first)
113125

114126
def main():
115127
if len(sys.argv[1:]) != 5:
116-
print("Usage: proxies/proxy.py [localhost] [localport]", end="")
128+
print("Usage: proxies/proxy.py [localhost] [localport]", end=" ")
117129
print("[remotehost] [remoteport] [receive_first]")
118130
print("Example: proxies/proxy.py 127.0.0.1 9000 172.31.134.104 9000 True")
119131
sys.exit(0)

0 commit comments

Comments
 (0)