Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def main():
sock = await curio.open_connection(
'www.python.org', 443, ssl=True, server_hostname='www.python.org')
async with sock:
await sock.sendall(b'GET / HTTP/1.0\r\nHost: www.python.org\r\n\r\n')
chunks = []
while True:
chunk = await sock.recv(10000)
if not chunk:
break
chunks.append(chunk)
response = b''.join(chunks)
print(response.decode('latin-1'))
async def connect(self):
self.sock = await curio.open_connection(self.host, self.port)
return
async def tcp_connection(address):
"""Async generator reading from tcp network transport layer"""
logger = logging.getLogger('curio.tcp-connection')
logger.debug('... connecting to tcp://{}:{}'.format(*address))
host, port = address
sock = await curio.open_connection(host, port)
async with sock:
while True:
data = await sock.recv(128)
if data:
logger.debug('<<< {!r}'.format(data))
yield data
else:
break
async def open_connection(host, port, **kwargs):
for i in range(2, -1, -1):
try:
return await curio.open_connection(host, port, **kwargs)
except socket.gaierror:
if i == 0:
gvars.logger.debug(f"dns query failed: {host}")
raise
async def connect(self):
self.sock = await curio.open_connection(self.host, self.port)
self.logger.debug('open amqp connection')
# send amqp header frame
await self.send_amqp_procotol_header()
self.logger.debug('send amqp header')
# got start
await self.assert_recv_method(pika.spec.Connection.Start)
self.logger.debug('get amqp connection.Start')
# send start ok back
await self.send_start_ok()
self.logger.debug('send amqp connection.StartOk')
# got tune
await self.assert_recv_method(pika.spec.Connection.Tune)
self.logger.debug('get amqp connection.Tune')
# send tune ok
await self.send_tune_ok()
self.logger.debug('send amqp connection.TuneOk')
async def connect(self):
self.sock = await curio.open_connection(self.host, self.port)
self.logger.debug('open amqp connection')
# send amqp header frame
await self.send_amqp_procotol_header()
self.logger.debug('send amqp header')
# got start
await self.assert_recv_method(pika.spec.Connection.Start)
self.logger.debug('get amqp connection.Start')
# send start ok back
await self.send_start_ok()
self.logger.debug('send amqp connection.StartOk')
# got tune
await self.assert_recv_method(pika.spec.Connection.Tune)
self.logger.debug('get amqp connection.Tune')
# send tune ok
await self.send_tune_ok()
self.logger.debug('send amqp connection.TuneOk')
async def connect(self):
return await curio.open_connection(*self.raddr)