summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDenis Bilenko <denis@ag-projects.com>2008-10-29 13:36:02 +0600
committerDenis Bilenko <denis@ag-projects.com>2008-10-29 13:36:02 +0600
commit1f855222a66d3cbaacc920c2c93fca099e019e2b (patch)
tree1882439e23f9b02146f8062743e5fc98c9e79205 /examples
parent78b749bb685effd4337dc22319a274a7e6c0a1e1 (diff)
downloadeventlet-1f855222a66d3cbaacc920c2c93fca099e019e2b.tar.gz
converted twisted_ex2.py to use eventlet.twisteds.basic
Diffstat (limited to 'examples')
-rw-r--r--examples/twisted_ex2.py52
1 files changed, 3 insertions, 49 deletions
diff --git a/examples/twisted_ex2.py b/examples/twisted_ex2.py
index 6c7cf88..f5282df 100644
--- a/examples/twisted_ex2.py
+++ b/examples/twisted_ex2.py
@@ -1,53 +1,7 @@
-"wrapping twisted protocol using a channel and block_on()"
-from twisted.internet import pollreactor; pollreactor.install()
-from twisted.internet.protocol import ClientCreator
-from twisted.protocols import basic
-from twisted.internet import reactor
-from twisted.internet.error import ConnectionDone
+from eventlet.twisteds import basic
-from eventlet.api import spawn
-from eventlet.channel import channel
-from eventlet.twisteds.util import block_on
-
-
-class LineOnlyReceiver(basic.LineOnlyReceiver):
-
- def lineReceived(self, line):
- spawn(self.channel.send, line)
-
- def connectionLost(self, reason):
- self.channel.send_exception(reason.value)
-
-
-class line_only_receiver:
-
- def __init__(self, host, port):
- cc = ClientCreator(reactor, LineOnlyReceiver)
- self.protocol = block_on(cc.connectTCP(host, port))
- self.protocol.channel = self.channel = channel()
-
- def readline(self):
- return self.channel.receive()
-
- def send(self, data):
- self.protocol.transport.write(data)
-
- def sendline(self, line):
- self.protocol.sendLine(line)
-
- # iterator protocol:
-
- def __iter__(self):
- return self
-
- def next(self):
- try:
- return self.readline()
- except ConnectionDone:
- raise StopIteration
-
-
-conn = line_only_receiver('www.google.com', 80)
+conn = basic.connectTCP(basic.line_only_receiver, 'www.google.com', 80)
conn.send('GET / HTTP/1.0\r\n\r\n')
for line in conn:
print line
+