Skip to content

Commit b12e115

Browse files
committed
Refactored to be a workable module
1 parent 3cdd1e4 commit b12e115

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

python-message/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from simpleprotocol import LOG, simpleServer, simpleProtocol

message.py renamed to python-message/message.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def decode(self, message):
2828

2929
def get(self):
3030
result = self.decode(self.socket.readLine())
31-
if self.LOG: print result
31+
if self.LOG: print(result)
3232
return result
3333

3434
def send(self, code, subcode=0, param=[]):

python-message/simpleprotocol.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import .socketwrapper
2+
import .message
3+
4+
LOG = False
5+
6+
class SimpleServer():
7+
8+
def __init__(self, port):
9+
self.port = port
10+
self.socket = socketwrapper.ServerSocket(port=port)
11+
12+
def accept(self):
13+
return SimpleSocket(self.socket.getClientObject())
14+
15+
class SimpleProtocol():
16+
17+
def __init__(self, port):
18+
self.socket = socketwrapper.ClientSocket(port=port)
19+
self.message = message.Message(socket=self.socket)
20+
21+
def __init__(self, socket):
22+
self.socket = socket
23+
self.message = message.Message(socket=self.socket)
24+
25+
def send(self, *args, **kwargs):
26+
self.message.send(*args, **kwargs)
27+
28+
def get(self, *args, **kwargs):
29+
self.message.get(*args, **kwargs)

sockets.py renamed to python-message/socketwrapper.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ def __init__(self, ip='localhost', port=10000):
88
self.sock.bind(self.server_address)
99
self.sock.listen(1)
1010

11-
def getClient(self):
11+
def accept(self):
1212
connection, client_address = self.sock.accept()
1313
return [connection, client_address]
1414

1515
def getClientObject(self):
16-
return self.ServerSocketHandler(*self.getClient())
17-
18-
def startThreadedFunctionWithClient(self, function):
19-
pass
16+
return self.ServerSocketHandler(*self.accept())
2017

2118
class ServerSocketHandler():
2219

0 commit comments

Comments
 (0)