<s> """<STR_LIT>""" <EOL> import types <EOL> import socket <EOL> import sys <EOL> import operator <EOL> import struct <EOL> from zope . interface import implements <EOL> from twisted . python . runtime import platformType <EOL> from twisted . python import versions , deprecate <EOL> try : <EOL> from twisted . internet . _newtls import ( <EOL> ConnectionMixin as _TLSConnectionMixin , <EOL> ClientMixin as _TLSClientMixin , <EOL> ServerMixin as _TLSServerMixin ) <EOL> except ImportError : <EOL> try : <EOL> from twisted . internet . _oldtls import ( <EOL> ConnectionMixin as _TLSConnectionMixin , <EOL> ClientMixin as _TLSClientMixin , <EOL> ServerMixin as _TLSServerMixin ) <EOL> except ImportError : <EOL> class _TLSConnectionMixin ( object ) : <EOL> TLS = False <EOL> class _TLSClientMixin ( object ) : <EOL> pass <EOL> class _TLSServerMixin ( object ) : <EOL> pass <EOL> if platformType == '<STR_LIT:win32>' : <EOL> EPERM = object ( ) <EOL> from errno import WSAEINVAL as EINVAL <EOL> from errno import WSAEWOULDBLOCK as EWOULDBLOCK <EOL> from errno import WSAEINPROGRESS as EINPROGRESS <EOL> from errno import WSAEALREADY as EALREADY <EOL> from errno import WSAECONNRESET as ECONNRESET <EOL> from errno import WSAEISCONN as EISCONN <EOL> from errno import WSAENOTCONN as ENOTCONN <EOL> from errno import WSAEINTR as EINTR <EOL> from errno import WSAENOBUFS as ENOBUFS <EOL> from errno import WSAEMFILE as EMFILE <EOL> ENFILE = object ( ) <EOL> ENOMEM = object ( ) <EOL> EAGAIN = EWOULDBLOCK <EOL> from errno import WSAECONNRESET as ECONNABORTED <EOL> from twisted . python . win32 import formatError as strerror <EOL> else : <EOL> from errno import EPERM <EOL> from errno import EINVAL <EOL> from errno import EWOULDBLOCK <EOL> from errno import EINPROGRESS <EOL> from errno import EALREADY <EOL> from errno import ECONNRESET <EOL> from errno import EISCONN <EOL> from errno import ENOTCONN <EOL> from errno import EINTR <EOL> from errno import ENOBUFS <EOL> from errno import EMFILE <EOL> from errno import ENFILE <EOL> from errno import ENOMEM <EOL> from errno import EAGAIN <EOL> from errno import ECONNABORTED <EOL> from os import strerror <EOL> from errno import errorcode <EOL> from twisted . internet import base , address , fdesc <EOL> from twisted . internet . task import deferLater <EOL> from twisted . python import log , failure , reflect <EOL> from twisted . python . util import unsignedID , untilConcludes <EOL> from twisted . internet . error import CannotListenError <EOL> from twisted . internet import abstract , main , interfaces , error <EOL> _AI_NUMERICSERV = getattr ( socket , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> class _SocketCloser ( object ) : <EOL> _socketShutdownMethod = '<STR_LIT>' <EOL> def _closeSocket ( self , orderly ) : <EOL> skt = self . socket <EOL> try : <EOL> if orderly : <EOL> if self . _socketShutdownMethod is not None : <EOL> getattr ( skt , self . _socketShutdownMethod ) ( <NUM_LIT:2> ) <EOL> else : <EOL> self . socket . setsockopt ( socket . SOL_SOCKET , socket . SO_LINGER , <EOL> struct . pack ( "<STR_LIT>" , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> except socket . error : <EOL> pass <EOL> try : <EOL> skt . close ( ) <EOL> except socket . error : <EOL> pass <EOL> class _AbortingMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> _aborting = False <EOL> def abortConnection ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . disconnected or self . _aborting : <EOL> return <EOL> self . _aborting = True <EOL> self . stopReading ( ) <EOL> self . stopWriting ( ) <EOL> self . doRead = lambda * args , ** kwargs : None <EOL> self . doWrite = lambda * args , ** kwargs : None <EOL> self . reactor . callLater ( <NUM_LIT:0> , self . connectionLost , <EOL> failure . Failure ( error . ConnectionAborted ( ) ) ) <EOL> class Connection ( _TLSConnectionMixin , abstract . FileDescriptor , _SocketCloser , <EOL> _AbortingMixin ) : <EOL> """<STR_LIT>""" <EOL> implements ( interfaces . ITCPTransport , interfaces . ISystemHandle ) <EOL> def __init__ ( self , skt , protocol , reactor = None ) : <EOL> abstract . FileDescriptor . __init__ ( self , reactor = reactor ) <EOL> self . socket = skt <EOL> self . socket . setblocking ( <NUM_LIT:0> ) <EOL> self . fileno = skt . fileno <EOL> self . protocol = protocol <EOL> def getHandle ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . socket <EOL> def doRead ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> data = self . socket . recv ( self . bufferSize ) <EOL> except socket . error , se : <EOL> if se . args [ <NUM_LIT:0> ] == EWOULDBLOCK : <EOL> return <EOL> else : <EOL> return main . CONNECTION_LOST <EOL> return self . _dataReceived ( data ) <EOL> def _dataReceived ( self , data ) : <EOL> if not data : <EOL> return main . CONNECTION_DONE <EOL> rval = self . protocol . dataReceived ( data ) <EOL> if rval is not None : <EOL> offender = self . protocol . dataReceived <EOL> warningFormat = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> warningString = deprecate . getDeprecationWarningString ( <EOL> offender , versions . Version ( '<STR_LIT>' , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:0> ) , <EOL> format = warningFormat ) <EOL> deprecate . warnAboutFunction ( offender , warningString ) <EOL> return rval <EOL> def writeSomeData ( self , data ) : <EOL> """<STR_LIT>""" <EOL> limitedData = buffer ( data , <NUM_LIT:0> , self . SEND_LIMIT ) <EOL> try : <EOL> return untilConcludes ( self . socket . send , limitedData ) <EOL> except socket . error , se : <EOL> if se . args [ <NUM_LIT:0> ] in ( EWOULDBLOCK , ENOBUFS ) : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return main . CONNECTION_LOST <EOL> def _closeWriteConnection ( self ) : <EOL> try : <EOL> getattr ( self . socket , self . _socketShutdownMethod ) ( <NUM_LIT:1> ) <EOL> except socket . error : <EOL> pass <EOL> p = interfaces . IHalfCloseableProtocol ( self . protocol , None ) <EOL> if p : <EOL> try : <EOL> p . writeConnectionLost ( ) <EOL> except : <EOL> f = failure . Failure ( ) <EOL> log . err ( ) <EOL> self . connectionLost ( f ) <EOL> def readConnectionLost ( self , reason ) : <EOL> p = interfaces . IHalfCloseableProtocol ( self . protocol , None ) <EOL> if p : <EOL> try : <EOL> p . readConnectionLost ( ) <EOL> except : <EOL> log . err ( ) <EOL> self . connectionLost ( failure . Failure ( ) ) <EOL> else : <EOL> self . connectionLost ( reason ) <EOL> def connectionLost ( self , reason ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> return <EOL> abstract . FileDescriptor . connectionLost ( self , reason ) <EOL> self . _closeSocket ( not reason . check ( error . ConnectionAborted ) ) <EOL> protocol = self . protocol <EOL> del self . protocol <EOL> del self . socket <EOL> del self . fileno <EOL> protocol . connectionLost ( reason ) <EOL> logstr = "<STR_LIT>" <EOL> def logPrefix ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . logstr <EOL> def getTcpNoDelay ( self ) : <EOL> return operator . truth ( self . socket . getsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY ) ) <EOL> def setTcpNoDelay ( self , enabled ) : <EOL> self . socket . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , enabled ) <EOL> def getTcpKeepAlive ( self ) : <EOL> return operator . truth ( self . socket . getsockopt ( socket . SOL_SOCKET , <EOL> socket . SO_KEEPALIVE ) ) <EOL> def setTcpKeepAlive ( self , enabled ) : <EOL> self . socket . setsockopt ( socket . SOL_SOCKET , socket . SO_KEEPALIVE , enabled ) <EOL> class _BaseBaseClient ( object ) : <EOL> """<STR_LIT>""" <EOL> addressFamily = socket . AF_INET <EOL> socketType = socket . SOCK_STREAM <EOL> def _finishInit ( self , whenDone , skt , error , reactor ) : <EOL> """<STR_LIT>""" <EOL> if whenDone : <EOL> self . _commonConnection . __init__ ( self , skt , None , reactor ) <EOL> reactor . callLater ( <NUM_LIT:0> , whenDone ) <EOL> else : <EOL> reactor . callLater ( <NUM_LIT:0> , self . failIfNotConnected , error ) <EOL> def resolveAddress ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _requiresResolution : <EOL> d = self . reactor . resolve ( self . addr [ <NUM_LIT:0> ] ) <EOL> d . addCallback ( lambda n : ( n , ) + self . addr [ <NUM_LIT:1> : ] ) <EOL> d . addCallbacks ( self . _setRealAddress , self . failIfNotConnected ) <EOL> else : <EOL> self . _setRealAddress ( self . addr ) <EOL> def _setRealAddress ( self , address ) : <EOL> """<STR_LIT>""" <EOL> self . realAddress = address <EOL> self . doConnect ( ) <EOL> def failIfNotConnected ( self , err ) : <EOL> """<STR_LIT>""" <EOL> if ( self . connected or self . disconnected or <EOL> not hasattr ( self , "<STR_LIT>" ) ) : <EOL> return <EOL> self . _stopReadingAndWriting ( ) <EOL> try : <EOL> self . _closeSocket ( True ) <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> self . _collectSocketDetails ( ) <EOL> self . connector . connectionFailed ( failure . Failure ( err ) ) <EOL> del self . connector <EOL> def stopConnecting ( self ) : <EOL> """<STR_LIT>""" <EOL> self . failIfNotConnected ( error . UserError ( ) ) <EOL> def connectionLost ( self , reason ) : <EOL> """<STR_LIT>""" <EOL> if not self . connected : <EOL> self . failIfNotConnected ( error . ConnectError ( string = reason ) ) <EOL> else : <EOL> self . _commonConnection . connectionLost ( self , reason ) <EOL> self . connector . connectionLost ( reason ) <EOL> class BaseClient ( _BaseBaseClient , _TLSClientMixin , Connection ) : <EOL> """<STR_LIT>""" <EOL> _base = Connection <EOL> _commonConnection = Connection <EOL> def _stopReadingAndWriting ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> self . stopReading ( ) <EOL> self . stopWriting ( ) <EOL> def _collectSocketDetails ( self ) : <EOL> """<STR_LIT>""" <EOL> del self . socket , self . fileno <EOL> def createInternetSocket ( self ) : <EOL> """<STR_LIT>""" <EOL> s = socket . socket ( self . addressFamily , self . socketType ) <EOL> s . setblocking ( <NUM_LIT:0> ) <EOL> fdesc . _setCloseOnExec ( s . fileno ( ) ) <EOL> return s <EOL> def doConnect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . doWrite = self . doConnect <EOL> self . doRead = self . doConnect <EOL> if not hasattr ( self , "<STR_LIT>" ) : <EOL> return <EOL> err = self . socket . getsockopt ( socket . SOL_SOCKET , socket . SO_ERROR ) <EOL> if err : <EOL> self . failIfNotConnected ( error . getConnectError ( ( err , strerror ( err ) ) ) ) <EOL> return <EOL> try : <EOL> connectResult = self . socket . connect_ex ( self . realAddress ) <EOL> except socket . error , se : <EOL> connectResult = se . args [ <NUM_LIT:0> ] <EOL> if connectResult : <EOL> if connectResult == EISCONN : <EOL> pass <EOL> elif ( ( connectResult in ( EWOULDBLOCK , EINPROGRESS , EALREADY ) ) or <EOL> ( connectResult == EINVAL and platformType == "<STR_LIT:win32>" ) ) : <EOL> self . startReading ( ) <EOL> self . startWriting ( ) <EOL> return <EOL> else : <EOL> self . failIfNotConnected ( error . getConnectError ( ( connectResult , strerror ( connectResult ) ) ) ) <EOL> return <EOL> del self . doWrite <EOL> del self . doRead <EOL> self . stopReading ( ) <EOL> self . stopWriting ( ) <EOL> self . _connectDone ( ) <EOL> def _connectDone ( self ) : <EOL> """<STR_LIT>""" <EOL> self . protocol = self . connector . buildProtocol ( self . getPeer ( ) ) <EOL> self . connected = <NUM_LIT:1> <EOL> logPrefix = self . _getLogPrefix ( self . protocol ) <EOL> self . logstr = "<STR_LIT>" % logPrefix <EOL> self . startReading ( ) <EOL> self . protocol . makeConnection ( self ) <EOL> _NUMERIC_ONLY = socket . AI_NUMERICHOST | _AI_NUMERICSERV <EOL> def _resolveIPv6 ( ip , port ) : <EOL> """<STR_LIT>""" <EOL> return socket . getaddrinfo ( ip , port , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , _NUMERIC_ONLY ) [ <NUM_LIT:0> ] [ <NUM_LIT:4> ] <EOL> class _BaseTCPClient ( object ) : <EOL> """<STR_LIT>""" <EOL> _addressType = address . IPv4Address <EOL> def __init__ ( self , host , port , bindAddress , connector , reactor = None ) : <EOL> self . connector = connector <EOL> self . addr = ( host , port ) <EOL> whenDone = self . resolveAddress <EOL> err = None <EOL> skt = None <EOL> if abstract . isIPAddress ( host ) : <EOL> self . _requiresResolution = False <EOL> elif abstract . isIPv6Address ( host ) : <EOL> self . _requiresResolution = False <EOL> self . addr = _resolveIPv6 ( host , port ) <EOL> self . addressFamily = socket . AF_INET6 <EOL> self . _addressType = address . IPv6Address <EOL> else : <EOL> self . _requiresResolution = True <EOL> try : <EOL> skt = self . createInternetSocket ( ) <EOL> except socket . error , se : <EOL> err = error . ConnectBindError ( se . args [ <NUM_LIT:0> ] , se . args [ <NUM_LIT:1> ] ) <EOL> whenDone = None <EOL> if whenDone and bindAddress is not None : <EOL> try : <EOL> if abstract . isIPv6Address ( bindAddress [ <NUM_LIT:0> ] ) : <EOL> bindinfo = _resolveIPv6 ( * bindAddress ) <EOL> else : <EOL> bindinfo = bindAddress <EOL> skt . bind ( bindinfo ) <EOL> except socket . error , se : <EOL> err = error . ConnectBindError ( se . args [ <NUM_LIT:0> ] , se . args [ <NUM_LIT:1> ] ) <EOL> whenDone = None <EOL> self . _finishInit ( whenDone , skt , err , reactor ) <EOL> def getHost ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _addressType ( '<STR_LIT>' , * self . socket . getsockname ( ) [ : <NUM_LIT:2> ] ) <EOL> def getPeer ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _addressType ( '<STR_LIT>' , * self . realAddress [ : <NUM_LIT:2> ] ) <EOL> def __repr__ ( self ) : <EOL> s = '<STR_LIT>' % ( self . __class__ , self . addr , unsignedID ( self ) ) <EOL> return s <EOL> class Client ( _BaseTCPClient , BaseClient ) : <EOL> """<STR_LIT>""" <EOL> class Server ( _TLSServerMixin , Connection ) : <EOL> """<STR_LIT>""" <EOL> _base = Connection <EOL> _addressType = address . IPv4Address <EOL> def __init__ ( self , sock , protocol , client , server , sessionno , reactor ) : <EOL> """<STR_LIT>""" <EOL> Connection . __init__ ( self , sock , protocol , reactor ) <EOL> if len ( client ) != <NUM_LIT:2> : <EOL> self . _addressType = address . IPv6Address <EOL> self . server = server <EOL> self . client = client <EOL> self . sessionno = sessionno <EOL> self . hostname = client [ <NUM_LIT:0> ] <EOL> logPrefix = self . _getLogPrefix ( self . protocol ) <EOL> self . logstr = "<STR_LIT>" % ( logPrefix , <EOL> sessionno , <EOL> self . hostname ) <EOL> if self . server is not None : <EOL> self . repstr = "<STR_LIT>" % ( self . protocol . __class__ . __name__ , <EOL> self . sessionno , <EOL> self . server . _realPortNumber ) <EOL> self . startReading ( ) <EOL> self . connected = <NUM_LIT:1> <EOL> def __repr__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . repstr <EOL> @ classmethod <EOL> def _fromConnectedSocket ( cls , fileDescriptor , addressFamily , factory , <EOL> reactor ) : <EOL> """<STR_LIT>""" <EOL> addressType = address . IPv4Address <EOL> if addressFamily == socket . AF_INET6 : <EOL> addressType = address . IPv6Address <EOL> skt = socket . fromfd ( fileDescriptor , addressFamily , socket . SOCK_STREAM ) <EOL> addr = skt . getpeername ( ) <EOL> protocolAddr = addressType ( '<STR_LIT>' , addr [ <NUM_LIT:0> ] , addr [ <NUM_LIT:1> ] ) <EOL> localPort = skt . getsockname ( ) [ <NUM_LIT:1> ] <EOL> protocol = factory . buildProtocol ( protocolAddr ) <EOL> if protocol is None : <EOL> skt . close ( ) <EOL> return <EOL> self = cls ( skt , protocol , addr , None , addr [ <NUM_LIT:1> ] , reactor ) <EOL> self . repstr = "<STR_LIT>" % ( <EOL> self . protocol . __class__ . __name__ , self . sessionno , localPort ) <EOL> protocol . makeConnection ( self ) <EOL> return self <EOL> def getHost ( self ) : <EOL> """<STR_LIT>""" <EOL> host , port = self . socket . getsockname ( ) [ : <NUM_LIT:2> ] <EOL> return self . _addressType ( '<STR_LIT>' , host , port ) <EOL> def getPeer ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _addressType ( '<STR_LIT>' , * self . client [ : <NUM_LIT:2> ] ) <EOL> class Port ( base . BasePort , _SocketCloser ) : <EOL> """<STR_LIT>""" <EOL> implements ( interfaces . IListeningPort ) <EOL> socketType = socket . SOCK_STREAM <EOL> transport = Server <EOL> sessionno = <NUM_LIT:0> <EOL> interface = '<STR_LIT>' <EOL> backlog = <NUM_LIT:50> <EOL> _type = '<STR_LIT>' <EOL> _realPortNumber = None <EOL> _preexistingSocket = None <EOL> addressFamily = socket . AF_INET <EOL> _addressType = address . IPv4Address <EOL> def __init__ ( self , port , factory , backlog = <NUM_LIT:50> , interface = '<STR_LIT>' , reactor = None ) : <EOL> """<STR_LIT>""" <EOL> base . BasePort . __init__ ( self , reactor = reactor ) <EOL> self . port = port <EOL> self . factory = factory <EOL> self . backlog = backlog <EOL> if abstract . isIPv6Address ( interface ) : <EOL> self . addressFamily = socket . AF_INET6 <EOL> self . _addressType = address . IPv6Address <EOL> self . interface = interface <EOL> @ classmethod <EOL> def _fromListeningDescriptor ( cls , reactor , fd , addressFamily , factory ) : <EOL> """<STR_LIT>""" <EOL> port = socket . fromfd ( fd , addressFamily , cls . socketType ) <EOL> interface = port . getsockname ( ) [ <NUM_LIT:0> ] <EOL> self = cls ( None , factory , None , interface , reactor ) <EOL> self . _preexistingSocket = port <EOL> return self <EOL> def __repr__ ( self ) : <EOL> if self . _realPortNumber is not None : <EOL> return "<STR_LIT>" % ( self . __class__ , <EOL> self . factory . __class__ , self . _realPortNumber ) <EOL> else : <EOL> return "<STR_LIT>" % ( self . __class__ , self . factory . __class__ ) <EOL> def createInternetSocket ( self ) : <EOL> s = base . BasePort . createInternetSocket ( self ) <EOL> if platformType == "<STR_LIT>" and sys . platform != "<STR_LIT>" : <EOL> s . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , <NUM_LIT:1> ) <EOL> return s <EOL> def startListening ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _preexistingSocket is None : <EOL> try : <EOL> skt = self . createInternetSocket ( ) <EOL> if self . addressFamily == socket . AF_INET6 : <EOL> addr = _resolveIPv6 ( self . interface , self . port ) <EOL> else : <EOL> addr = ( self . interface , self . port ) <EOL> skt . bind ( addr ) <EOL> except socket . error , le : <EOL> raise CannotListenError , ( self . interface , self . port , le ) <EOL> skt . listen ( self . backlog ) <EOL> else : <EOL> skt = self . _preexistingSocket <EOL> self . _preexistingSocket = None <EOL> self . _socketShutdownMethod = None <EOL> self . _realPortNumber = skt . getsockname ( ) [ <NUM_LIT:1> ] <EOL> log . msg ( "<STR_LIT>" % ( <EOL> self . _getLogPrefix ( self . factory ) , self . _realPortNumber ) ) <EOL> self . factory . doStart ( ) <EOL> self . connected = True <EOL> self . socket = skt <EOL> self . fileno = self . socket . fileno <EOL> self . numberAccepts = <NUM_LIT:100> <EOL> self . startReading ( ) <EOL> def _buildAddr ( self , address ) : <EOL> host , port = address [ : <NUM_LIT:2> ] <EOL> return self . _addressType ( '<STR_LIT>' , host , port ) <EOL> def doRead ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if platformType == "<STR_LIT>" : <EOL> numAccepts = self . numberAccepts <EOL> else : <EOL> numAccepts = <NUM_LIT:1> <EOL> for i in range ( numAccepts ) : <EOL> if self . disconnecting : <EOL> return <EOL> try : <EOL> skt , addr = self . socket . accept ( ) <EOL> except socket . error , e : <EOL> if e . args [ <NUM_LIT:0> ] in ( EWOULDBLOCK , EAGAIN ) : <EOL> self . numberAccepts = i <EOL> break <EOL> elif e . args [ <NUM_LIT:0> ] == EPERM : <EOL> continue <EOL> elif e . args [ <NUM_LIT:0> ] in ( EMFILE , ENOBUFS , ENFILE , ENOMEM , ECONNABORTED ) : <EOL> log . msg ( "<STR_LIT>" % ( <EOL> errorcode [ e . args [ <NUM_LIT:0> ] ] , ) ) <EOL> break <EOL> raise <EOL> fdesc . _setCloseOnExec ( skt . fileno ( ) ) <EOL> protocol = self . factory . buildProtocol ( self . _buildAddr ( addr ) ) <EOL> if protocol is None : <EOL> skt . close ( ) <EOL> continue <EOL> s = self . sessionno <EOL> self . sessionno = s + <NUM_LIT:1> <EOL> transport = self . transport ( skt , protocol , addr , self , s , self . reactor ) <EOL> protocol . makeConnection ( transport ) <EOL> else : <EOL> self . numberAccepts = self . numberAccepts + <NUM_LIT:20> <EOL> except : <EOL> log . deferr ( ) <EOL> def loseConnection ( self , connDone = failure . Failure ( main . CONNECTION_DONE ) ) : <EOL> """<STR_LIT>""" <EOL> self . disconnecting = True <EOL> self . stopReading ( ) <EOL> if self . connected : <EOL> self . deferred = deferLater ( <EOL> self . reactor , <NUM_LIT:0> , self . connectionLost , connDone ) <EOL> return self . deferred <EOL> stopListening = loseConnection <EOL> def _logConnectionLostMsg ( self ) : <EOL> """<STR_LIT>""" <EOL> log . msg ( '<STR_LIT>' % ( self . _type , self . _realPortNumber ) ) <EOL> def connectionLost ( self , reason ) : <EOL> """<STR_LIT>""" <EOL> self . _logConnectionLostMsg ( ) <EOL> self . _realPortNumber = None <EOL> base . BasePort . connectionLost ( self , reason ) <EOL> self . connected = False <EOL> self . _closeSocket ( True ) <EOL> del self . socket <EOL> del self . fileno <EOL> try : <EOL> self . factory . doStop ( ) <EOL> finally : <EOL> self . disconnecting = False <EOL> def logPrefix ( self ) : <EOL> """<STR_LIT>""" <EOL> return reflect . qual ( self . factory . __class__ ) <EOL> def getHost ( self ) : <EOL> """<STR_LIT>""" <EOL> host , port = self . socket . getsockname ( ) [ : <NUM_LIT:2> ] <EOL> return self . _addressType ( '<STR_LIT>' , host , port ) <EOL> class Connector ( base . BaseConnector ) : <EOL> """<STR_LIT>""" <EOL> _addressType = address . IPv4Address <EOL> def __init__ ( self , host , port , factory , timeout , bindAddress , reactor = None ) : <EOL> if isinstance ( port , types . StringTypes ) : <EOL> try : <EOL> port = socket . getservbyname ( port , '<STR_LIT>' ) <EOL> except socket . error , e : <EOL> raise error . ServiceNameUnknownError ( string = "<STR_LIT>" % ( e , port ) ) <EOL> self . host , self . port = host , port <EOL> if abstract . isIPv6Address ( host ) : <EOL> self . _addressType = address . IPv6Address <EOL> self . bindAddress = bindAddress <EOL> base . BaseConnector . __init__ ( self , factory , timeout , reactor ) <EOL> def _makeTransport ( self ) : <EOL> """<STR_LIT>""" <EOL> return Client ( self . host , self . port , self . bindAddress , self , self . reactor ) <EOL> def getDestination ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _addressType ( '<STR_LIT>' , self . host , self . port ) </s>
