
    h              	         S r SSKJr  SSKrSSKrSSKrSSKrSSKJrJ	r	J
r
JrJrJr  SSKJrJr  SSKrSSKrSSKJrJrJrJrJrJr  SSKJr  SSKJrJrJr  SS	K J!r!J"r"  SS
K#J$r$   SSK%J&r'J(r)J*r+  SSKJ,r,  \$S:X  a6  \." 5       r/SSK0J1r2J3r4J5r6J7r8J9r:J;r<J=r>  \." 5       r?\." 5       r@\>rASSK0JBrC  SSKDJErF  ONSSK0J/r/  SSK0J6r6  SSK0J>r>  SSK0J4r4  SSK0J2r2  SSK0J8r8  SSK0J<r<  SSK0J:r:  SSK0J?r?  SS K0J@r@  SS!K0JArA  SS"K0JCrC  SS#KJFrF  SS$K0JGrG  SS%KHJIrIJJrJJKrKJLrLJMrMJNrN  SS&KOJPrP  SS'KJQrQ  SS(KRJSrS  SS)K JTrTJUrUJVrV  SS*KWJXrX  \Y" \S+S5      rZS, r[S- r\S. r] " S/ S05      r^ " S1 S25      r_\" \,\\5       " S3 S4\)\IR                  \^\_5      5       ra " S5 S65      rb " S7 S8\b\'\a5      rc\R                  \Z-  reS9 rf " S: S;5      rg " S< S=\g\c5      rh " S> S?\+\a5      ri " S@ SA\5      rj " SB SC\R                  5      rk\" \j5      \R                  " SDSE9 " SF SG5      5       5       rm\" \j5       " SH SI5      5       rn\$S:X  a  \n" 5       roO	\m" SJ 5      ro\:\<\?\@\C4rp\R                  " SDSE9 " SK SL5      5       rqSM rr\" \5       " SN SO\KR                  \^5      5       rt " SP SQ\KR                  5      rvg! \- a$    \r, " S S5      r) " S S5      r' " S S5      r+ GNTf = f)Rzt
Various asynchronous TCP/IP classes.

End users shouldn't use this module directly - use the reactor APIs instead.
    )annotationsN)AnyCallableClassVarListOptionalUnion)	Interfaceimplementer)IHalfCloseableProtocolIListeningPort	IProtocolIReactorTCPISystemHandleITCPTransport)ClientFactory)ILogObserverLogEventLogger)	deprecateversions)platformType)ClientMixinConnectionMixinServerMixin)ITLSTransportc                      \ rS rSrSrSrg)_TLSConnectionMixin2   F N)__name__
__module____qualname____firstlineno__TLS__static_attributes__r        [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/internet/tcp.pyr   r   2   s    r'   r   c                      \ rS rSrSrg)_TLSClientMixin5   r    Nr!   r"   r#   r$   r&   r    r'   r(   r*   r*   5       r'   r*   c                      \ rS rSrSrg)_TLSServerMixin8   r    Nr,   r    r'   r(   r/   r/   8   r-   r'   r/   win32)WSAEALREADYWSAEINPROGRESS	WSAEINVAL
WSAEISCONN	WSAEMFILE
WSAENOBUFSWSAEWOULDBLOCK)WSAECONNRESET)formatError)EPERM)EINVAL)EWOULDBLOCK)EINPROGRESS)EALREADY)EISCONN)ENOBUFS)EMFILE)ENFILE)ENOMEM)EAGAIN)ECONNABORTED)strerror)	errorcode)abstractaddressbaseerrorfdescmain)CannotListenError)Protocol)
deferLater)failurelogreflect)untilConcludesAI_NUMERICSERVc                    [        U 5      S:X  aT  [        R                  " U [        R                  [        R                  -  5      S   n[        U/[        U SS 5      -   5      $ U SS $ )aM  
Return a 2-tuple of socket IP and port for IPv4 and a 4-tuple of
socket IP, port, flowInfo, and scopeID for IPv6.  For IPv6, it
returns the interface portion (the part after the %) as a part of
the IPv6 address, which Python 3.7+ does not include.

@param addr: A 2-tuple for IPv4 information or a 4-tuple for IPv6
    information.
   r      N   )lensocketgetnameinfoNI_NUMERICHOSTNI_NUMERICSERVtuplelist)addrhosts     r(   _getrealnamerd   p   sc     4yA~!!$(=(=@U@U(UV
 dVd48n,--BQxr'   c                4    [        U R                  5       5      $ z
See L{_getrealname}.
)rd   getpeernameskts    r(   _getpeernamerj           )**r'   c                4    [        U R                  5       5      $ rf   )rd   getsocknamerh   s    r(   _getsocknamern      rk   r'   c                  "    \ rS rSrSrSrS rSrg)_SocketCloser   z
@ivar _shouldShutdown: Set to C{True} if C{shutdown} should be called
    before calling C{close} on the underlying socket.
@type _shouldShutdown: C{bool}
Tc           	     t   U R                   n U(       a#  U R                  (       a  UR                  S5        OPU R                   R                  [         R                  [         R
                  [        R                  " SSS5      5          UR                  5         g ! [         a     Nf = f! [         a     g f = f)NrZ   iirY   r   )
r\   _shouldShutdownshutdown
setsockopt
SOL_SOCKET	SO_LINGERstructpackOSErrorclose)selforderlyri   s      r(   _closeSocket_SocketCloser._closeSocket   s    
 kk	''LLO
 &&%%v'7'7T1a9P	IIK  		  		s)   )B AB 	B* 
B'&B'*
B76B7r    N)r!   r"   r#   r$   __doc__rt   r   r&   r    r'   r(   rp   rp      s     Or'   rp   c                  "    \ rS rSrSrSrS rSrg)_AbortingMixin   z
Common implementation of C{abortConnection}.

@ivar _aborting: Set to C{True} when C{abortConnection} is called.
@type _aborting: C{bool}
Fc                T   U R                   (       d  U R                  (       a  gSU l        U R                  5         U R                  5         S U l        S U l        U R                  R                  SU R                  [        R                  " [        R                  " 5       5      5        g)zN
Aborts the connection immediately, dropping any buffered data.

@since: 11.1
NTc                     g Nr    argskwargss     r(   <lambda>0_AbortingMixin.abortConnection.<locals>.<lambda>   s    dr'   c                     g r   r    r   s     r(   r   r      s    tr'   r   )disconnected	_abortingstopReadingstopWritingdoReaddoWritereactor	callLaterconnectionLostrR   FailurerL   ConnectionAbortedr}   s    r(   abortConnection_AbortingMixin.abortConnection   st     23t""GOOE4K4K4M$N	
r'   )r   r   r   N)r!   r"   r#   r$   r   r   r   r&   r    r'   r(   r   r      s     I
r'   r   c                  n    \ rS rSrSrSS jrS rS rS rS r	S	 r
S
 rS rSrS rS rS rS rS rSrg)
Connection   z
Superclass of all socket-based FileDescriptors.

This is an abstract superclass of all objects which represent a TCP/IP
connection based socket.

@ivar logstr: prefix used when logging events related to this connection.
@type logstr: C{str}
Nc                    [         R                  R                  XS9  Xl        U R                  R	                  S5        UR
                  U l        X l        g )Nr   r   )rI   FileDescriptor__init__r\   setblockingfilenoprotocol)r}   ri   r   r   s       r(   r   Connection.__init__   s@    (((?"jj r'   c                    U R                   $ )z&Return the socket for this connection.)r\   r   s    r(   	getHandleConnection.getHandle       {{r'   c                     U R                   R                  U R                  5      nU R                  U5      $ ! [         a6  nUR                  S   [
        :X  a   SnAg[        R                  s SnA$ SnAff = f)a4  Calls self.protocol.dataReceived with all available data.

This reads up to self.bufferSize bytes of data from its socket, then
calls self.dataReceived(data) to process it.  If the connection is not
lost through an error in the physical recv(), this function will return
the result of the dataReceived call.
r   N)	r\   recv
bufferSizer{   r   r=   rN   CONNECTION_LOST_dataReceived)r}   datases      r(   r   Connection.doRead   sc    	,;;##DOO4D !!$''  	,wwqz[(+++		,s!   %8 
A8A3A3-A83A8c           	     &   U(       d  [         R                  $ U R                  R                  U5      nUb[  U R                  R                  nSn[        R
                  " U[        R                  " SSSS5      US9n[        R                  " X55        U$ )NzPReturning a value other than None from %(fqpn)s is deprecated since %(version)s.Twisted   r   )format)	rN   CONNECTION_DONEr   dataReceivedr   getDeprecationWarningStringr   VersionwarnAboutFunction)r}   r   rvaloffenderwarningFormatwarningStrings         r(   r   Connection._dataReceived   s    '''}}))$/}}11H0  &AA(**9b!Q?M ''@r'   c                   [        U5      SU R                   n [        U R                  R                  U5      $ ! [
         a<  nUR                  S   [        [        4;   a   SnAg[        R                  s SnA$ SnAff = f)z
Write as much as possible of the given data to this TCP connection.

This sends up to C{self.SEND_LIMIT} bytes from C{data}.  If the
connection is lost, an exception is returned.  Otherwise, the number
of bytes successfully written is returned.
Nr   )
memoryview
SEND_LIMITrU   r\   sendr{   r   r=   rA   rN   r   )r}   r   limitedDatar   s       r(   writeSomeDataConnection.writeSomeData  sj     !&'89	,!$++"2"2K@@ 	,wwqzk733+++		,s!   : 
B A;&A;5B ;B c                P    U R                   R                  S5        [        U R                  S 5      nU(       a   UR                  5         g g ! [         a     N<f = f! [         a>    [        R                  " 5       n[        R                  " 5         U R                  U5         g f = fNrY   )r\   ru   r{   r   r   writeConnectionLostBaseExceptionrR   r   rS   errr   )r}   pfs      r(   _closeWriteConnection Connection._closeWriteConnection   s    	KK  # #4==$7'%%'   		 ! 'OO%	##A&'s#   A A 
AAAB%$B%c                   [        U R                  S 5      nU(       a   UR                  5         g U R                  U5        g ! [         a<    [        R
                  " 5         U R                  [        R                  " 5       5         g f = fr   )	r   r   readConnectionLostr   rS   r   r   rR   r   )r}   reasonr   s      r(   r   Connection.readConnectionLost.  se    "4==$77$$&
 '	 ! 7	##GOO$567s   A ABBc                   [        U S5      (       d  g[        R                  R                  X5        U R	                  UR                  [        R                  5      (       + 5        U R                  nU ?U ?	U ?
UR                  U5        g)z-See abstract.FileDescriptor.connectionLost().r\   N)hasattrrI   r   r   r   checkrL   r   r   r\   r   )r}   r   r   s      r(   r   Connection.connectionLost9  sn     tX&&..t<fll5+B+BCCD==MKK'r'   Uninitializedc                    U R                   $ )z<Return the prefix to log with when I own the logging thread.)logstrr   s    r(   	logPrefixConnection.logPrefixL  r   r'   c                    [        U R                  R                  [        R                  [        R                  5      5      $ r   )boolr\   
getsockoptIPPROTO_TCPTCP_NODELAYr   s    r(   getTcpNoDelayConnection.getTcpNoDelayP  s*    DKK**6+=+=v?Q?QRSSr'   c                     U R                   R                  [         R                  [         R                  U5        g ! [         a!  n[
        R                  " US5         S nAg S nAff = f)Nz0got error when setting TCP_NODELAY on TCP socket)r\   rv   r   r   r{   rS   r   )r}   enabledes      r(   setTcpNoDelayConnection.setTcpNoDelayS  sP    	K KK""6#5#5v7I7I7S 	KGGAIJJ	Ks   9< 
A'A""A'c                    [        U R                  R                  [        R                  [        R                  5      5      $ r   )r   r\   r   rw   SO_KEEPALIVEr   s    r(   getTcpKeepAliveConnection.getTcpKeepAlivea  s*    DKK**6+<+<f>Q>QRSSr'   c                v    U R                   R                  [         R                  [         R                  U5        g r   )r\   rv   rw   r   )r}   r   s     r(   setTcpKeepAliveConnection.setTcpKeepAlived  s$    v00&2E2EwOr'   )r   r   r\   r   )r!   r"   r#   r$   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r    r'   r(   r   r      sS    !($ ,('	((" FTKTPr'   r   c                  l    \ rS rSrSr\R                  r\R                  r	S r
S rS rS rS rS rS	rg
)_BaseBaseClientih  a  
Code shared with other (non-POSIX) reactors for management of general
outgoing connections.

Requirements upon subclasses are documented as instance variables rather
than abstract methods, in order to avoid MRO confusion, since this base is
mixed in to unfortunately weird and distinctive multiple-inheritance
hierarchies and many of these attributes are provided by peer classes
rather than descendant classes in those hierarchies.

@ivar addressFamily: The address family constant (C{socket.AF_INET},
    C{socket.AF_INET6}, C{socket.AF_UNIX}) of the underlying socket of this
    client connection.
@type addressFamily: C{int}

@ivar socketType: The socket type constant (C{socket.SOCK_STREAM} or
    C{socket.SOCK_DGRAM}) of the underlying socket.
@type socketType: C{int}

@ivar _requiresResolution: A flag indicating whether the address of this
    client will require name resolution.  C{True} if the hostname of said
    address indicates a name that must be resolved by hostname lookup,
    C{False} if it indicates an IP address literal.
@type _requiresResolution: C{bool}

@cvar _commonConnection: Subclasses must provide this attribute, which
    indicates the L{Connection}-alike class to invoke C{__init__} and
    C{connectionLost} on.
@type _commonConnection: C{type}

@ivar _stopReadingAndWriting: Subclasses must implement in order to remove
    this transport from its reactor's notifications in response to a
    terminated connection attempt.
@type _stopReadingAndWriting: 0-argument callable returning L{None}

@ivar _closeSocket: Subclasses must implement in order to close the socket
    in response to a terminated connection attempt.
@type _closeSocket: 1-argument callable; see L{_SocketCloser._closeSocket}

@ivar _collectSocketDetails: Clean up references to the attached socket in
    its underlying OS resource (such as a file descriptor or file handle),
    as part of post connection-failure cleanup.
@type _collectSocketDetails: 0-argument callable returning L{None}.

@ivar reactor: The class pointed to by C{_commonConnection} should set this
    attribute in its constructor.
@type reactor: L{twisted.internet.interfaces.IReactorTime},
    L{twisted.internet.interfaces.IReactorCore},
    L{twisted.internet.interfaces.IReactorFDSet}
c                    U(       a0  U R                   R                  XSU5        UR                  SU5        gUR                  SU R                  U5        g)a   
Called by subclasses to continue to the stage of initialization where
the socket connect attempt is made.

@param whenDone: A 0-argument callable to invoke once the connection is
    set up.  This is L{None} if the connection could not be prepared
    due to a previous error.

@param skt: The socket object to use to perform the connection.
@type skt: C{socket._socketobject}

@param error: The error to fail the connection with.

@param reactor: The reactor to use for this client.
@type reactor: L{twisted.internet.interfaces.IReactorTime}
Nr   )_commonConnectionr   r   failIfNotConnected)r}   whenDoneri   rL   r   s        r(   _finishInit_BaseBaseClient._finishInit  sG    " ""++DtWEa*a!8!8%@r'   c                &  ^  T R                   (       ad  T R                  R                  T R                  S   5      nUR	                  U 4S j5        UR                  T R                  T R                  5        gT R                  T R                  5        g)ao  
Resolve the name that was passed to this L{_BaseBaseClient}, if
necessary, and then move on to attempting the connection once an
address has been determined.  (The connection will be attempted
immediately within this function if either name resolution can be
synchronous or the address was an IP address literal.)

@note: You don't want to call this method from outside, as it won't do
    anything useful; it's just part of the connection bootstrapping
    process.  Also, although this method is on L{_BaseBaseClient} for
    historical reasons, it's not used anywhere except for L{Client}
    itself.

@return: L{None}
r   c                *   > U 4TR                   SS  -   $ r   )rb   )nr}   s    r(   r   0_BaseBaseClient.resolveAddress.<locals>.<lambda>  s    QD499QR=$8r'   N)_requiresResolutionr   resolverb   addCallbackaddCallbacks_setRealAddressr   )r}   ds   ` r(   resolveAddress_BaseBaseClient.resolveAddress  sc      ##$$TYYq\2AMM89NN4//1H1HI  +r'   c                   [        U5      S:X  aZ  [        R                  " U[        R                  [        R                  -  5      S   n[        U/[        USS 5      -   5      U l        OXl        U R                  5         g)a{  
Set the resolved address of this L{_BaseBaseClient} and initiate the
connection attempt.

@param address: Depending on whether this is an IPv4 or IPv6 connection
    attempt, a 2-tuple of C{(host, port)} or a 4-tuple of C{(host,
    port, flow, scope)}.  At this point it is a fully resolved address,
    and the 'host' portion will always be an IP address, not a DNS
    name.
rX   r   rY   N)	r[   r\   r]   r^   r_   r`   ra   realAddress	doConnect)r}   rJ   hostnames      r(   r  _BaseBaseClient._setRealAddress  so     w<1))..1F1FFH  %hZ$wqr{2C%CDD&r'   c                R   U R                   (       d"  U R                  (       d  [        U S5      (       d  gU R                  5          U R	                  S5        U R                  5         U R                  R                  [        R                  " U5      5        U ?g! [         a     N>f = f)z
Generic method called when the attempts to connect failed. It basically
cleans everything it can: call connectionFailed, stop read and write,
delete socket related members.
	connectorNT)	connectedr   r   _stopReadingAndWritingr   _collectSocketDetailsAttributeErrorr  connectionFailedrR   r   )r}   r   s     r(   r   "_BaseBaseClient.failIfNotConnected  s     >>T..gdK6P6P##%	)d# &&(''(<=N  		s   B 
B&%B&c                L    U R                  [        R                  " 5       5        g)z
If a connection attempt is still outstanding (i.e.  no connection is
yet established), immediately stop attempting to connect.
N)r   rL   	UserErrorr   s    r(   stopConnecting_BaseBaseClient.stopConnecting  s    
 	 12r'   c                    U R                   (       d$  U R                  [        R                  " US95        gU R                  R                  X5        U R                  R                  U5        g)aj  
Invoked by lower-level logic when it's time to clean the socket up.
Depending on the state of the connection, either inform the attached
L{Connector} that the connection attempt has failed, or inform the
connected L{IProtocol} that the established connection has been lost.

@param reason: the reason that the connection was terminated
@type reason: L{Failure}
stringN)r  r   rL   ConnectErrorr   r   r  r}   r   s     r(   r   _BaseBaseClient.connectionLost  sJ     ~~##E$6$6f$EF""11$?NN))&1r'   )r  N)r!   r"   r#   r$   r   r\   AF_INETaddressFamilySOCK_STREAM
socketTyper   r  r  r   r  r   r&   r    r'   r(   r   r   h  s=    1f NNM##JA.,.*&32r'   r   c                  >    \ rS rSrSr\r\rS rS r	S r
S rS rSrg	)

BaseClienti  a  
A base class for client TCP (and similar) sockets.

@ivar realAddress: The address object that will be used for socket.connect;
    this address is an address tuple (the number of elements dependent upon
    the address family) which does not contain any names which need to be
    resolved.
@type realAddress: C{tuple}

@ivar _base: L{Connection}, which is the base class of this class which has
    all of the useful file descriptor methods.  This is used by
    L{_TLSServerMixin} to call the right methods to directly manipulate the
    transport, as is necessary for writing TLS-encrypted bytes (whereas
    those methods on L{Server} will go through another layer of TLS if it
    has been enabled).
c                h    [        U S5      (       a!  U R                  5         U R                  5         gg)z
Implement the POSIX-ish (i.e.
L{twisted.internet.interfaces.IReactorFDSet}) method of detaching this
socket from the reactor for L{_BaseBaseClient}.
r   N)r   r   r   r   s    r(   r  !BaseClient._stopReadingAndWriting"  s.     4## $r'   c                    U ? U ?g)zV
Clean up references to the socket and its file descriptor.

@see: L{_BaseBaseClient}
N)r\   r   r   s    r(   r   BaseClient._collectSocketDetails-  s     Kr'   c                    [         R                   " U R                  U R                  5      nUR                  S5        [        R
                  " UR                  5       5        U$ )zS(internal) Create a non-blocking socket using
self.addressFamily, self.socketType.
r   )r\   r  r  r   rM   _setCloseOnExecr   r}   ss     r(   createInternetSocketBaseClient.createInternetSocket5  sC     MM$,,doo>	aahhj)r'   c                f   U R                   U l        U R                   U l        [        U S5      (       d  gU R                  R                  [        R                  [        R                  5      nU(       a1  U R                  [        R                  " U[        U5      45      5        g U R                  R                  U R                  5      nU(       a  U[         :X  a  O{U["        [$        [&        4;   d  U[(        :X  a+  [*        S:X  a!  U R-                  5         U R/                  5         gU R                  [        R                  " U[        U5      45      5        gU ?U ?U R1                  5         U R3                  5         U R5                  5         g! [         a  nUR                  S   n SnANSnAff = f)z
Initiate the outgoing connection attempt.

@note: Applications do not need to call this method; it will be invoked
    internally as part of L{IReactorTCP.connectTCP}.
r  Nr   r1   )r  r   r   r   r\   r   rw   SO_ERRORr   rL   getConnectErrorrG   
connect_exr  r{   r   r@   r=   r>   r?   r<   r   startReadingstartWritingr   r   _connectDone)r}   r   connectResultr   s       r(   r  BaseClient.doConnect>  sX    ~~nnt[)) kk$$V%6%6H##E$9$93:N$OP	' KK2243C3CDM '  Kh#GG'LG,C!!#!!#''))=(=:Q*RS  LK5  	'GGAJM	's   &%F 
F0F++F0c                h   U R                   R                  U R                  5       5      U l        SU l        U R                  U R                  5      nSU-  U l        U R                  c   [        5       U l        U R                  5         gU R                  5         U R                  R                  U 5        g)aj  
This is a hook for when a connection attempt has succeeded.

Here, we build the protocol from the
L{twisted.internet.protocol.ClientFactory} that was passed in, compute
a log string, begin reading so as to send traffic to the newly built
protocol, and finally hook up the protocol itself.

This hook is overridden by L{ssl.Client} to initiate the TLS protocol.
rY   z	%s,clientN)r  buildProtocolgetPeerr   r  _getLogPrefixr   rP   loseConnectionr0  makeConnection)r}   r   s     r(   r2  BaseClient._connectDonev  s     44T\\^D&&t}}5	!I-==  %JDM!MM((.r'   )r  r   r   r   r   N)r!   r"   r#   r$   r   r   _baser   r  r  r*  r  r2  r&   r    r'   r(   r!  r!    s.    " E"	%6p/r'   r!  c                J    [         R                  " XSSS[        5      S   S   $ )a>  
Resolve an IPv6 literal into an IPv6 address.

This is necessary to resolve any embedded scope identifiers to the relevant
C{sin6_scope_id} for use with C{socket.connect()}, C{socket.listen()}, or
C{socket.bind()}; see U{RFC 3493 <https://tools.ietf.org/html/rfc3493>} for
more information.

@param ip: An IPv6 address literal.
@type ip: C{str}

@param port: A port number.
@type port: C{int}

@return: a 4-tuple of C{(host, port, flow, scope)}, suitable for use as an
    IPv6 address.

@raise socket.gaierror: if either the IP or port is not numeric as it
    should be.
r   rX   )r\   getaddrinfo_NUMERIC_ONLY)ipports     r(   _resolveIPv6rB    s'    * b1a?B1EEr'   c                  P    \ rS rSrSr\R                  rS	S jrS r	S r
S
S jrSrg)_BaseTCPClienti  a  
Code shared with other (non-POSIX) reactors for management of outgoing TCP
connections (both TCPv4 and TCPv6).

@note: In order to be functional, this class must be mixed into the same
    hierarchy as L{_BaseBaseClient}.  It would subclass L{_BaseBaseClient}
    directly, but the class hierarchy here is divided in strange ways out
    of the need to share code along multiple axes; specifically, with the
    IOCP reactor and also with UNIX clients in other reactors.

@ivar _addressType: The Twisted _IPAddress implementation for this client
@type _addressType: L{IPv4Address} or L{IPv6Address}

@ivar connector: The L{Connector} which is driving this L{_BaseTCPClient}'s
    connection attempt.

@ivar addr: The address that this socket will be connecting to.
@type addr: If IPv4, a 2-C{tuple} of C{(str host, int port)}.  If IPv6, a
    4-C{tuple} of (C{str host, int port, int ignored, int scope}).

@ivar createInternetSocket: Subclasses must implement this as a method to
    create a python socket object of the appropriate address family and
    socket type.
@type createInternetSocket: 0-argument callable returning
    C{socket._socketobject}.
Nc                p   X@l         X4U l        U R                  nS nS n[        R                  " U5      (       a  SU l        Od[        R                  " U5      (       aB  SU l        [        X5      U l        [        R                  U l
        [        R                  U l        OSU l         U R                  5       nU(       aS  UbP   ['        U5      [(        :X  d   e[        R                  " US   5      (       a	  [        U6 n
OUn
UR+                  U
5        U R-                  XhXu5        g ! [         a=  n	[         R"                  " U	R$                  S   U	R$                  S   5      nS n S n	A	NS n	A	ff = f! [         a=  n	[         R"                  " U	R$                  S   U	R$                  S   5      nS n S n	A	NS n	A	ff = f)NFTr   rY   )r  rb   r  rI   isIPAddressr   isIPv6AddressrB  r\   AF_INET6r  rJ   IPv6Address_addressTyper*  r{   rL   ConnectBindErrorr   typer`   bindr   )r}   rc   rA  bindAddressr  r   r   r   ri   r   bindinfos              r(   r   _BaseTCPClient.__init__  sm   "L	&&%%',D$##D))',D$$T0DI!'D ' 3 3D'+D$	++-C /	 K(E111))+a.99+[9H*H" 	5  	((RWWQZ@CH	   ,,RWWQZD s1   'D$ AE. $
E+.3E&&E+.
F583F00F5c                N    U R                   " S/[        U R                  5      Q76 $ )zf
Returns an L{IPv4Address} or L{IPv6Address}.

This indicates the address from which I am connecting.
TCP)rJ  rn   r\   r   s    r(   getHost_BaseTCPClient.getHost  s#       Cdkk)BCCr'   c                <    U R                   " S/U R                  Q76 $ )zb
Returns an L{IPv4Address} or L{IPv6Address}.

This indicates the address that I am connected to.
rR  )rJ  r  r   s    r(   r7  _BaseTCPClient.getPeer  s        :)9)9::r'   c                Z    SU R                    SU R                   S[        U 5      S S3nU$ )N<z to z at x>)	__class__rb   idr(  s     r(   __repr___BaseTCPClient.__repr__   s0    tDII;d2d8A,a@r'   )rJ  r   rb   r  r  r   returnstr)r!   r"   r#   r$   r   rJ   IPv4AddressrJ  r   rS  r7  r]  r&   r    r'   r(   rD  rD    s*    6 &&L"6HD;r'   rD  c                      \ rS rSrSrSrg)Clienti  zv
A transport for a TCP protocol; either TCPv4 or TCPv6.

Do not create these directly; use L{IReactorTCP.connectTCP}.
r    N)r!   r"   r#   r$   r   r&   r    r'   r(   rd  rd    s    r'   rd  c                      \ rS rSr% Sr\r\R                  r	S\
S'                 SS jrSS jr\S 5       rS rS	 rS
rg)Serveri  a  
Serverside socket-stream connection class.

This is a serverside network connection transport; a socket which came from
an accept() on a server.

@ivar _base: L{Connection}, which is the base class of this class which has
    all of the useful file descriptor methods.  This is used by
    L{_TLSServerMixin} to call the right methods to directly manipulate the
    transport, as is necessary for writing TLS-encrypted bytes (whereas
    those methods on L{Server} will go through another layer of TLS if it
    has been enabled).
z;Union[type[address.IPv4Address], type[address.IPv6Address]]rJ  c                   [         R                  XX&5        [        U5      S:w  a  [        R                  U l        X@l        X0l        XPl        US   U l	        U R                  U R                  5      nU SU SU R                   3U l        U R                  bT  SR                  U R                  R                  R                  U R                  U R                  R                   5      U l        U R%                  5         SU l        g)z
Server(sock, protocol, client, server, sessionno)

Initialize it with a socket, a protocol, a descriptor for my peer (a
tuple of host, port describing the other end of the connection), an
instance of Port, and a session number.
rZ   r   ,N<{} #{} on {}>rY   )r   r   r[   rJ   rI  rJ  serverclient	sessionnor  r8  r   r   r   r[  r!   _realPortNumberrepstrr0  r  )r}   sockr   rk  rj  rl  r   r   s           r(   r   Server.__init__"  s      	D:v;! ' 3 3D"q	&&t}}5	"1YKq@;;"/66''00++ DK
 	r'   c                    U R                   $ )z-
A string representation of this connection.
)rn  r   s    r(   r]  Server.__repr__E  s     {{r'   c                   [         R                  nU[        R                  :X  a  [         R                  n[        R
                  " X[        R                  5      n[        U5      nU" S/UQ76 nUR                  5       S   n	UR                  U5      n
U
c  UR                  5         gU " XjUSUS   U5      nSR                  UR                  R                  R                  UR                  U	5      Ul        U
R#                  U5        U$ )aQ  
Create a new L{Server} based on an existing connected I{SOCK_STREAM}
socket.

Arguments are the same as to L{Server.__init__}, except where noted.

@param fileDescriptor: An integer file descriptor associated with a
    connected socket.  The socket must be in non-blocking mode.  Any
    additional attributes desired, such as I{FD_CLOEXEC}, must also be
    set already.

@param addressFamily: The address family (sometimes called I{domain})
    of the existing socket.  For example, L{socket.AF_INET}.

@return: A new instance of C{cls} wrapping the socket given by
    C{fileDescriptor}.
rR  rY   Nri  )rJ   rb  r\   rH  rI  fromfdr  rj   rm   r6  r|   r   r   r[  r!   rl  rn  r:  )clsfileDescriptorr  factoryr   addressTyperi   rb   protocolAddr	localPortr   r}   s               r(   _fromConnectedSocketServer._fromConnectedSocketK  s    & ))FOO+!--KmmN6;M;MNC "5040OO%a(	((6IIK3$d1gw?&--MM##,,NN

 	%r'   c                R    [        U R                  5      nU R                  " S/UQ76 $ )zT
Returns an L{IPv4Address} or L{IPv6Address}.

This indicates the server's address.
rR  rn   r\   rJ  r}   rb   s     r(   rS  Server.getHostt  s(     DKK(  ...r'   c                <    U R                   " S/U R                  Q76 $ )zT
Returns an L{IPv4Address} or L{IPv6Address}.

This indicates the client's address.
rR  )rJ  rk  r   s    r(   r7  Server.getPeer}  s       555r'   )rJ  rk  r  r  r   rn  rj  rl  N)ro  zsocket.socketr   r   rk  ztuple[object, ...]rj  Portrl  intr   r   r`  Noner_  )r!   r"   r#   r$   r   r   r<  rJ   rb  rJ  __annotations__r   r]  classmethodr{  rS  r7  r&   r    r'   r(   rf  rf    s     E 	   !! ! #	!
 ! ! ! 
!F & &P/6r'   rf  c                  0    \ rS rSrSrS rS rS rS rSr	g)	_IFileDescriptorReservationi  a  
An open file that represents an emergency reservation in the
process' file descriptor table.  If L{Port} encounters C{EMFILE}
on C{accept(2)}, it can close this file descriptor, retry the
C{accept} so that the incoming connection occupies this file
descriptor's space, and then close that connection and reopen this
one.

Calling L{_IFileDescriptorReservation.reserve} attempts to open
the reserve file descriptor if it is not already open.
L{_IFileDescriptorReservation.available} returns L{True} if the
underlying file is open and its descriptor claimed.

L{_IFileDescriptorReservation} instances are context managers;
entering them releases the underlying file descriptor, while
exiting them attempts to reacquire it.  The block can take
advantage of the free slot in the process' file descriptor table
accept and close a client connection.

Because another thread might open a file descriptor between the
time the context manager is entered and the time C{accept} is
called, opening the reserve descriptor is best-effort only.
c                     g)z
Is the reservation available?

@return: L{True} if the reserved file descriptor is open and
    can thus be closed to allow a new file to be opened in its
    place; L{False} if it is not open.
Nr    r    r'   r(   	available%_IFileDescriptorReservation.available      r'   c                     g)z
Attempt to open the reserved file descriptor; if this fails
because of C{EMFILE}, internal state is reset so that another
reservation attempt can be made.

@raises Exception: Any exception except an L{OSError} whose
    errno is L{EMFILE}.
Nr    r    r'   r(   reserve#_IFileDescriptorReservation.reserve  r  r'   c                     g)ze
Release the underlying file descriptor so that code within the
context manager can open a new file.
Nr    r    r'   r(   	__enter__%_IFileDescriptorReservation.__enter__  r  r'   c                    g)z
Attempt to re-open the reserved file descriptor.  See
L{reserve} for caveats.

@param excType: See L{object.__exit__}
@param excValue: See L{object.__exit__}
@param traceback: See L{object.__exit__}
Nr    )excTypeexcValue	tracebacks      r(   __exit__$_IFileDescriptorReservation.__exit__  r  r'   r    N
r!   r"   r#   r$   r   r  r  r  r  r&   r    r'   r(   r  r    s    0r'   r  c                      \ rS rSrSS jrSrg)	_HasClosei  c                    g r   r    r   s    r(   r|   _HasClose.close  s    r'   r    N)r`  object)r!   r"   r#   r$   r|   r&   r    r'   r(   r  r    s    r'   r  T)auto_attribsc                      \ rS rSr% Sr\" 5       rS\S'   S\S'   \R                  " SSS	9r
S
\S'   S rS rS rS rSrg)_FileDescriptorReservationi  z
L{_IFileDescriptorReservation} implementation.

@ivar fileFactory: A factory that will be called to reserve a
    file descriptor.
@type fileFactory: A L{callable} that accepts no arguments and
    returns an object with a C{close} method.
zClassVar[Logger]_logzCallable[[], _HasClose]_fileFactoryFN)initdefaultzOptional[_HasClose]_fileDescriptorc                    U R                   SL$ )z
See L{_IFileDescriptorReservation.available}.

@return: L{True} if the reserved file descriptor is open and
    can thus be closed to allow a new file to be opened in its
    place; L{False} if it is not open.
Nr  r   s    r(   r  $_FileDescriptorReservation.available  s     ##4//r'   c                    U R                   c   U R                  5       nXl         gg! [         a:  nUR                  [        :X  a   U R
                  R                  S5         SnAge SnAff = f)z-
See L{_IFileDescriptorReservation.reserve}.
Nz2Could not reserve EMFILE recovery file descriptor.)r  r  r{   errnorB   r  rR   )r}   rv  r   s      r(   r  "_FileDescriptorReservation.reserve  sm     '
6!%!2!2!4 (6$ (  77f$II%%L  s   ' 
A+/A&%A&&A+c                v    U R                   c  [        S5      eU R                   R                  5         SU l         g)z/
See L{_IFileDescriptorReservation.__enter__}.
Nz5No file reserved.  Have you called my reserve method?)r  RuntimeErrorr|   r   s    r(   r  $_FileDescriptorReservation.__enter__  s6     'VWW""$#r'   c                |     U R                  5         g! [         a    U R                  R                  S5         gf = f)z.
See L{_IFileDescriptorReservation.__exit__}.
z5Could not re-reserve EMFILE recovery file descriptor.N)r  	Exceptionr  rR   r}   r  r  r  s       r(   r  #_FileDescriptorReservation.__exit__  s5    	WLLN 	WIIUV	Ws    %;;r  )r!   r"   r#   r$   r   r   r  r  attribr  r  r  r  r  r&   r    r'   r(   r  r    sG     $XD
%))+/77t+LO(L06"$Wr'   r  c                  0    \ rS rSrSrS rS rS rS rSr	g)	_NullFileDescriptorReservationi  z:
A null implementation of L{_IFileDescriptorReservation}.
c                    g)zi
The reserved file is never available.  See
L{_IFileDescriptorReservation.available}.

@return: L{False}
Fr    r   s    r(   r  (_NullFileDescriptorReservation.available  s     r'   c                    g)z:
Do nothing.  See L{_IFileDescriptorReservation.reserve}.
Nr    r   s    r(   r  &_NullFileDescriptorReservation.reserve  r  r'   c                    g)zM
Do nothing. See L{_IFileDescriptorReservation.__enter__}

@return: L{False}
Nr    r   s    r(   r  (_NullFileDescriptorReservation.__enter__  r  r'   c                    g)z
Do nothing.  See L{_IFileDescriptorReservation.__exit__}.

@param excType: See L{object.__exit__}
@param excValue: See L{object.__exit__}
@param traceback: See L{object.__exit__}
Nr    r  s       r(   r  '_NullFileDescriptorReservation.__exit__"  r  r'   r    Nr  r    r'   r(   r  r    s    
r'   r  c                 4    [        [        R                  5      $ r   )openosdevnullr    r'   r(   r   r   J  s    T"**5Er'   c                      \ rS rSr% SrS\S'   S\S'   \R                  " \R                  " \	5      S9r
S\S	'   S
 rS rSrg)_BuffersLogsi_  a   
A context manager that buffers any log events until after its
block exits.

@ivar _namespace: The namespace of the buffered events.
@type _namespace: L{str}.

@ivar _observer: The observer to which buffered log events will be
    written
@type _observer: L{twisted.logger.ILogObserver}.
ra  
_namespacer   	_observer)r  zList[LogEvent]_logsc                R    [        U R                  U R                  R                  S9$ )z_
Enter a log buffering context.

@return: A logger that buffers log events.
@rtype: L{Logger}.
)	namespaceobserver)r   r  r  appendr   s    r(   r  _BuffersLogs.__enter__q  s     $**:K:KLLr'   c                L    U R                    H  nU R                  U5        M     g)z
Exit a log buffering context and log all buffered events to
the provided observer.

@param excType: See L{object.__exit__}
@param excValue: See L{object.__exit__}
@param traceback: See L{object.__exit__}
N)r  r  )r}   r  r  r  events        r(   r  _BuffersLogs.__exit__z  s     ZZENN5!  r'   r    N)r!   r"   r#   r$   r   r  r  r  Factoryra   r  r  r  r&   r    r'   r(   r  r  _  s;    
 O GGDLL,>?E>?M
"r'   r  c           	   #    #    U H  n UR                  5       u  pVXV4v   M     g! [         Ga/  nUR                  S   [        [        4;   a   SnA  gUR                  S   [
        :X  a   SnAMk  UR                  S   [        :X  a  UR                  5       (       a|  U R                  S5        U   [        XX#5      nU H%  u  pU	R                  5         U R                  SU
S9  M'     U R                  S5        SSS5        O! , (       d  f       O= f SnA  gUR                  S   [        ;   a*  U R                  S[        UR                  S      S9   SnA  ge SnAff = f7f)	aR  
Return a generator that yields client sockets from the provided
listening socket until there are none left or an unrecoverable
error occurs.

@param logger: A logger to which C{accept}-related events will be
    logged.  This should not log to arbitrary observers that might
    open a file descriptor to avoid claiming the C{EMFILE} file
    descriptor on UNIX-like systems.
@type logger: L{Logger}

@param accepts: An iterable iterated over to limit the number
    consecutive C{accept}s.
@type accepts: An iterable.

@param listener: The listening socket.
@type listener: L{socket.socket}

@param reservedFD: A reserved file descriptor that can be used to
    recover from C{EMFILE} on UNIX-like systems.
@type reservedFD: L{_IFileDescriptorReservation}

@return: A generator that yields C{(socket, addr)} tuples from
    L{socket.socket.accept}
r   Nz7EMFILE encountered; releasing reserved file descriptor.z-EMFILE recovery: Closed socket from {address})rJ   z-Re-reserving EMFILE recovery file descriptor.z/Could not accept new connection ({acceptError}))acceptError)acceptr{   r   r=   rE   r;   rB   r  info_acceptr|   _ACCEPT_ERRORSrH   )loggeracceptslistener
reservedFD_rk  rJ   r   clientsToCloseclientToCloseclosedAddresss              r(   r  r    s:    4 +	"&oo/OFT /!Y   '	vvay[&11e# f$)=)=)?)? P
  %,Vh%SN8F4%++-N$1 $  9G KK OP  ZZ n,E )!&&) 4   O'	sm   E"%
E"EEE"E*E"0?E/A	D8	E
DEE";EE"EEE"c                  .   \ rS rSr% Sr\R                  r\r	Sr
SrSrSrSrS\S	'   Sr\R"                  r\R(                  r\" 5       rSS
 jr\S 5       rSS jrS rS rS rS r\ RB                  " \"RF                  5      4S jr$\$r%S r&S r'S r(S r)Sr*g)r  i  a  
A TCP server port, listening for connections.

When a connection is accepted, this will call a factory's buildProtocol
with the incoming address as an argument, according to the specification
described in L{twisted.internet.interfaces.IProtocolFactory}.

If you wish to change the sort of transport that will be used, the
C{transport} attribute will be called with the signature expected for
C{Server.__init__}, so it can be replaced.

@ivar deferred: a deferred created when L{stopListening} is called, and
    that will fire when connection is lost. This is not to be used it
    directly: prefer the deferred returned by L{stopListening} instead.
@type deferred: L{defer.Deferred}

@ivar disconnecting: flag indicating that the L{stopListening} method has
    been called and that no connections should be accepted anymore.
@type disconnecting: C{bool}

@ivar connected: flag set once the listen has successfully been called on
    the socket.
@type connected: C{bool}

@ivar _type: A string describing the connections which will be created by
    this port.  Normally this is C{"TCP"}, since this is a TCP port, but
    when the TLS implementation re-uses this class it overrides the value
    with C{"TLS"}.  Only used for logging.

@ivar _preexistingSocket: If not L{None}, a L{socket.socket} instance which
    was created and initialized outside of the reactor and will be used to
    listen for connections (instead of a new socket being created by this
    L{Port}).
r    r   rR  NzOptional[int]rm  c                    [         R                  R                  XS9  Xl        X l        X0l        [        R                  " U5      (       a*  [        R                  U l
        [        R                  U l        X@l        g)z,Initialize with a numeric port to listen on.r   N)rK   BasePortr   rA  rw  backlogrI   rG  r\   rH  r  rJ   rI  rJ  	interface)r}   rA  rw  r  r  r   s         r(   r   Port.__init__
  sV    t5	!!),,!'D ' 3 3D"r'   c                    [         R                  " X#U R                  5      n[        U5      S   nU " SUSXa5      nXWl        U$ )a-  
Create a new L{Port} based on an existing listening I{SOCK_STREAM}
socket.

Arguments are the same as to L{Port.__init__}, except where noted.

@param fd: An integer file descriptor associated with a listening
    socket.  The socket must be in non-blocking mode.  Any additional
    attributes desired, such as I{FD_CLOEXEC}, must also be set already.

@param addressFamily: The address family (sometimes called I{domain}) of
    the existing socket.  For example, L{socket.AF_INET}.

@return: A new instance of C{cls} wrapping the socket given by C{fd}.
r   N)r\   rt  r  rn   _preexistingSocket)ru  r   fdr  rw  rA  r  r}   s           r(   _fromListeningDescriptorPort._fromListeningDescriptor  sB    " }}R? &q)	4$	;"&r'   c                    U R                   b;  SR                  U R                  U R                  R                  U R                   5      $ SR                  U R                  U R                  R                  5      $ )Nz<{} of {} on {}>z<{} of {} (not listening)>)rm  r   r[  rw  r   s    r(   r]  Port.__repr__,  sg    +%,,&&$$  066&& r'   c                    [         R                  R                  U 5      n[        S:X  aC  [        R
                  S:w  a/  UR                  [        R                  [        R                  S5        U$ )NposixcygwinrY   )
rK   r  r*  r   sysplatformrv   r\   rw   SO_REUSEADDRr(  s     r(   r*  Port.createInternetSocket9  sJ    MM..t47"s||x'?LL**F,?,?Cr'   c                l   [         R                  5         U R                  c   U R                  5       nU R                  [
        R                  :X  a!  [        U R                  U R                  5      nOU R                  U R                  4nUR                  U5        UR                  U R                  5        OU R                  nSU l        SU l        UR!                  5       S   U l        [$        R&                  " U R)                  U R*                  5      < SU R"                  < 35        U R*                  R-                  5         SU l        Xl        U R
                  R0                  U l        SU l        U R5                  5         g! [         a&  n[        U R                  U R                  U5      eSnAff = f)zCreate and bind my socket, and begin listening on it.

This is called on unserialization, and must be called after creating a
server to begin listening on the specified port.
NFrY   z starting on Td   )_reservedFDr  r  r*  r  r\   rH  rB  r  rA  rM  r{   rO   listenr  rt   rm   rm  rS   msgr8  rw  doStartr  r   numberAcceptsr0  )r}   ri   rb   les       r(   startListeningPort.startListening?  sR    	""*G//1%%8'		BD NNDII6D JJt||$ ))C&*D##(D   #03!!$,,/1E1EG	
 	kk(( 7  G'		2FFGs   A8F 
F3!F..F3c                (    U R                   " S/UQ76 $ )NrR  )rJ  )r}   rJ   s     r(   
_buildAddrPort._buildAddrl  s      111r'   c           
     "    [         S:X  a  U R                  nOSn[        U R                  R                  U R                  R
                  5       nSn[        U[        U5      U R                  [        5      n[        US5       GH  u  nu  pV[        R                  " UR                  5       5        [        U5      S:X  aT  [        R                  " U[        R                   [        R"                  -  5      n[%        US   /['        USS 5      -   5      nU R(                  R+                  U R-                  U5      5      nUc  UR/                  5         M  U R0                  n	U	S-   U l        U R3                  XXX`XR4                  5      n
UR7                  U
5        GM     SSS5        WU R                  :X  a  U =R                  S-  sl        g[9        SU5      U l        g! , (       d  f       NF= f! [:         a    [<        R>                  " 5          gf = f)z
Called when my socket is ready for reading.

This accepts a connection and calls self.protocol() to handle the
wire-level protocol.
r  rY   r   rX   N   ) r   r  r  _loggerr  r  r  ranger\   r  	enumeraterM   r'  r   r[   r]   r^   r_   r`   ra   rw  r6  r  r|   rl  	transportr   r:  maxr   rS   deferr)r}   
numAcceptsbufferingLoggeracceptedclientsri   rb   rc   r   r)  r  s              r(   r   Port.doReado  s   8	w&!//
 
&&(=(= !#U:%6[ .7w-B)Hks))#**,74yA~  &11 &"7"7&:O:O"O   %d1gYd12h%?@#||99$//$:OPH'		 A%&UDN $t1ll!I ++I6) .CD 4---""b(" &)H%5"O P  	 JJL	s1   AG, EG-G, 	G, 
G)%G, ,HHc                    SU l         U R                  5         U R                  (       a3  [        U R                  SU R
                  U5      U l        U R                  $ g)z
Stop accepting connections on this port.

This will shut down the socket and call self.connectionLost().  It
returns a deferred which will fire successfully when the port is
actually closed, or with a failure if an error occurs shutting down.
Tr   N)disconnectingr   r  rQ   r   r   deferred)r}   connDones     r(   r9  Port.loseConnection  sJ     ">>&t||Q8K8KXVDM==  r'   c                f    [         R                  " SU R                   SU R                   S35        g)z
Log message for closing port
(z Port z Closed)N)rS   r  _typerm  r   s    r(   _logConnectionLostMsgPort._logConnectionLostMsg  s*     	!DJJ<vd&:&:%;8DEr'   c                   U R                  5         SU l        [        R                  R	                  X5        SU l        U R                  S5        U ?U ? U R                  R                  5         SU l        g! SU l        f = f)z
Cleans up the socket.
NFT)r  rm  rK   r  r   r  r   r\   r   rw  doStopr  r  s     r(   r   Port.connectionLost  so     	""$#$$T2$KK	'LL!!&DDs   A6 6	A?c                V    [         R                  " U R                  R                  5      $ )z9Returns the name of my class, to prefix log entries with.)rT   qualrw  r[  r   s    r(   r   Port.logPrefix  s    ||DLL2233r'   c                R    [        U R                  5      nU R                  " S/UQ76 $ )z[
Return an L{IPv4Address} or L{IPv6Address} indicating the listening
address of this port.
rR  r~  r  s     r(   rS  Port.getHost  s(    
 DKK(  ...r'   )rJ  r  rm  rt   r  r  r  r  r  rw  r   r  r  rA  rl  r\   )r   r  Nr_  )+r!   r"   r#   r$   r   r\   r  r  rf  r  rl  r  r  r  rm  r  r  r  r  rJ   rb  rJ  r   r  r   r  r  r]  r*  r  r  r   rR   r   rN   r   r9  stopListeningr  r   r   rS  r&   r    r'   r(   r  r    s    !F ##JIIIGE &*O]) NNM&&LhG	#  ,+Z2?B '.ood6J6J&K ! #MF'$4/r'   r  c                  v    \ rS rSr% Sr\R                  rS\S'    S
             SS jjr	SS jr
S rS	rg)	Connectori  a  
A L{Connector} provides of L{twisted.internet.interfaces.IConnector} for
all POSIX-style reactors.

@ivar _addressType: the type returned by L{Connector.getDestination}.
    Either L{IPv4Address} or L{IPv6Address}, depending on the type of
    address.
@type _addressType: C{type}
z/type[address.IPv4Address | address.IPv6Address]rJ  Nc                   [        U[        5      (       a   [        R                  " US5      nXsU l        U l        [        R                  " U5      (       a  [        R                  U l        XPl        [        R                   R#                  XXF5        g ! [         a   n[
        R                  " U SU< S3S9eS nAff = f)Ntcpz ()r  )
isinstancera  r\   getservbynamer{   rL   ServiceNameUnknownErrorrc   rA  rI   rG  rJ   rI  rJ  rN  rK   BaseConnectorr   )r}   rc   rA  rw  timeoutrN  r   r   s           r(   r   Connector.__init__  s     dC  N++D%8  $	49!!$'' ' 3 3D&##D7D  N33aS4(!;LMMNs   B 
B=B88B=c                n    [        U R                  U R                  U R                  X R                  5      $ )z\
Create a L{Client} bound to this L{Connector}.

@return: a new L{Client}
@rtype: L{Client}
)rd  rc   rA  rN  r   r   s    r(   _makeTransportConnector._makeTransport  s'     diiD,<,<dLLQQr'   c                P    U R                  SU R                  U R                  5      $ )zA
@see: L{twisted.internet.interfaces.IConnector.getDestination}.
rR  )rJ  rc   rA  r   s    r(   getDestinationConnector.getDestination  s!       		499==r'   )rJ  rN  rc   rA  r   )rc   ra  rA  z	int | strrw  r   r,  floatrN  zstr | tuple[str, int] | Noner   r   r`  r  )r`  rd  )r!   r"   r#   r$   r   rJ   rb  rJ  r  r   r/  r2  r&   r    r'   r(   r$  r$    s}     ELDWDWLAW EE E 	E
 E 2E E 
E(R>r'   r$  )wr   
__future__r   r  r\   ry   r  typingr   r   r   r   r   r	   zope.interfacer
   r   r  typing_extensionstwisted.internet.interfacesr   r   r   r   r   r   twisted.internet.protocolr   twisted.loggerr   r   r   twisted.pythonr   r   twisted.python.runtimer   twisted.internet._newtlsr   r*   r   r   r   r/   r   ImportErrorr  r;   r  r2   r?   r3   r>   r4   r<   r5   r@   r6   rB   r7   rA   r8   r=   rC   rD   rE   r9   rF   twisted.python.win32r:   rG   rH   twisted.internetrI   rJ   rK   rL   rM   rN   twisted.internet.errorrO   rP   twisted.internet.taskrQ   rR   rS   rT   twisted.python.utilrU   getattr_AI_NUMERICSERVrd   rj   rn   rp   r   r   r   r   r!  AI_NUMERICHOSTr?  rB  rD  rd  rf  r  r  r)  r  r  r  r  r  r  r  r  r+  r$  r    r'   r(   <module>rH     s  
 # 	   
 A A 1    4 9 9 . / 
 : 7 HE   XFXFF3<!!"  I H 4 . , 0 0 . &"2A6(++   F
 
8 ]M=9SP00-SP :SPlb2 b2JC//: C/L %%7F0T Tn^Z v6_j v6r:) :z!** 
 ()T:W :W  *:Wz ()! ! *!~ 702K,-EFK$ '66<@ T$" $" $"NF"R ^Q/4==- Q/ Q/h.>"" .>o-  M   s   (J# #&KK