Files
deb-python-eventlet/examples/twisted/twisted_client.py
Davanum Srinivas 80633ab224 python3 compat: 2to3: except E as e: syntax
First step to Python 3 compatibility
"2to3 -w -f except ." See [1]

[1] http://docs.python.org/2/library/2to3.html#fixers
2013-12-03 22:31:55 +04:00

27 lines
903 B
Python

"""Example for GreenTransport and GreenClientCreator.
In this example reactor is started implicitly upon the first
use of a blocking function.
"""
from twisted.internet import ssl
from twisted.internet.error import ConnectionClosed
from eventlet.twistedutil.protocol import GreenClientCreator
from eventlet.twistedutil.protocols.basic import LineOnlyReceiverTransport
from twisted.internet import reactor
# read from TCP connection
conn = GreenClientCreator(reactor).connectTCP('www.google.com', 80)
conn.write('GET / HTTP/1.0\r\n\r\n')
conn.loseWriteConnection()
print conn.read()
# read from SSL connection line by line
conn = GreenClientCreator(reactor, LineOnlyReceiverTransport).connectSSL('sf.net', 443, ssl.ClientContextFactory())
conn.write('GET / HTTP/1.0\r\n\r\n')
try:
for num, line in enumerate(conn):
print '%3s %r' % (num, line)
except ConnectionClosed as ex:
print ex