- commit
- 0f449989b9694f52700428b3d0b3ec8c970efb88
- parent
- 3c07b73d144b0855d8f95f5067931fd52f66cfcb
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2014-10-05 08:58
move server protocol extension to protocol
Diffstat
| M | laneya/protocol.py | 18 | ++++++++++++++++-- |
| M | laneya/server.py | 15 | --------------- |
2 files changed, 16 insertions, 17 deletions
diff --git a/laneya/protocol.py b/laneya/protocol.py
@@ -123,6 +123,15 @@ class BaseProtocol(JSONProtocol): 123 123 class ServerProtocol(BaseProtocol): 124 124 """Default implementation of the server protocol.""" 125 125 -1 126 def __init__(self, factory): -1 127 self.factory = factory -1 128 -1 129 def connectionMade(self): -1 130 self.factory.connections.append(self) -1 131 -1 132 def connectionLost(self, reason): -1 133 self.factory.connections.remove(self) -1 134 126 135 def requestReceived(self, user, action, **kwargs): 127 136 """Overwrite this on the server implementation.""" 128 137 raise NotImplementedError @@ -162,8 +171,7 @@ class ServerProtocol(BaseProtocol): 162 171 } 163 172 self.sendJSON(data) 164 173165 -1 def sendUpdate(self, action, **kwargs):166 -1 """Send an update."""-1 174 def _sendUpdate(self, action, **kwargs): 167 175 data = { 168 176 'type': 'update', 169 177 'action': action, @@ -171,6 +179,12 @@ class ServerProtocol(BaseProtocol): 171 179 } 172 180 self.sendJSON(data) 173 181 -1 182 def broadcastUpdate(self, action, **kwargs): -1 183 """Broadcast an update to all connected clients.""" -1 184 -1 185 for connection in self.factory.connections: -1 186 connection._sendUpdate(action, **kwargs) -1 187 174 188 175 189 class ClientProtocol(BaseProtocol): 176 190 """Default implementation of the client protocol."""
diff --git a/laneya/server.py b/laneya/server.py
@@ -9,21 +9,6 @@ import protocol 9 9 10 10 11 11 class ServerProtocol(protocol.ServerProtocol):12 -1 def __init__(self, factory):13 -1 self.factory = factory14 -115 -1 def connectionMade(self):16 -1 self.factory.connections.append(self)17 -118 -1 def connectionLost(self, reason):19 -1 self.factory.connections.remove(self)20 -121 -1 def broadcastUpdate(self, action, **kwargs):22 -1 """Broadcast an update to all connected clients."""23 -124 -1 for connection in self.factory.connections:25 -1 connection.sendUpdate(action, **kwargs)26 -127 12 def requestReceived(self, user, action, **kwargs): # TODO 28 13 if action == 'echo': 29 14 return kwargs