- commit
- b3ad561dde23e66cc107d7e340917fe12e6417a1
- parent
- 3cc11dd4392bec713c494075088c0f0f67aee8c3
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2014-10-18 08:37
switch to asyncio
Diffstat
| M | laneya/client.py | 15 | +++++++-------- |
| M | laneya/protocol.py | 7 | +++---- |
| M | laneya/server.py | 20 | +++++++++++--------- |
3 files changed, 21 insertions, 21 deletions
diff --git a/laneya/client.py b/laneya/client.py
@@ -1,6 +1,4 @@1 -1 from twisted.internet.endpoints import TCP4ClientEndpoint2 -1 from twisted.internet import reactor3 -1 from twisted.internet import task-1 1 import trollius as asyncio 4 2 5 3 from dirtywords import Screen 6 4 @@ -44,16 +42,17 @@ class Client(protocol.ClientProtocolFactory): 44 42 45 43 46 44 def main():47 -1 # log.startLogging(sys.stdout)48 -1 client = Client()-1 45 loop = asyncio.get_event_loop() -1 46 -1 47 client = Client(loop) 49 48 client.setup('testuser')50 -1 endpoint = TCP4ClientEndpoint(reactor, 'localhost', 5001)51 -1 endpoint.connect(client)-1 49 coro = loop.create_connection(client.build_protocol, 'localhost', 5001) -1 50 loop.run_until_complete(coro) 52 51 53 52 mainloop = protocol.LoopingCall(loop, client.mainloop) 54 53 mainloop.start(0.02) 55 5456 -1 reactor.run()-1 55 loop.run_forever() 57 56 58 57 59 58 if __name__ == '__main__': # pragma: nocover
diff --git a/laneya/protocol.py b/laneya/protocol.py
@@ -65,8 +65,7 @@ Update 65 65 import json 66 66 import logging 67 6768 -1 from twisted.internet.protocol import Factory69 -1 from twisted.internet import reactor-1 68 import trollius as asyncio 70 69 71 70 import deferred as q 72 71 import actions @@ -248,7 +247,7 @@ class ServerProtocol(BaseProtocol): 248 247 self.send_json(data) 249 248 250 249251 -1 class ServerProtocolFactory(Factory):-1 250 class ServerProtocolFactory(object): 252 251 """Factory for :py:class:`ServerProtocol`.""" 253 252 254 253 def __init__(self): @@ -333,7 +332,7 @@ class ClientProtocol(BaseProtocol): 333 332 return d.promise 334 333 335 334336 -1 class ClientProtocolFactory(Factory):-1 335 class ClientProtocolFactory(object): 337 336 """Factory for :py:class:`ClientProtocol`. 338 337 339 338 We assume that this factory has only one active connection.
diff --git a/laneya/server.py b/laneya/server.py
@@ -1,8 +1,4 @@1 -1 import sys2 -13 -1 from twisted.internet.endpoints import TCP4ServerEndpoint4 -1 from twisted.internet import reactor5 -1 from twisted.internet import task-1 1 import trollius as asyncio 6 2 7 3 import protocol 8 4 @@ -64,15 +60,21 @@ class Server(protocol.ServerProtocolFactory): 64 60 65 61 66 62 def main():67 -1 log.startLogging(sys.stdout)-1 63 loop = asyncio.get_event_loop() -1 64 68 65 server = Server()69 -1 endpoint = TCP4ServerEndpoint(reactor, 5001)70 -1 endpoint.listen(server)-1 66 coro = loop.create_server(server.build_protocol, 'localhost', 5001) -1 67 s = loop.run_until_complete(coro) 71 68 72 69 mainloop = protocol.LoopingCall(loop, server.mainloop) 73 70 mainloop.start(0.1) 74 7175 -1 reactor.run()-1 72 try: -1 73 loop.run_forever() -1 74 finally: -1 75 s.close() -1 76 loop.run_until_complete(s.wait_closed()) -1 77 loop.close() 76 78 77 79 78 80 if __name__ == '__main__': # pragma: nocover