<s> from . connection import Connection <EOL> from . tcp import create , bind <EOL> from . tcp import connect <EOL> from . tcp import MD5 <EOL> from . tcp import nagle <EOL> from . tcp import TTL <EOL> from . tcp import async <EOL> from . tcp import ready <EOL> from . error import NetworkError <EOL> class Outgoing ( Connection ) : <EOL> direction = '<STR_LIT>' <EOL> def __init__ ( self , afi , peer , local , port = <NUM_LIT> , md5 = '<STR_LIT>' , ttl = None ) : <EOL> Connection . __init__ ( self , afi , peer , local ) <EOL> self . logger . wire ( "<STR_LIT>" % ( self . peer , port ) ) <EOL> self . peer = peer <EOL> self . ttl = ttl <EOL> self . afi = afi <EOL> self . md5 = md5 <EOL> self . port = port <EOL> try : <EOL> self . io = create ( afi ) <EOL> MD5 ( self . io , peer , port , md5 ) <EOL> TTL ( self . io , peer , self . ttl ) <EOL> bind ( self . io , local , afi ) <EOL> async ( self . io , peer ) <EOL> connect ( self . io , peer , port , afi , md5 ) <EOL> self . init = True <EOL> except NetworkError , exc : <EOL> self . init = False <EOL> self . close ( ) <EOL> self . logger . wire ( "<STR_LIT>" % ( self . peer , port , str ( exc ) ) ) <EOL> def establish ( self ) : <EOL> if not self . init : <EOL> yield False <EOL> return <EOL> try : <EOL> generator = ready ( self . io ) <EOL> while True : <EOL> connected = generator . next ( ) <EOL> if not connected : <EOL> yield False <EOL> continue <EOL> yield True <EOL> return <EOL> except StopIteration : <EOL> yield False <EOL> return <EOL> nagle ( self . io , self . peer ) <EOL> yield True </s>
