aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test')
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/__init__.py6
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_posixifaces.py131
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_win32ifaces.py119
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/connectionmixins.py649
-rw-r--r--lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/not-a-certificate1
-rw-r--r--lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing1.pem26
-rw-r--r--lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2-duplicate.pem26
-rw-r--r--lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2.pem26
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fakeendpoint.py66
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/inlinecb_tests.py92
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/process_helper.py33
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/reactormixins.py409
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_abstract.py56
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_address.py292
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_base.py272
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_baseprocess.py73
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_core.py331
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_default.py83
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_endpoints.py2021
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_epollreactor.py246
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_fdset.py394
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_filedescriptor.py41
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_glibbase.py66
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtk3reactor.py152
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtkreactor.py95
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inlinecb.py13
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inotify.py504
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_interfaces.py53
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_iocp.py150
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_main.py38
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_newtls.py194
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_pollingfile.py46
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixbase.py387
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixprocess.py340
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_process.py711
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_protocol.py357
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_qtreactor.py35
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_serialport.py72
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_sigchld.py194
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_socket.py128
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_stdio.py195
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tcp.py2077
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_threads.py218
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_time.py66
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tls.py432
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp.py197
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp_internals.py165
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_unix.py558
-rwxr-xr-xlib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_win32events.py183
49 files changed, 0 insertions, 13019 deletions
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/__init__.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/__init__.py
deleted file mode 100755
index cf1de2ac..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/__init__.py
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet}.
-"""
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_posixifaces.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_posixifaces.py
deleted file mode 100755
index 3dcbc272..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_posixifaces.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-POSIX implementation of local network interface enumeration.
-"""
-
-import sys, socket
-
-from socket import AF_INET, AF_INET6, inet_ntop
-from ctypes import (
- CDLL, POINTER, Structure, c_char_p, c_ushort, c_int,
- c_uint32, c_uint8, c_void_p, c_ubyte, pointer, cast)
-from ctypes.util import find_library
-
-libc = CDLL(find_library("c"))
-
-if sys.platform == 'darwin':
- _sockaddrCommon = [
- ("sin_len", c_uint8),
- ("sin_family", c_uint8),
- ]
-else:
- _sockaddrCommon = [
- ("sin_family", c_ushort),
- ]
-
-
-
-class in_addr(Structure):
- _fields_ = [
- ("in_addr", c_ubyte * 4),
- ]
-
-
-
-class in6_addr(Structure):
- _fields_ = [
- ("in_addr", c_ubyte * 16),
- ]
-
-
-
-class sockaddr(Structure):
- _fields_ = _sockaddrCommon + [
- ("sin_port", c_ushort),
- ]
-
-
-
-class sockaddr_in(Structure):
- _fields_ = _sockaddrCommon + [
- ("sin_port", c_ushort),
- ("sin_addr", in_addr),
- ]
-
-
-
-class sockaddr_in6(Structure):
- _fields_ = _sockaddrCommon + [
- ("sin_port", c_ushort),
- ("sin_flowinfo", c_uint32),
- ("sin_addr", in6_addr),
- ]
-
-
-
-class ifaddrs(Structure):
- pass
-
-ifaddrs_p = POINTER(ifaddrs)
-ifaddrs._fields_ = [
- ('ifa_next', ifaddrs_p),
- ('ifa_name', c_char_p),
- ('ifa_flags', c_uint32),
- ('ifa_addr', POINTER(sockaddr)),
- ('ifa_netmask', POINTER(sockaddr)),
- ('ifa_dstaddr', POINTER(sockaddr)),
- ('ifa_data', c_void_p)]
-
-getifaddrs = libc.getifaddrs
-getifaddrs.argtypes = [POINTER(ifaddrs_p)]
-getifaddrs.restype = c_int
-
-freeifaddrs = libc.freeifaddrs
-freeifaddrs.argtypes = [ifaddrs_p]
-
-def _interfaces():
- """
- Call C{getifaddrs(3)} and return a list of tuples of interface name, address
- family, and human-readable address representing its results.
- """
- ifaddrs = ifaddrs_p()
- if getifaddrs(pointer(ifaddrs)) < 0:
- raise OSError()
- results = []
- try:
- while ifaddrs:
- if ifaddrs[0].ifa_addr:
- family = ifaddrs[0].ifa_addr[0].sin_family
- if family == AF_INET:
- addr = cast(ifaddrs[0].ifa_addr, POINTER(sockaddr_in))
- elif family == AF_INET6:
- addr = cast(ifaddrs[0].ifa_addr, POINTER(sockaddr_in6))
- else:
- addr = None
-
- if addr:
- packed = ''.join(map(chr, addr[0].sin_addr.in_addr[:]))
- results.append((
- ifaddrs[0].ifa_name,
- family,
- inet_ntop(family, packed)))
-
- ifaddrs = ifaddrs[0].ifa_next
- finally:
- freeifaddrs(ifaddrs)
- return results
-
-
-
-def posixGetLinkLocalIPv6Addresses():
- """
- Return a list of strings in colon-hex format representing all the link local
- IPv6 addresses available on the system, as reported by I{getifaddrs(3)}.
- """
- retList = []
- for (interface, family, address) in _interfaces():
- if family == socket.AF_INET6 and address.startswith('fe80:'):
- retList.append('%s%%%s' % (address, interface))
- return retList
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_win32ifaces.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_win32ifaces.py
deleted file mode 100755
index 4a1e82b1..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/_win32ifaces.py
+++ /dev/null
@@ -1,119 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Windows implementation of local network interface enumeration.
-"""
-
-from socket import socket, AF_INET6, SOCK_STREAM
-from ctypes import (
- WinDLL, byref, create_string_buffer, c_int, c_void_p,
- POINTER, Structure, cast, string_at)
-
-WS2_32 = WinDLL('ws2_32')
-
-SOCKET = c_int
-DWORD = c_int
-LPVOID = c_void_p
-LPSOCKADDR = c_void_p
-LPWSAPROTOCOL_INFO = c_void_p
-LPTSTR = c_void_p
-LPDWORD = c_void_p
-LPWSAOVERLAPPED = c_void_p
-LPWSAOVERLAPPED_COMPLETION_ROUTINE = c_void_p
-
-# http://msdn.microsoft.com/en-us/library/ms741621(v=VS.85).aspx
-# int WSAIoctl(
-# __in SOCKET s,
-# __in DWORD dwIoControlCode,
-# __in LPVOID lpvInBuffer,
-# __in DWORD cbInBuffer,
-# __out LPVOID lpvOutBuffer,
-# __in DWORD cbOutBuffer,
-# __out LPDWORD lpcbBytesReturned,
-# __in LPWSAOVERLAPPED lpOverlapped,
-# __in LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
-# );
-WSAIoctl = WS2_32.WSAIoctl
-WSAIoctl.argtypes = [
- SOCKET, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD,
- LPWSAOVERLAPPED, LPWSAOVERLAPPED_COMPLETION_ROUTINE]
-WSAIoctl.restype = c_int
-
-# http://msdn.microsoft.com/en-us/library/ms741516(VS.85).aspx
-# INT WSAAPI WSAAddressToString(
-# __in LPSOCKADDR lpsaAddress,
-# __in DWORD dwAddressLength,
-# __in_opt LPWSAPROTOCOL_INFO lpProtocolInfo,
-# __inout LPTSTR lpszAddressString,
-# __inout LPDWORD lpdwAddressStringLength
-# );
-WSAAddressToString = WS2_32.WSAAddressToStringA
-WSAAddressToString.argtypes = [
- LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFO, LPTSTR, LPDWORD]
-WSAAddressToString.restype = c_int
-
-
-SIO_ADDRESS_LIST_QUERY = 0x48000016
-WSAEFAULT = 10014
-
-class SOCKET_ADDRESS(Structure):
- _fields_ = [('lpSockaddr', c_void_p),
- ('iSockaddrLength', c_int)]
-
-
-
-def make_SAL(ln):
- class SOCKET_ADDRESS_LIST(Structure):
- _fields_ = [('iAddressCount', c_int),
- ('Address', SOCKET_ADDRESS * ln)]
- return SOCKET_ADDRESS_LIST
-
-
-
-def win32GetLinkLocalIPv6Addresses():
- """
- Return a list of strings in colon-hex format representing all the link local
- IPv6 addresses available on the system, as reported by
- I{WSAIoctl}/C{SIO_ADDRESS_LIST_QUERY}.
- """
- s = socket(AF_INET6, SOCK_STREAM)
- size = 4096
- retBytes = c_int()
- for i in range(2):
- buf = create_string_buffer(size)
- ret = WSAIoctl(
- s.fileno(),
- SIO_ADDRESS_LIST_QUERY, 0, 0, buf, size, byref(retBytes), 0, 0)
-
- # WSAIoctl might fail with WSAEFAULT, which means there was not enough
- # space in the buffer we gave it. There's no way to check the errno
- # until Python 2.6, so we don't even try. :/ Maybe if retBytes is still
- # 0 another error happened, though.
- if ret and retBytes.value:
- size = retBytes.value
- else:
- break
-
- # If it failed, then we'll just have to give up. Still no way to see why.
- if ret:
- raise RuntimeError("WSAIoctl failure")
-
- addrList = cast(buf, POINTER(make_SAL(0)))
- addrCount = addrList[0].iAddressCount
- addrList = cast(buf, POINTER(make_SAL(addrCount)))
-
- addressStringBufLength = 1024
- addressStringBuf = create_string_buffer(addressStringBufLength)
-
- retList = []
- for i in range(addrList[0].iAddressCount):
- retBytes.value = addressStringBufLength
- addr = addrList[0].Address[i]
- ret = WSAAddressToString(
- addr.lpSockaddr, addr.iSockaddrLength, 0, addressStringBuf,
- byref(retBytes))
- if ret:
- raise RuntimeError("WSAAddressToString failure")
- retList.append(string_at(addressStringBuf))
- return [addr for addr in retList if '%' in addr]
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/connectionmixins.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/connectionmixins.py
deleted file mode 100755
index 655f9092..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/connectionmixins.py
+++ /dev/null
@@ -1,649 +0,0 @@
-# -*- test-case-name: twisted.internet.test.test_tcp -*-
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Various helpers for tests for connection-oriented transports.
-"""
-
-import socket
-
-from gc import collect
-from weakref import ref
-
-from zope.interface import implements
-from zope.interface.verify import verifyObject
-
-from twisted.python import context, log
-from twisted.python.failure import Failure
-from twisted.python.runtime import platform
-from twisted.python.log import ILogContext, msg, err
-from twisted.internet.defer import Deferred, gatherResults, succeed, fail
-from twisted.internet.interfaces import (
- IConnector, IResolverSimple, IReactorFDSet)
-from twisted.internet.protocol import ClientFactory, Protocol, ServerFactory
-from twisted.test.test_tcp import ClosingProtocol
-from twisted.trial.unittest import SkipTest
-from twisted.internet.error import DNSLookupError
-from twisted.internet.interfaces import ITLSTransport
-from twisted.internet.test.reactormixins import ConnectableProtocol
-from twisted.internet.test.reactormixins import runProtocolsWithReactor
-from twisted.internet.test.reactormixins import needsRunningReactor
-
-
-
-def serverFactoryFor(protocol):
- """
- Helper function which returns a L{ServerFactory} which will build instances
- of C{protocol}.
-
- @param protocol: A callable which returns an L{IProtocol} provider to be
- used to handle connections to the port the returned factory listens on.
- """
- factory = ServerFactory()
- factory.protocol = protocol
- return factory
-
-# ServerFactory is good enough for client endpoints, too.
-factoryFor = serverFactoryFor
-
-
-
-def findFreePort(interface='127.0.0.1', family=socket.AF_INET,
- type=socket.SOCK_STREAM):
- """
- Ask the platform to allocate a free port on the specified interface, then
- release the socket and return the address which was allocated.
-
- @param interface: The local address to try to bind the port on.
- @type interface: C{str}
-
- @param type: The socket type which will use the resulting port.
-
- @return: A two-tuple of address and port, like that returned by
- L{socket.getsockname}.
- """
- addr = socket.getaddrinfo(interface, 0)[0][4]
- probe = socket.socket(family, type)
- try:
- probe.bind(addr)
- return probe.getsockname()
- finally:
- probe.close()
-
-
-
-def _getWriters(reactor):
- """
- Like L{IReactorFDSet.getWriters}, but with support for IOCP reactor as
- well.
- """
- if IReactorFDSet.providedBy(reactor):
- return reactor.getWriters()
- elif 'IOCP' in reactor.__class__.__name__:
- return reactor.handles
- else:
- # Cannot tell what is going on.
- raise Exception("Cannot find writers on %r" % (reactor,))
-
-
-
-class _AcceptOneClient(ServerFactory):
- """
- This factory fires a L{Deferred} with a protocol instance shortly after it
- is constructed (hopefully long enough afterwards so that it has been
- connected to a transport).
-
- @ivar reactor: The reactor used to schedule the I{shortly}.
-
- @ivar result: A L{Deferred} which will be fired with the protocol instance.
- """
- def __init__(self, reactor, result):
- self.reactor = reactor
- self.result = result
-
-
- def buildProtocol(self, addr):
- protocol = ServerFactory.buildProtocol(self, addr)
- self.reactor.callLater(0, self.result.callback, protocol)
- return protocol
-
-
-
-class _SimplePullProducer(object):
- """
- A pull producer which writes one byte whenever it is resumed. For use by
- L{test_unregisterProducerAfterDisconnect}.
- """
- def __init__(self, consumer):
- self.consumer = consumer
-
-
- def stopProducing(self):
- pass
-
-
- def resumeProducing(self):
- log.msg("Producer.resumeProducing")
- self.consumer.write('x')
-
-
-
-class Stop(ClientFactory):
- """
- A client factory which stops a reactor when a connection attempt fails.
- """
- failReason = None
-
- def __init__(self, reactor):
- self.reactor = reactor
-
-
- def clientConnectionFailed(self, connector, reason):
- self.failReason = reason
- msg("Stop(CF) cCFailed: %s" % (reason.getErrorMessage(),))
- self.reactor.stop()
-
-
-
-class FakeResolver(object):
- """
- A resolver implementation based on a C{dict} mapping names to addresses.
- """
- implements(IResolverSimple)
-
- def __init__(self, names):
- self.names = names
-
-
- def getHostByName(self, name, timeout):
- try:
- return succeed(self.names[name])
- except KeyError:
- return fail(DNSLookupError("FakeResolver couldn't find " + name))
-
-
-
-class ClosingLaterProtocol(ConnectableProtocol):
- """
- ClosingLaterProtocol exchanges one byte with its peer and then disconnects
- itself. This is mostly a work-around for the fact that connectionMade is
- called before the SSL handshake has completed.
- """
- def __init__(self, onConnectionLost):
- self.lostConnectionReason = None
- self.onConnectionLost = onConnectionLost
-
-
- def connectionMade(self):
- msg("ClosingLaterProtocol.connectionMade")
-
-
- def dataReceived(self, bytes):
- msg("ClosingLaterProtocol.dataReceived %r" % (bytes,))
- self.transport.loseConnection()
-
-
- def connectionLost(self, reason):
- msg("ClosingLaterProtocol.connectionLost")
- self.lostConnectionReason = reason
- self.onConnectionLost.callback(self)
-
-
-
-class ConnectionTestsMixin(object):
- """
- This mixin defines test methods which should apply to most L{ITransport}
- implementations.
- """
-
- # This should be a reactormixins.EndpointCreator instance.
- endpoints = None
-
-
- def test_logPrefix(self):
- """
- Client and server transports implement L{ILoggingContext.logPrefix} to
- return a message reflecting the protocol they are running.
- """
- class CustomLogPrefixProtocol(ConnectableProtocol):
- def __init__(self, prefix):
- self._prefix = prefix
- self.system = None
-
- def connectionMade(self):
- self.transport.write("a")
-
- def logPrefix(self):
- return self._prefix
-
- def dataReceived(self, bytes):
- self.system = context.get(ILogContext)["system"]
- self.transport.write("b")
- # Only close connection if both sides have received data, so
- # that both sides have system set.
- if "b" in bytes:
- self.transport.loseConnection()
-
- client = CustomLogPrefixProtocol("Custom Client")
- server = CustomLogPrefixProtocol("Custom Server")
- runProtocolsWithReactor(self, server, client, self.endpoints)
- self.assertIn("Custom Client", client.system)
- self.assertIn("Custom Server", server.system)
-
-
- def test_writeAfterDisconnect(self):
- """
- After a connection is disconnected, L{ITransport.write} and
- L{ITransport.writeSequence} are no-ops.
- """
- reactor = self.buildReactor()
-
- finished = []
-
- serverConnectionLostDeferred = Deferred()
- protocol = lambda: ClosingLaterProtocol(serverConnectionLostDeferred)
- portDeferred = self.endpoints.server(reactor).listen(
- serverFactoryFor(protocol))
- def listening(port):
- msg("Listening on %r" % (port.getHost(),))
- endpoint = self.endpoints.client(reactor, port.getHost())
-
- lostConnectionDeferred = Deferred()
- protocol = lambda: ClosingLaterProtocol(lostConnectionDeferred)
- client = endpoint.connect(factoryFor(protocol))
- def write(proto):
- msg("About to write to %r" % (proto,))
- proto.transport.write('x')
- client.addCallbacks(write, lostConnectionDeferred.errback)
-
- def disconnected(proto):
- msg("%r disconnected" % (proto,))
- proto.transport.write("some bytes to get lost")
- proto.transport.writeSequence(["some", "more"])
- finished.append(True)
-
- lostConnectionDeferred.addCallback(disconnected)
- serverConnectionLostDeferred.addCallback(disconnected)
- return gatherResults([
- lostConnectionDeferred,
- serverConnectionLostDeferred])
-
- def onListen():
- portDeferred.addCallback(listening)
- portDeferred.addErrback(err)
- portDeferred.addCallback(lambda ignored: reactor.stop())
- needsRunningReactor(reactor, onListen)
-
- self.runReactor(reactor)
- self.assertEqual(finished, [True, True])
-
-
- def test_protocolGarbageAfterLostConnection(self):
- """
- After the connection a protocol is being used for is closed, the
- reactor discards all of its references to the protocol.
- """
- lostConnectionDeferred = Deferred()
- clientProtocol = ClosingLaterProtocol(lostConnectionDeferred)
- clientRef = ref(clientProtocol)
-
- reactor = self.buildReactor()
- portDeferred = self.endpoints.server(reactor).listen(
- serverFactoryFor(Protocol))
- def listening(port):
- msg("Listening on %r" % (port.getHost(),))
- endpoint = self.endpoints.client(reactor, port.getHost())
-
- client = endpoint.connect(factoryFor(lambda: clientProtocol))
- def disconnect(proto):
- msg("About to disconnect %r" % (proto,))
- proto.transport.loseConnection()
- client.addCallback(disconnect)
- client.addErrback(lostConnectionDeferred.errback)
- return lostConnectionDeferred
-
- def onListening():
- portDeferred.addCallback(listening)
- portDeferred.addErrback(err)
- portDeferred.addBoth(lambda ignored: reactor.stop())
- needsRunningReactor(reactor, onListening)
-
- self.runReactor(reactor)
-
- # Drop the reference and get the garbage collector to tell us if there
- # are no references to the protocol instance left in the reactor.
- clientProtocol = None
- collect()
- self.assertIdentical(None, clientRef())
-
-
-
-class LogObserverMixin(object):
- """
- Mixin for L{TestCase} subclasses which want to observe log events.
- """
- def observe(self):
- loggedMessages = []
- log.addObserver(loggedMessages.append)
- self.addCleanup(log.removeObserver, loggedMessages.append)
- return loggedMessages
-
-
-
-class BrokenContextFactory(object):
- """
- A context factory with a broken C{getContext} method, for exercising the
- error handling for such a case.
- """
- message = "Some path was wrong maybe"
-
- def getContext(self):
- raise ValueError(self.message)
-
-
-
-class TCPClientTestsMixin(object):
- """
- This mixin defines tests applicable to TCP client implementations. Classes
- which mix this in must provide all of the documented instance variables in
- order to specify how the test works. These are documented as instance
- variables rather than declared as methods due to some peculiar inheritance
- ordering concerns, but they are effectively abstract methods.
-
- This must be mixed in to a L{ReactorBuilder
- <twisted.internet.test.reactormixins.ReactorBuilder>} subclass, as it
- depends on several of its methods.
-
- @ivar endpoints: A L{twisted.internet.test.reactormixins.EndpointCreator}
- instance.
-
- @ivar interface: An IP address literal to locally bind a socket to as well
- as to connect to. This can be any valid interface for the local host.
- @type interface: C{str}
-
- @ivar port: An unused local listening port to listen on and connect to.
- This will be used in conjunction with the C{interface}. (Depending on
- what they're testing, some tests will locate their own port with
- L{findFreePort} instead.)
- @type port: C{int}
-
- @ivar family: an address family constant, such as L{socket.AF_INET},
- L{socket.AF_INET6}, or L{socket.AF_UNIX}, which indicates the address
- family of the transport type under test.
- @type family: C{int}
-
- @ivar addressClass: the L{twisted.internet.interfaces.IAddress} implementor
- associated with the transport type under test. Must also be a
- 3-argument callable which produces an instance of same.
- @type addressClass: C{type}
-
- @ivar fakeDomainName: A fake domain name to use, to simulate hostname
- resolution and to distinguish between hostnames and IP addresses where
- necessary.
- @type fakeDomainName: C{str}
- """
-
- def test_interface(self):
- """
- L{IReactorTCP.connectTCP} returns an object providing L{IConnector}.
- """
- reactor = self.buildReactor()
- connector = reactor.connectTCP(self.interface, self.port,
- ClientFactory())
- self.assertTrue(verifyObject(IConnector, connector))
-
-
- def test_clientConnectionFailedStopsReactor(self):
- """
- The reactor can be stopped by a client factory's
- C{clientConnectionFailed} method.
- """
- host, port = findFreePort(self.interface, self.family)[:2]
- reactor = self.buildReactor()
- needsRunningReactor(
- reactor, lambda: reactor.connectTCP(host, port, Stop(reactor)))
- self.runReactor(reactor)
-
-
- def test_addresses(self):
- """
- A client's transport's C{getHost} and C{getPeer} return L{IPv4Address}
- instances which have the dotted-quad string form of the resolved
- adddress of the local and remote endpoints of the connection
- respectively as their C{host} attribute, not the hostname originally
- passed in to L{connectTCP
- <twisted.internet.interfaces.IReactorTCP.connectTCP>}, if a hostname
- was used.
- """
- host, port = findFreePort(self.interface, self.family)[:2]
- reactor = self.buildReactor()
- fakeDomain = self.fakeDomainName
- reactor.installResolver(FakeResolver({fakeDomain: self.interface}))
-
- server = reactor.listenTCP(
- 0, serverFactoryFor(Protocol), interface=host)
- serverAddress = server.getHost()
-
- addresses = {'host': None, 'peer': None}
- class CheckAddress(Protocol):
- def makeConnection(self, transport):
- addresses['host'] = transport.getHost()
- addresses['peer'] = transport.getPeer()
- reactor.stop()
-
- clientFactory = Stop(reactor)
- clientFactory.protocol = CheckAddress
-
- def connectMe():
- reactor.connectTCP(
- fakeDomain, server.getHost().port, clientFactory,
- bindAddress=(self.interface, port))
- needsRunningReactor(reactor, connectMe)
-
- self.runReactor(reactor)
-
- if clientFactory.failReason:
- self.fail(clientFactory.failReason.getTraceback())
-
- self.assertEqual(
- addresses['host'],
- self.addressClass('TCP', self.interface, port))
- self.assertEqual(
- addresses['peer'],
- self.addressClass('TCP', self.interface, serverAddress.port))
-
-
- def test_connectEvent(self):
- """
- This test checks that we correctly get notifications event for a
- client. This ought to prevent a regression under Windows using the
- GTK2 reactor. See #3925.
- """
- reactor = self.buildReactor()
-
- server = reactor.listenTCP(0, serverFactoryFor(Protocol),
- interface=self.interface)
- connected = []
-
- class CheckConnection(Protocol):
- def connectionMade(self):
- connected.append(self)
- reactor.stop()
-
- clientFactory = Stop(reactor)
- clientFactory.protocol = CheckConnection
-
- needsRunningReactor(reactor, lambda: reactor.connectTCP(
- self.interface, server.getHost().port, clientFactory))
-
- reactor.run()
-
- self.assertTrue(connected)
-
-
- def test_unregisterProducerAfterDisconnect(self):
- """
- If a producer is unregistered from a L{ITCPTransport} provider after
- the transport has been disconnected (by the peer) and after
- L{ITCPTransport.loseConnection} has been called, the transport is not
- re-added to the reactor as a writer as would be necessary if the
- transport were still connected.
- """
- reactor = self.buildReactor()
- port = reactor.listenTCP(0, serverFactoryFor(ClosingProtocol),
- interface=self.interface)
-
- finished = Deferred()
- finished.addErrback(log.err)
- finished.addCallback(lambda ign: reactor.stop())
-
- writing = []
-
- class ClientProtocol(Protocol):
- """
- Protocol to connect, register a producer, try to lose the
- connection, wait for the server to disconnect from us, and then
- unregister the producer.
- """
- def connectionMade(self):
- log.msg("ClientProtocol.connectionMade")
- self.transport.registerProducer(
- _SimplePullProducer(self.transport), False)
- self.transport.loseConnection()
-
- def connectionLost(self, reason):
- log.msg("ClientProtocol.connectionLost")
- self.unregister()
- writing.append(self.transport in _getWriters(reactor))
- finished.callback(None)
-
- def unregister(self):
- log.msg("ClientProtocol unregister")
- self.transport.unregisterProducer()
-
- clientFactory = ClientFactory()
- clientFactory.protocol = ClientProtocol
- reactor.connectTCP(self.interface, port.getHost().port, clientFactory)
- self.runReactor(reactor)
- self.assertFalse(writing[0],
- "Transport was writing after unregisterProducer.")
-
-
- def test_disconnectWhileProducing(self):
- """
- If L{ITCPTransport.loseConnection} is called while a producer is
- registered with the transport, the connection is closed after the
- producer is unregistered.
- """
- reactor = self.buildReactor()
-
- # For some reason, pyobject/pygtk will not deliver the close
- # notification that should happen after the unregisterProducer call in
- # this test. The selectable is in the write notification set, but no
- # notification ever arrives. Probably for the same reason #5233 led
- # win32eventreactor to be broken.
- skippedReactors = ["Glib2Reactor", "Gtk2Reactor"]
- reactorClassName = reactor.__class__.__name__
- if reactorClassName in skippedReactors and platform.isWindows():
- raise SkipTest(
- "A pygobject/pygtk bug disables this functionality on Windows.")
-
- class Producer:
- def resumeProducing(self):
- log.msg("Producer.resumeProducing")
-
- port = reactor.listenTCP(0, serverFactoryFor(Protocol),
- interface=self.interface)
-
- finished = Deferred()
- finished.addErrback(log.err)
- finished.addCallback(lambda ign: reactor.stop())
-
- class ClientProtocol(Protocol):
- """
- Protocol to connect, register a producer, try to lose the
- connection, unregister the producer, and wait for the connection to
- actually be lost.
- """
- def connectionMade(self):
- log.msg("ClientProtocol.connectionMade")
- self.transport.registerProducer(Producer(), False)
- self.transport.loseConnection()
- # Let the reactor tick over, in case synchronously calling
- # loseConnection and then unregisterProducer is the same as
- # synchronously calling unregisterProducer and then
- # loseConnection (as it is in several reactors).
- reactor.callLater(0, reactor.callLater, 0, self.unregister)
-
- def unregister(self):
- log.msg("ClientProtocol unregister")
- self.transport.unregisterProducer()
- # This should all be pretty quick. Fail the test
- # if we don't get a connectionLost event really
- # soon.
- reactor.callLater(
- 1.0, finished.errback,
- Failure(Exception("Connection was not lost")))
-
- def connectionLost(self, reason):
- log.msg("ClientProtocol.connectionLost")
- finished.callback(None)
-
- clientFactory = ClientFactory()
- clientFactory.protocol = ClientProtocol
- reactor.connectTCP(self.interface, port.getHost().port, clientFactory)
- self.runReactor(reactor)
- # If the test failed, we logged an error already and trial
- # will catch it.
-
-
- def test_badContext(self):
- """
- If the context factory passed to L{ITCPTransport.startTLS} raises an
- exception from its C{getContext} method, that exception is raised by
- L{ITCPTransport.startTLS}.
- """
- reactor = self.buildReactor()
-
- brokenFactory = BrokenContextFactory()
- results = []
-
- serverFactory = ServerFactory()
- serverFactory.protocol = Protocol
-
- port = reactor.listenTCP(0, serverFactory, interface=self.interface)
- endpoint = self.endpoints.client(reactor, port.getHost())
-
- clientFactory = ClientFactory()
- clientFactory.protocol = Protocol
- connectDeferred = endpoint.connect(clientFactory)
-
- def connected(protocol):
- if not ITLSTransport.providedBy(protocol.transport):
- results.append("skip")
- else:
- results.append(self.assertRaises(ValueError,
- protocol.transport.startTLS,
- brokenFactory))
-
- def connectFailed(failure):
- results.append(failure)
-
- def whenRun():
- connectDeferred.addCallback(connected)
- connectDeferred.addErrback(connectFailed)
- connectDeferred.addBoth(lambda ign: reactor.stop())
- needsRunningReactor(reactor, whenRun)
-
- self.runReactor(reactor)
-
- self.assertEqual(len(results), 1,
- "more than one callback result: %s" % (results,))
-
- if isinstance(results[0], Failure):
- # self.fail(Failure)
- results[0].raiseException()
- if results[0] == "skip":
- raise SkipTest("Reactor does not support ITLSTransport")
- self.assertEqual(BrokenContextFactory.message, str(results[0]))
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/not-a-certificate b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/not-a-certificate
deleted file mode 100644
index 316453dd..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/not-a-certificate
+++ /dev/null
@@ -1 +0,0 @@
-This file is not a certificate; it is present to make sure that it will be skipped.
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing1.pem b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing1.pem
deleted file mode 100644
index 75e47a64..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing1.pem
+++ /dev/null
@@ -1,26 +0,0 @@
-
-This is a self-signed certificate authority certificate to be used in tests.
-
-It was created with the following command:
-certcreate -f thing1.pem -h fake-ca-1.example.com -e noreply@example.com \
- -S 1234 -o 'Twisted Matrix Labs'
-
-'certcreate' may be obtained from <http://divmod.org/trac/wiki/DivmodEpsilon>
-
------BEGIN CERTIFICATE-----
-MIICwjCCAisCAgTSMA0GCSqGSIb3DQEBBAUAMIGoMREwDwYDVQQLEwhTZWN1cml0
-eTEcMBoGA1UEChMTVHdpc3RlZCBNYXRyaXggTGFiczEeMBwGA1UEAxMVZmFrZS1j
-YS0xLmV4YW1wbGUuY29tMREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UEBhMCVVMx
-IjAgBgkqhkiG9w0BCQEWE25vcmVwbHlAZXhhbXBsZS5jb20xETAPBgNVBAcTCE5l
-dyBZb3JrMB4XDTEwMDkyMTAxMjUxNFoXDTExMDkyMTAxMjUxNFowgagxETAPBgNV
-BAsTCFNlY3VyaXR5MRwwGgYDVQQKExNUd2lzdGVkIE1hdHJpeCBMYWJzMR4wHAYD
-VQQDExVmYWtlLWNhLTEuZXhhbXBsZS5jb20xETAPBgNVBAgTCE5ldyBZb3JrMQsw
-CQYDVQQGEwJVUzEiMCAGCSqGSIb3DQEJARYTbm9yZXBseUBleGFtcGxlLmNvbTER
-MA8GA1UEBxMITmV3IFlvcmswgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALRb
-VqC0CsaFgq1vbwPfs8zoP3ZYC/0sPMv0RJN+f3Dc7Q6YgNHS7o7TM3uAy/McADeW
-rwVuNJGe9k+4ZBHysmBH1sG64fHT5TlK9saPcUQqkubSWj4cKSDtVbQERWqC5Dy+
-qTQeZGYoPEMlnRXgMpST04DG//Dgzi4PYqUOjwxTAgMBAAEwDQYJKoZIhvcNAQEE
-BQADgYEAqNEdMXWEs8Co76wxL3/cSV3MjiAroVxJdI/3EzlnfPi1JeibbdWw31fC
-bn6428KTjjfhS31zo1yHG3YNXFEJXRscwLAH7ogz5kJwZMy/oS/96EFM10bkNwkK
-v+nWKN8i3t/E5TEIl3BPN8tchtWmH0rycVuzs5LwaewwR1AnUE4=
------END CERTIFICATE-----
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2-duplicate.pem b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2-duplicate.pem
deleted file mode 100644
index 429e1211..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2-duplicate.pem
+++ /dev/null
@@ -1,26 +0,0 @@
-
-This is a self-signed certificate authority certificate to be used in tests.
-
-It was created with the following command:
-certcreate -f thing2.pem -h fake-ca-2.example.com -e noreply@example.com \
- -S 1234 -o 'Twisted Matrix Labs'
-
-'certcreate' may be obtained from <http://divmod.org/trac/wiki/DivmodEpsilon>
-
------BEGIN CERTIFICATE-----
-MIICwjCCAisCAgTSMA0GCSqGSIb3DQEBBAUAMIGoMREwDwYDVQQLEwhTZWN1cml0
-eTEcMBoGA1UEChMTVHdpc3RlZCBNYXRyaXggTGFiczEeMBwGA1UEAxMVZmFrZS1j
-YS0yLmV4YW1wbGUuY29tMREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UEBhMCVVMx
-IjAgBgkqhkiG9w0BCQEWE25vcmVwbHlAZXhhbXBsZS5jb20xETAPBgNVBAcTCE5l
-dyBZb3JrMB4XDTEwMDkyMTAxMjUzMVoXDTExMDkyMTAxMjUzMVowgagxETAPBgNV
-BAsTCFNlY3VyaXR5MRwwGgYDVQQKExNUd2lzdGVkIE1hdHJpeCBMYWJzMR4wHAYD
-VQQDExVmYWtlLWNhLTIuZXhhbXBsZS5jb20xETAPBgNVBAgTCE5ldyBZb3JrMQsw
-CQYDVQQGEwJVUzEiMCAGCSqGSIb3DQEJARYTbm9yZXBseUBleGFtcGxlLmNvbTER
-MA8GA1UEBxMITmV3IFlvcmswgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMNn
-b3EcKqBedQed1qJC4uGVx8PYmn2vxL3QwCVW1w0VjpZXyhCq/2VrYBhJAXRzpfvE
-dCqhtJKcdifwavUrTfr4yXu1MvWA0YuaAkj1TbmlHHQYACf3h+MPOXroYzhT72bO
-FSSLDWuitj0ozR+2Fk15QwLWUxaYLmwylxXAf7vpAgMBAAEwDQYJKoZIhvcNAQEE
-BQADgYEADB2N6VHHhm5M2rJqqGDXMm2dU+7abxiuN+PUygN2LXIsqdGBS6U7/rta
-lJNVeRaM423c8imfuklkIBG9Msn5+xm1xIMIULoi/efActDLbsX1x6IyHQrG5aDP
-/RMKBio9RjS8ajgSwyYVUZiCZBsn/T0/JS8K61YLpiv4Tg8uXmM=
------END CERTIFICATE-----
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2.pem b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2.pem
deleted file mode 100644
index 429e1211..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fake_CAs/thing2.pem
+++ /dev/null
@@ -1,26 +0,0 @@
-
-This is a self-signed certificate authority certificate to be used in tests.
-
-It was created with the following command:
-certcreate -f thing2.pem -h fake-ca-2.example.com -e noreply@example.com \
- -S 1234 -o 'Twisted Matrix Labs'
-
-'certcreate' may be obtained from <http://divmod.org/trac/wiki/DivmodEpsilon>
-
------BEGIN CERTIFICATE-----
-MIICwjCCAisCAgTSMA0GCSqGSIb3DQEBBAUAMIGoMREwDwYDVQQLEwhTZWN1cml0
-eTEcMBoGA1UEChMTVHdpc3RlZCBNYXRyaXggTGFiczEeMBwGA1UEAxMVZmFrZS1j
-YS0yLmV4YW1wbGUuY29tMREwDwYDVQQIEwhOZXcgWW9yazELMAkGA1UEBhMCVVMx
-IjAgBgkqhkiG9w0BCQEWE25vcmVwbHlAZXhhbXBsZS5jb20xETAPBgNVBAcTCE5l
-dyBZb3JrMB4XDTEwMDkyMTAxMjUzMVoXDTExMDkyMTAxMjUzMVowgagxETAPBgNV
-BAsTCFNlY3VyaXR5MRwwGgYDVQQKExNUd2lzdGVkIE1hdHJpeCBMYWJzMR4wHAYD
-VQQDExVmYWtlLWNhLTIuZXhhbXBsZS5jb20xETAPBgNVBAgTCE5ldyBZb3JrMQsw
-CQYDVQQGEwJVUzEiMCAGCSqGSIb3DQEJARYTbm9yZXBseUBleGFtcGxlLmNvbTER
-MA8GA1UEBxMITmV3IFlvcmswgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMNn
-b3EcKqBedQed1qJC4uGVx8PYmn2vxL3QwCVW1w0VjpZXyhCq/2VrYBhJAXRzpfvE
-dCqhtJKcdifwavUrTfr4yXu1MvWA0YuaAkj1TbmlHHQYACf3h+MPOXroYzhT72bO
-FSSLDWuitj0ozR+2Fk15QwLWUxaYLmwylxXAf7vpAgMBAAEwDQYJKoZIhvcNAQEE
-BQADgYEADB2N6VHHhm5M2rJqqGDXMm2dU+7abxiuN+PUygN2LXIsqdGBS6U7/rta
-lJNVeRaM423c8imfuklkIBG9Msn5+xm1xIMIULoi/efActDLbsX1x6IyHQrG5aDP
-/RMKBio9RjS8ajgSwyYVUZiCZBsn/T0/JS8K61YLpiv4Tg8uXmM=
------END CERTIFICATE-----
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fakeendpoint.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fakeendpoint.py
deleted file mode 100755
index dbb74197..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/fakeendpoint.py
+++ /dev/null
@@ -1,66 +0,0 @@
-# -*- test-case-name: twisted.internet.test.test_endpoints -*-
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Fake client and server endpoint string parser plugins for testing purposes.
-"""
-
-from zope.interface.declarations import implements
-from twisted.plugin import IPlugin
-from twisted.internet.interfaces import (IStreamClientEndpoint,
- IStreamServerEndpoint,
- IStreamClientEndpointStringParser,
- IStreamServerEndpointStringParser)
-
-class PluginBase(object):
- implements(IPlugin)
-
- def __init__(self, pfx):
- self.prefix = pfx
-
-
-
-class FakeClientParser(PluginBase):
-
- implements(IStreamClientEndpointStringParser)
-
- def parseStreamClient(self, *a, **kw):
- return StreamClient(self, a, kw)
-
-
-
-class FakeParser(PluginBase):
-
- implements(IStreamServerEndpointStringParser)
-
- def parseStreamServer(self, *a, **kw):
- return StreamServer(self, a, kw)
-
-
-
-class EndpointBase(object):
-
- def __init__(self, parser, args, kwargs):
- self.parser = parser
- self.args = args
- self.kwargs = kwargs
-
-
-
-class StreamClient(EndpointBase):
-
- implements(IStreamClientEndpoint)
-
-
-
-class StreamServer(EndpointBase):
-
- implements(IStreamServerEndpoint)
-
-
-
-# Instantiate plugin interface providers to register them.
-fake = FakeParser('fake')
-fakeClient = FakeClientParser('cfake')
-
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/inlinecb_tests.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/inlinecb_tests.py
deleted file mode 100755
index a6d01218..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/inlinecb_tests.py
+++ /dev/null
@@ -1,92 +0,0 @@
-# -*- test-case-name: twisted.internet.test.test_inlinecb -*-
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.defer.inlineCallbacks}.
-
-These tests are defined in a non-C{test_*} module because they are
-syntactically invalid on python < 2.5. test_inlinecb will conditionally import
-these tests on python 2.5 and greater.
-
-Some tests for inlineCallbacks are defined in L{twisted.test.test_defgen} as
-well: see U{http://twistedmatrix.com/trac/ticket/4182}.
-"""
-
-from twisted.trial.unittest import TestCase
-from twisted.internet.defer import Deferred, returnValue, inlineCallbacks
-
-class NonLocalExitTests(TestCase):
- """
- It's possible for L{returnValue} to be (accidentally) invoked at a stack
- level below the L{inlineCallbacks}-decorated function which it is exiting.
- If this happens, L{returnValue} should report useful errors.
-
- If L{returnValue} is invoked from a function not decorated by
- L{inlineCallbacks}, it will emit a warning if it causes an
- L{inlineCallbacks} function further up the stack to exit.
- """
-
- def mistakenMethod(self):
- """
- This method mistakenly invokes L{returnValue}, despite the fact that it
- is not decorated with L{inlineCallbacks}.
- """
- returnValue(1)
-
-
- def assertMistakenMethodWarning(self, resultList):
- """
- Flush the current warnings and assert that we have been told that
- C{mistakenMethod} was invoked, and that the result from the Deferred
- that was fired (appended to the given list) is C{mistakenMethod}'s
- result. The warning should indicate that an inlineCallbacks function
- called 'inline' was made to exit.
- """
- self.assertEqual(resultList, [1])
- warnings = self.flushWarnings(offendingFunctions=[self.mistakenMethod])
- self.assertEqual(len(warnings), 1)
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(
- warnings[0]['message'],
- "returnValue() in 'mistakenMethod' causing 'inline' to exit: "
- "returnValue should only be invoked by functions decorated with "
- "inlineCallbacks")
-
-
- def test_returnValueNonLocalWarning(self):
- """
- L{returnValue} will emit a non-local exit warning in the simplest case,
- where the offending function is invoked immediately.
- """
- @inlineCallbacks
- def inline():
- self.mistakenMethod()
- returnValue(2)
- yield 0
- d = inline()
- results = []
- d.addCallback(results.append)
- self.assertMistakenMethodWarning(results)
-
-
- def test_returnValueNonLocalDeferred(self):
- """
- L{returnValue} will emit a non-local warning in the case where the
- L{inlineCallbacks}-decorated function has already yielded a Deferred
- and therefore moved its generator function along.
- """
- cause = Deferred()
- @inlineCallbacks
- def inline():
- yield cause
- self.mistakenMethod()
- returnValue(2)
- effect = inline()
- results = []
- effect.addCallback(results.append)
- self.assertEqual(results, [])
- cause.callback(1)
- self.assertMistakenMethodWarning(results)
-
-
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/process_helper.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/process_helper.py
deleted file mode 100755
index b921697a..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/process_helper.py
+++ /dev/null
@@ -1,33 +0,0 @@
-
-# A program which exits after starting a child which inherits its
-# stdin/stdout/stderr and keeps them open until stdin is closed.
-
-import sys, os
-
-def grandchild():
- sys.stdout.write('grandchild started')
- sys.stdout.flush()
- sys.stdin.read()
-
-def main():
- if sys.argv[1] == 'child':
- if sys.argv[2] == 'windows':
- import win32api as api, win32process as proc
- info = proc.STARTUPINFO()
- info.hStdInput = api.GetStdHandle(api.STD_INPUT_HANDLE)
- info.hStdOutput = api.GetStdHandle(api.STD_OUTPUT_HANDLE)
- info.hStdError = api.GetStdHandle(api.STD_ERROR_HANDLE)
- python = sys.executable
- scriptDir = os.path.dirname(__file__)
- scriptName = os.path.basename(__file__)
- proc.CreateProcess(
- None, " ".join((python, scriptName, "grandchild")), None,
- None, 1, 0, os.environ, scriptDir, info)
- else:
- if os.fork() == 0:
- grandchild()
- else:
- grandchild()
-
-if __name__ == '__main__':
- main()
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/reactormixins.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/reactormixins.py
deleted file mode 100755
index dc9a5d59..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/reactormixins.py
+++ /dev/null
@@ -1,409 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorTime}.
-"""
-
-__metaclass__ = type
-
-import os, signal, time
-
-from twisted.internet.defer import TimeoutError, Deferred, gatherResults
-from twisted.internet.protocol import ClientFactory, Protocol
-from twisted.trial.unittest import TestCase, SkipTest
-from twisted.python.runtime import platform
-from twisted.python.reflect import namedAny, fullyQualifiedName
-from twisted.python import log
-from twisted.python.failure import Failure
-
-# Access private APIs.
-if platform.isWindows():
- process = None
-else:
- from twisted.internet import process
-
-
-
-def needsRunningReactor(reactor, thunk):
- """
- Various functions within these tests need an already-running reactor at
- some point. They need to stop the reactor when the test has completed, and
- that means calling reactor.stop(). However, reactor.stop() raises an
- exception if the reactor isn't already running, so if the L{Deferred} that
- a particular API under test returns fires synchronously (as especially an
- endpoint's C{connect()} method may do, if the connect is to a local
- interface address) then the test won't be able to stop the reactor being
- tested and finish. So this calls C{thunk} only once C{reactor} is running.
-
- (This is just an alias for
- L{twisted.internet.interfaces.IReactorCore.callWhenRunning} on the given
- reactor parameter, in order to centrally reference the above paragraph and
- repeating it everywhere as a comment.)
-
- @param reactor: the L{twisted.internet.interfaces.IReactorCore} under test
-
- @param thunk: a 0-argument callable, which eventually finishes the test in
- question, probably in a L{Deferred} callback.
- """
- reactor.callWhenRunning(thunk)
-
-
-
-class ConnectableProtocol(Protocol):
- """
- A protocol to be used with L{runProtocolsWithReactor}.
-
- The protocol and its pair should eventually disconnect from each other.
-
- @ivar reactor: The reactor used in this test.
-
- @ivar disconnectReason: The L{Failure} passed to C{connectionLost}.
-
- @ivar _done: A L{Deferred} which will be fired when the connection is
- lost.
- """
-
- disconnectReason = None
-
- def _setAttributes(self, reactor, done):
- """
- Set attributes on the protocol that are known only externally; this
- will be called by L{runProtocolsWithReactor} when this protocol is
- instantiated.
-
- @param reactor: The reactor used in this test.
-
- @param done: A L{Deferred} which will be fired when the connection is
- lost.
- """
- self.reactor = reactor
- self._done = done
-
-
- def connectionLost(self, reason):
- self.disconnectReason = reason
- self._done.callback(None)
- del self._done
-
-
-
-class EndpointCreator:
- """
- Create client and server endpoints that know how to connect to each other.
- """
-
- def server(self, reactor):
- """
- Return an object providing C{IStreamServerEndpoint} for use in creating
- a server to use to establish the connection type to be tested.
- """
- raise NotImplementedError()
-
-
- def client(self, reactor, serverAddress):
- """
- Return an object providing C{IStreamClientEndpoint} for use in creating
- a client to use to establish the connection type to be tested.
- """
- raise NotImplementedError()
-
-
-
-class _SingleProtocolFactory(ClientFactory):
- """
- Factory to be used by L{runProtocolsWithReactor}.
-
- It always returns the same protocol (i.e. is intended for only a single connection).
- """
-
- def __init__(self, protocol):
- self._protocol = protocol
-
-
- def buildProtocol(self, addr):
- return self._protocol
-
-
-
-def runProtocolsWithReactor(reactorBuilder, serverProtocol, clientProtocol,
- endpointCreator):
- """
- Connect two protocols using endpoints and a new reactor instance.
-
- A new reactor will be created and run, with the client and server protocol
- instances connected to each other using the given endpoint creator. The
- protocols should run through some set of tests, then disconnect; when both
- have disconnected the reactor will be stopped and the function will
- return.
-
- @param reactorBuilder: A L{ReactorBuilder} instance.
-
- @param serverProtocol: A L{ConnectableProtocol} that will be the server.
-
- @param clientProtocol: A L{ConnectableProtocol} that will be the client.
-
- @param endpointCreator: An instance of L{EndpointCreator}.
-
- @return: The reactor run by this test.
- """
- reactor = reactorBuilder.buildReactor()
- serverProtocol._setAttributes(reactor, Deferred())
- clientProtocol._setAttributes(reactor, Deferred())
- serverFactory = _SingleProtocolFactory(serverProtocol)
- clientFactory = _SingleProtocolFactory(clientProtocol)
-
- # Listen on a port:
- serverEndpoint = endpointCreator.server(reactor)
- d = serverEndpoint.listen(serverFactory)
-
- # Connect to the port:
- def gotPort(p):
- clientEndpoint = endpointCreator.client(
- reactor, p.getHost())
- return clientEndpoint.connect(clientFactory)
- d.addCallback(gotPort)
-
- # Stop reactor when both connections are lost:
- def failed(result):
- log.err(result, "Connection setup failed.")
- disconnected = gatherResults([serverProtocol._done, clientProtocol._done])
- d.addCallback(lambda _: disconnected)
- d.addErrback(failed)
- d.addCallback(lambda _: needsRunningReactor(reactor, reactor.stop))
-
- reactorBuilder.runReactor(reactor)
- return reactor
-
-
-
-class ReactorBuilder:
- """
- L{TestCase} mixin which provides a reactor-creation API. This mixin
- defines C{setUp} and C{tearDown}, so mix it in before L{TestCase} or call
- its methods from the overridden ones in the subclass.
-
- @cvar skippedReactors: A dict mapping FQPN strings of reactors for
- which the tests defined by this class will be skipped to strings
- giving the skip message.
- @cvar requiredInterfaces: A C{list} of interfaces which the reactor must
- provide or these tests will be skipped. The default, C{None}, means
- that no interfaces are required.
- @ivar reactorFactory: A no-argument callable which returns the reactor to
- use for testing.
- @ivar originalHandler: The SIGCHLD handler which was installed when setUp
- ran and which will be re-installed when tearDown runs.
- @ivar _reactors: A list of FQPN strings giving the reactors for which
- TestCases will be created.
- """
-
- _reactors = [
- # Select works everywhere
- "twisted.internet.selectreactor.SelectReactor",
- ]
-
- if platform.isWindows():
- # PortableGtkReactor is only really interesting on Windows,
- # but not really Windows specific; if you want you can
- # temporarily move this up to the all-platforms list to test
- # it on other platforms. It's not there in general because
- # it's not _really_ worth it to support on other platforms,
- # since no one really wants to use it on other platforms.
- _reactors.extend([
- "twisted.internet.gtk2reactor.PortableGtkReactor",
- "twisted.internet.gireactor.PortableGIReactor",
- "twisted.internet.gtk3reactor.PortableGtk3Reactor",
- "twisted.internet.win32eventreactor.Win32Reactor",
- "twisted.internet.iocpreactor.reactor.IOCPReactor"])
- else:
- _reactors.extend([
- "twisted.internet.glib2reactor.Glib2Reactor",
- "twisted.internet.gtk2reactor.Gtk2Reactor",
- "twisted.internet.gireactor.GIReactor",
- "twisted.internet.gtk3reactor.Gtk3Reactor"])
- if platform.isMacOSX():
- _reactors.append("twisted.internet.cfreactor.CFReactor")
- else:
- _reactors.extend([
- "twisted.internet.pollreactor.PollReactor",
- "twisted.internet.epollreactor.EPollReactor"])
- if not platform.isLinux():
- # Presumably Linux is not going to start supporting kqueue, so
- # skip even trying this configuration.
- _reactors.extend([
- # Support KQueue on non-OS-X POSIX platforms for now.
- "twisted.internet.kqreactor.KQueueReactor",
- ])
-
- reactorFactory = None
- originalHandler = None
- requiredInterfaces = None
- skippedReactors = {}
-
- def setUp(self):
- """
- Clear the SIGCHLD handler, if there is one, to ensure an environment
- like the one which exists prior to a call to L{reactor.run}.
- """
- if not platform.isWindows():
- self.originalHandler = signal.signal(signal.SIGCHLD, signal.SIG_DFL)
-
-
- def tearDown(self):
- """
- Restore the original SIGCHLD handler and reap processes as long as
- there seem to be any remaining.
- """
- if self.originalHandler is not None:
- signal.signal(signal.SIGCHLD, self.originalHandler)
- if process is not None:
- begin = time.time()
- while process.reapProcessHandlers:
- log.msg(
- "ReactorBuilder.tearDown reaping some processes %r" % (
- process.reapProcessHandlers,))
- process.reapAllProcesses()
-
- # The process should exit on its own. However, if it
- # doesn't, we're stuck in this loop forever. To avoid
- # hanging the test suite, eventually give the process some
- # help exiting and move on.
- time.sleep(0.001)
- if time.time() - begin > 60:
- for pid in process.reapProcessHandlers:
- os.kill(pid, signal.SIGKILL)
- raise Exception(
- "Timeout waiting for child processes to exit: %r" % (
- process.reapProcessHandlers,))
-
-
- def unbuildReactor(self, reactor):
- """
- Clean up any resources which may have been allocated for the given
- reactor by its creation or by a test which used it.
- """
- # Chris says:
- #
- # XXX These explicit calls to clean up the waker (and any other
- # internal readers) should become obsolete when bug #3063 is
- # fixed. -radix, 2008-02-29. Fortunately it should probably cause an
- # error when bug #3063 is fixed, so it should be removed in the same
- # branch that fixes it.
- #
- # -exarkun
- reactor._uninstallHandler()
- if getattr(reactor, '_internalReaders', None) is not None:
- for reader in reactor._internalReaders:
- reactor.removeReader(reader)
- reader.connectionLost(None)
- reactor._internalReaders.clear()
-
- # Here's an extra thing unrelated to wakers but necessary for
- # cleaning up after the reactors we make. -exarkun
- reactor.disconnectAll()
-
- # It would also be bad if any timed calls left over were allowed to
- # run.
- calls = reactor.getDelayedCalls()
- for c in calls:
- c.cancel()
-
-
- def buildReactor(self):
- """
- Create and return a reactor using C{self.reactorFactory}.
- """
- try:
- from twisted.internet.cfreactor import CFReactor
- from twisted.internet import reactor as globalReactor
- except ImportError:
- pass
- else:
- if (isinstance(globalReactor, CFReactor)
- and self.reactorFactory is CFReactor):
- raise SkipTest(
- "CFReactor uses APIs which manipulate global state, "
- "so it's not safe to run its own reactor-builder tests "
- "under itself")
- try:
- reactor = self.reactorFactory()
- except:
- # Unfortunately, not all errors which result in a reactor
- # being unusable are detectable without actually
- # instantiating the reactor. So we catch some more here
- # and skip the test if necessary. We also log it to aid
- # with debugging, but flush the logged error so the test
- # doesn't fail.
- log.err(None, "Failed to install reactor")
- self.flushLoggedErrors()
- raise SkipTest(Failure().getErrorMessage())
- else:
- if self.requiredInterfaces is not None:
- missing = filter(
- lambda required: not required.providedBy(reactor),
- self.requiredInterfaces)
- if missing:
- self.unbuildReactor(reactor)
- raise SkipTest("%s does not provide %s" % (
- fullyQualifiedName(reactor.__class__),
- ",".join([fullyQualifiedName(x) for x in missing])))
- self.addCleanup(self.unbuildReactor, reactor)
- return reactor
-
-
- def runReactor(self, reactor, timeout=None):
- """
- Run the reactor for at most the given amount of time.
-
- @param reactor: The reactor to run.
-
- @type timeout: C{int} or C{float}
- @param timeout: The maximum amount of time, specified in seconds, to
- allow the reactor to run. If the reactor is still running after
- this much time has elapsed, it will be stopped and an exception
- raised. If C{None}, the default test method timeout imposed by
- Trial will be used. This depends on the L{IReactorTime}
- implementation of C{reactor} for correct operation.
-
- @raise TimeoutError: If the reactor is still running after C{timeout}
- seconds.
- """
- if timeout is None:
- timeout = self.getTimeout()
-
- timedOut = []
- def stop():
- timedOut.append(None)
- reactor.stop()
-
- reactor.callLater(timeout, stop)
- reactor.run()
- if timedOut:
- raise TimeoutError(
- "reactor still running after %s seconds" % (timeout,))
-
-
- def makeTestCaseClasses(cls):
- """
- Create a L{TestCase} subclass which mixes in C{cls} for each known
- reactor and return a dict mapping their names to them.
- """
- classes = {}
- for reactor in cls._reactors:
- shortReactorName = reactor.split(".")[-1]
- name = (cls.__name__ + "." + shortReactorName).replace(".", "_")
- class testcase(cls, TestCase):
- __module__ = cls.__module__
- if reactor in cls.skippedReactors:
- skip = cls.skippedReactors[reactor]
- try:
- reactorFactory = namedAny(reactor)
- except:
- skip = Failure().getErrorMessage()
- testcase.__name__ = name
- classes[testcase.__name__] = testcase
- return classes
- makeTestCaseClasses = classmethod(makeTestCaseClasses)
-
-
-__all__ = ['ReactorBuilder']
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_abstract.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_abstract.py
deleted file mode 100755
index 5e9c0cfc..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_abstract.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.abstract}, a collection of APIs for implementing
-reactors.
-"""
-
-from twisted.trial.unittest import TestCase
-
-from twisted.internet.abstract import isIPv6Address
-
-class IPv6AddressTests(TestCase):
- """
- Tests for L{isIPv6Address}, a function for determining if a particular
- string is an IPv6 address literal.
- """
- def test_empty(self):
- """
- The empty string is not an IPv6 address literal.
- """
- self.assertFalse(isIPv6Address(""))
-
-
- def test_colon(self):
- """
- A single C{":"} is not an IPv6 address literal.
- """
- self.assertFalse(isIPv6Address(":"))
-
-
- def test_loopback(self):
- """
- C{"::1"} is the IPv6 loopback address literal.
- """
- self.assertTrue(isIPv6Address("::1"))
-
-
- def test_scopeID(self):
- """
- An otherwise valid IPv6 address literal may also include a C{"%"}
- followed by an arbitrary scope identifier.
- """
- self.assertTrue(isIPv6Address("fe80::1%eth0"))
- self.assertTrue(isIPv6Address("fe80::2%1"))
- self.assertTrue(isIPv6Address("fe80::3%en2"))
-
-
- def test_invalidWithScopeID(self):
- """
- An otherwise invalid IPv6 address literal is still invalid with a
- trailing scope identifier.
- """
- self.assertFalse(isIPv6Address("%eth0"))
- self.assertFalse(isIPv6Address(":%eth0"))
- self.assertFalse(isIPv6Address("hello%eth0"))
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_address.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_address.py
deleted file mode 100755
index 5007e3a3..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_address.py
+++ /dev/null
@@ -1,292 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-import re
-import os
-
-from twisted.trial import unittest
-from twisted.internet.address import IPv4Address, UNIXAddress
-
-try:
- os.symlink
-except AttributeError:
- symlinkSkip = "Platform does not support symlinks"
-else:
- symlinkSkip = None
-
-
-class AddressTestCaseMixin(object):
- def test_addressComparison(self):
- """
- Two different address instances, sharing the same properties are
- considered equal by C{==} and not considered not equal by C{!=}.
-
- Note: When applied via UNIXAddress class, this uses the same
- filename for both objects being compared.
- """
- self.assertTrue(self.buildAddress() == self.buildAddress())
- self.assertFalse(self.buildAddress() != self.buildAddress())
-
-
- def _stringRepresentation(self, stringFunction):
- """
- Verify that the string representation of an address object conforms to a
- simple pattern (the usual one for Python object reprs) and contains
- values which accurately reflect the attributes of the address.
- """
- addr = self.buildAddress()
- pattern = "".join([
- "^",
- "([^\(]+Address)", # class name,
- "\(", # opening bracket,
- "([^)]+)", # arguments,
- "\)", # closing bracket,
- "$"
- ])
- stringValue = stringFunction(addr)
- m = re.match(pattern, stringValue)
- self.assertNotEquals(
- None, m,
- "%s does not match the standard __str__ pattern "
- "ClassName(arg1, arg2, etc)" % (stringValue,))
- self.assertEqual(addr.__class__.__name__, m.group(1))
-
- args = [x.strip() for x in m.group(2).split(",")]
- self.assertEqual(
- args,
- [argSpec[1] % (getattr(addr, argSpec[0]),) for argSpec in self.addressArgSpec])
-
-
- def test_str(self):
- """
- C{str} can be used to get a string representation of an address instance
- containing information about that address.
- """
- self._stringRepresentation(str)
-
-
- def test_repr(self):
- """
- C{repr} can be used to get a string representation of an address
- instance containing information about that address.
- """
- self._stringRepresentation(repr)
-
-
- def test_hash(self):
- """
- C{__hash__} can be used to get a hash of an address, allowing
- addresses to be used as keys in dictionaries, for instance.
- """
- addr = self.buildAddress()
- d = {addr: True}
- self.assertTrue(d[self.buildAddress()])
-
-
- def test_differentNamesComparison(self):
- """
- Check that comparison operators work correctly on address objects
- when a different name is passed in
- """
- self.assertFalse(self.buildAddress() == self.buildDifferentAddress())
- self.assertFalse(self.buildDifferentAddress() == self.buildAddress())
-
- self.assertTrue(self.buildAddress() != self.buildDifferentAddress())
- self.assertTrue(self.buildDifferentAddress() != self.buildAddress())
-
-
- def assertDeprecations(self, testMethod, message):
- """
- Assert that the a DeprecationWarning with the given message was
- emitted against the given method.
- """
- warnings = self.flushWarnings([testMethod])
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(warnings[0]['message'], message)
- self.assertEqual(len(warnings), 1)
-
-
-
-class IPv4AddressTestCaseMixin(AddressTestCaseMixin):
- addressArgSpec = (("type", "%s"), ("host", "%r"), ("port", "%d"))
-
-
-
-class IPv4AddressTCPTestCase(unittest.TestCase, IPv4AddressTestCaseMixin):
- def buildAddress(self):
- """
- Create an arbitrary new L{IPv4Address} instance with a C{"TCP"}
- type. A new instance is created for each call, but always for the
- same address.
- """
- return IPv4Address("TCP", "127.0.0.1", 0)
-
-
- def buildDifferentAddress(self):
- """
- Like L{buildAddress}, but with a different fixed address.
- """
- return IPv4Address("TCP", "127.0.0.2", 0)
-
-
- def test_bwHackDeprecation(self):
- """
- If a value is passed for the C{_bwHack} parameter to L{IPv4Address},
- a deprecation warning is emitted.
- """
- # Construct this for warning side-effects, disregard the actual object.
- IPv4Address("TCP", "127.0.0.3", 0, _bwHack="TCP")
-
- message = (
- "twisted.internet.address.IPv4Address._bwHack is deprecated "
- "since Twisted 11.0")
- return self.assertDeprecations(self.test_bwHackDeprecation, message)
-
-
-
-class IPv4AddressUDPTestCase(unittest.TestCase, IPv4AddressTestCaseMixin):
- def buildAddress(self):
- """
- Create an arbitrary new L{IPv4Address} instance with a C{"UDP"}
- type. A new instance is created for each call, but always for the
- same address.
- """
- return IPv4Address("UDP", "127.0.0.1", 0)
-
-
- def buildDifferentAddress(self):
- """
- Like L{buildAddress}, but with a different fixed address.
- """
- return IPv4Address("UDP", "127.0.0.2", 0)
-
-
- def test_bwHackDeprecation(self):
- """
- If a value is passed for the C{_bwHack} parameter to L{IPv4Address},
- a deprecation warning is emitted.
- """
- # Construct this for warning side-effects, disregard the actual object.
- IPv4Address("UDP", "127.0.0.3", 0, _bwHack="UDP")
-
- message = (
- "twisted.internet.address.IPv4Address._bwHack is deprecated "
- "since Twisted 11.0")
- return self.assertDeprecations(self.test_bwHackDeprecation, message)
-
-
-
-class UNIXAddressTestCase(unittest.TestCase, AddressTestCaseMixin):
- addressArgSpec = (("name", "%r"),)
-
- def setUp(self):
- self._socketAddress = self.mktemp()
- self._otherAddress = self.mktemp()
-
-
- def buildAddress(self):
- """
- Create an arbitrary new L{UNIXAddress} instance. A new instance is
- created for each call, but always for the same address.
- """
- return UNIXAddress(self._socketAddress)
-
-
- def buildDifferentAddress(self):
- """
- Like L{buildAddress}, but with a different fixed address.
- """
- return UNIXAddress(self._otherAddress)
-
-
- def test_comparisonOfLinkedFiles(self):
- """
- UNIXAddress objects compare as equal if they link to the same file.
- """
- linkName = self.mktemp()
- self.fd = open(self._socketAddress, 'w')
- os.symlink(os.path.abspath(self._socketAddress), linkName)
- self.assertTrue(
- UNIXAddress(self._socketAddress) == UNIXAddress(linkName))
- self.assertTrue(
- UNIXAddress(linkName) == UNIXAddress(self._socketAddress))
- test_comparisonOfLinkedFiles.skip = symlinkSkip
-
-
- def test_hashOfLinkedFiles(self):
- """
- UNIXAddress Objects that compare as equal have the same hash value.
- """
- linkName = self.mktemp()
- self.fd = open(self._socketAddress, 'w')
- os.symlink(os.path.abspath(self._socketAddress), linkName)
- self.assertEqual(
- hash(UNIXAddress(self._socketAddress)), hash(UNIXAddress(linkName)))
- test_hashOfLinkedFiles.skip = symlinkSkip
-
-
- def test_bwHackDeprecation(self):
- """
- If a value is passed for the C{_bwHack} parameter to L{UNIXAddress},
- a deprecation warning is emitted.
- """
- # Construct this for warning side-effects, disregard the actual object.
- UNIXAddress(self.mktemp(), _bwHack='UNIX')
-
- message = (
- "twisted.internet.address.UNIXAddress._bwHack is deprecated "
- "since Twisted 11.0")
- return self.assertDeprecations(self.test_bwHackDeprecation, message)
-
-
-
-class EmptyUNIXAddressTestCase(unittest.TestCase, AddressTestCaseMixin):
- """
- Tests for L{UNIXAddress} operations involving a C{None} address.
- """
- addressArgSpec = (("name", "%r"),)
-
- def setUp(self):
- self._socketAddress = self.mktemp()
-
-
- def buildAddress(self):
- """
- Create an arbitrary new L{UNIXAddress} instance. A new instance is
- created for each call, but always for the same address.
- """
- return UNIXAddress(self._socketAddress)
-
-
- def buildDifferentAddress(self):
- """
- Like L{buildAddress}, but with a fixed address of C{None}.
- """
- return UNIXAddress(None)
-
-
- def test_comparisonOfLinkedFiles(self):
- """
- A UNIXAddress referring to a C{None} address does not compare equal to a
- UNIXAddress referring to a symlink.
- """
- linkName = self.mktemp()
- self.fd = open(self._socketAddress, 'w')
- os.symlink(os.path.abspath(self._socketAddress), linkName)
- self.assertTrue(
- UNIXAddress(self._socketAddress) != UNIXAddress(None))
- self.assertTrue(
- UNIXAddress(None) != UNIXAddress(self._socketAddress))
- test_comparisonOfLinkedFiles.skip = symlinkSkip
-
-
- def test_emptyHash(self):
- """
- C{__hash__} can be used to get a hash of an address, even one referring
- to C{None} rather than a real path.
- """
- addr = self.buildDifferentAddress()
- d = {addr: True}
- self.assertTrue(d[self.buildDifferentAddress()])
-
-
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_base.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_base.py
deleted file mode 100755
index 6cab8fad..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_base.py
+++ /dev/null
@@ -1,272 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.base}.
-"""
-
-import socket
-from Queue import Queue
-
-from zope.interface import implements
-
-from twisted.python.threadpool import ThreadPool
-from twisted.python.util import setIDFunction
-from twisted.internet.interfaces import IReactorTime, IReactorThreads
-from twisted.internet.error import DNSLookupError
-from twisted.internet.base import ThreadedResolver, DelayedCall
-from twisted.internet.task import Clock
-from twisted.trial.unittest import TestCase
-
-
-class FakeReactor(object):
- """
- A fake reactor implementation which just supports enough reactor APIs for
- L{ThreadedResolver}.
- """
- implements(IReactorTime, IReactorThreads)
-
- def __init__(self):
- self._clock = Clock()
- self.callLater = self._clock.callLater
-
- self._threadpool = ThreadPool()
- self._threadpool.start()
- self.getThreadPool = lambda: self._threadpool
-
- self._threadCalls = Queue()
-
-
- def callFromThread(self, f, *args, **kwargs):
- self._threadCalls.put((f, args, kwargs))
-
-
- def _runThreadCalls(self):
- f, args, kwargs = self._threadCalls.get()
- f(*args, **kwargs)
-
-
- def _stop(self):
- self._threadpool.stop()
-
-
-
-class ThreadedResolverTests(TestCase):
- """
- Tests for L{ThreadedResolver}.
- """
- def test_success(self):
- """
- L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires
- with the value returned by the call to L{socket.gethostbyname} in the
- threadpool of the reactor passed to L{ThreadedResolver.__init__}.
- """
- ip = "10.0.0.17"
- name = "foo.bar.example.com"
- timeout = 30
-
- reactor = FakeReactor()
- self.addCleanup(reactor._stop)
-
- lookedUp = []
- resolvedTo = []
- def fakeGetHostByName(name):
- lookedUp.append(name)
- return ip
-
- self.patch(socket, 'gethostbyname', fakeGetHostByName)
-
- resolver = ThreadedResolver(reactor)
- d = resolver.getHostByName(name, (timeout,))
- d.addCallback(resolvedTo.append)
-
- reactor._runThreadCalls()
-
- self.assertEqual(lookedUp, [name])
- self.assertEqual(resolvedTo, [ip])
-
- # Make sure that any timeout-related stuff gets cleaned up.
- reactor._clock.advance(timeout + 1)
- self.assertEqual(reactor._clock.calls, [])
-
-
- def test_failure(self):
- """
- L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
- L{Failure} if the call to L{socket.gethostbyname} raises an exception.
- """
- timeout = 30
-
- reactor = FakeReactor()
- self.addCleanup(reactor._stop)
-
- def fakeGetHostByName(name):
- raise IOError("ENOBUFS (this is a funny joke)")
-
- self.patch(socket, 'gethostbyname', fakeGetHostByName)
-
- failedWith = []
- resolver = ThreadedResolver(reactor)
- d = resolver.getHostByName("some.name", (timeout,))
- self.assertFailure(d, DNSLookupError)
- d.addCallback(failedWith.append)
-
- reactor._runThreadCalls()
-
- self.assertEqual(len(failedWith), 1)
-
- # Make sure that any timeout-related stuff gets cleaned up.
- reactor._clock.advance(timeout + 1)
- self.assertEqual(reactor._clock.calls, [])
-
-
- def test_timeout(self):
- """
- If L{socket.gethostbyname} does not complete before the specified
- timeout elapsed, the L{Deferred} returned by
- L{ThreadedResolver.getHostByBame} fails with L{DNSLookupError}.
- """
- timeout = 10
-
- reactor = FakeReactor()
- self.addCleanup(reactor._stop)
-
- result = Queue()
- def fakeGetHostByName(name):
- raise result.get()
-
- self.patch(socket, 'gethostbyname', fakeGetHostByName)
-
- failedWith = []
- resolver = ThreadedResolver(reactor)
- d = resolver.getHostByName("some.name", (timeout,))
- self.assertFailure(d, DNSLookupError)
- d.addCallback(failedWith.append)
-
- reactor._clock.advance(timeout - 1)
- self.assertEqual(failedWith, [])
- reactor._clock.advance(1)
- self.assertEqual(len(failedWith), 1)
-
- # Eventually the socket.gethostbyname does finish - in this case, with
- # an exception. Nobody cares, though.
- result.put(IOError("The I/O was errorful"))
-
-
-
-class DelayedCallTests(TestCase):
- """
- Tests for L{DelayedCall}.
- """
- def _getDelayedCallAt(self, time):
- """
- Get a L{DelayedCall} instance at a given C{time}.
-
- @param time: The absolute time at which the returned L{DelayedCall}
- will be scheduled.
- """
- def noop(call):
- pass
- return DelayedCall(time, lambda: None, (), {}, noop, noop, None)
-
-
- def setUp(self):
- """
- Create two L{DelayedCall} instanced scheduled to run at different
- times.
- """
- self.zero = self._getDelayedCallAt(0)
- self.one = self._getDelayedCallAt(1)
-
-
- def test_str(self):
- """
- The string representation of a L{DelayedCall} instance, as returned by
- C{str}, includes the unsigned id of the instance, as well as its state,
- the function to be called, and the function arguments.
- """
- def nothing():
- pass
- dc = DelayedCall(12, nothing, (3, ), {"A": 5}, None, None, lambda: 1.5)
- ids = {dc: 200}
- def fakeID(obj):
- try:
- return ids[obj]
- except (TypeError, KeyError):
- return id(obj)
- self.addCleanup(setIDFunction, setIDFunction(fakeID))
- self.assertEqual(
- str(dc),
- "<DelayedCall 0xc8 [10.5s] called=0 cancelled=0 nothing(3, A=5)>")
-
-
- def test_lt(self):
- """
- For two instances of L{DelayedCall} C{a} and C{b}, C{a < b} is true
- if and only if C{a} is scheduled to run before C{b}.
- """
- zero, one = self.zero, self.one
- self.assertTrue(zero < one)
- self.assertFalse(one < zero)
- self.assertFalse(zero < zero)
- self.assertFalse(one < one)
-
-
- def test_le(self):
- """
- For two instances of L{DelayedCall} C{a} and C{b}, C{a <= b} is true
- if and only if C{a} is scheduled to run before C{b} or at the same
- time as C{b}.
- """
- zero, one = self.zero, self.one
- self.assertTrue(zero <= one)
- self.assertFalse(one <= zero)
- self.assertTrue(zero <= zero)
- self.assertTrue(one <= one)
-
-
- def test_gt(self):
- """
- For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
- if and only if C{a} is scheduled to run after C{b}.
- """
- zero, one = self.zero, self.one
- self.assertTrue(one > zero)
- self.assertFalse(zero > one)
- self.assertFalse(zero > zero)
- self.assertFalse(one > one)
-
-
- def test_ge(self):
- """
- For two instances of L{DelayedCall} C{a} and C{b}, C{a > b} is true
- if and only if C{a} is scheduled to run after C{b} or at the same
- time as C{b}.
- """
- zero, one = self.zero, self.one
- self.assertTrue(one >= zero)
- self.assertFalse(zero >= one)
- self.assertTrue(zero >= zero)
- self.assertTrue(one >= one)
-
-
- def test_eq(self):
- """
- A L{DelayedCall} instance is only equal to itself.
- """
- # Explicitly use == here, instead of assertEqual, to be more
- # confident __eq__ is being tested.
- self.assertFalse(self.zero == self.one)
- self.assertTrue(self.zero == self.zero)
- self.assertTrue(self.one == self.one)
-
-
- def test_ne(self):
- """
- A L{DelayedCall} instance is not equal to any other object.
- """
- # Explicitly use != here, instead of assertEqual, to be more
- # confident __ne__ is being tested.
- self.assertTrue(self.zero != self.one)
- self.assertFalse(self.zero != self.zero)
- self.assertFalse(self.one != self.one)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_baseprocess.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_baseprocess.py
deleted file mode 100755
index 750b6604..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_baseprocess.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet._baseprocess} which implements process-related
-functionality that is useful in all platforms supporting L{IReactorProcess}.
-"""
-
-__metaclass__ = type
-
-from twisted.python.deprecate import getWarningMethod, setWarningMethod
-from twisted.trial.unittest import TestCase
-from twisted.internet._baseprocess import BaseProcess
-
-
-class BaseProcessTests(TestCase):
- """
- Tests for L{BaseProcess}, a parent class for other classes which represent
- processes which implements functionality common to many different process
- implementations.
- """
- def test_callProcessExited(self):
- """
- L{BaseProcess._callProcessExited} calls the C{processExited} method of
- its C{proto} attribute and passes it a L{Failure} wrapping the given
- exception.
- """
- class FakeProto:
- reason = None
-
- def processExited(self, reason):
- self.reason = reason
-
- reason = RuntimeError("fake reason")
- process = BaseProcess(FakeProto())
- process._callProcessExited(reason)
- process.proto.reason.trap(RuntimeError)
- self.assertIdentical(reason, process.proto.reason.value)
-
-
- def test_callProcessExitedMissing(self):
- """
- L{BaseProcess._callProcessExited} emits a L{DeprecationWarning} if the
- object referred to by its C{proto} attribute has no C{processExited}
- method.
- """
- class FakeProto:
- pass
-
- reason = object()
- process = BaseProcess(FakeProto())
-
- self.addCleanup(setWarningMethod, getWarningMethod())
- warnings = []
- def collect(message, category, stacklevel):
- warnings.append((message, category, stacklevel))
- setWarningMethod(collect)
-
- process._callProcessExited(reason)
-
- [(message, category, stacklevel)] = warnings
- self.assertEqual(
- message,
- "Since Twisted 8.2, IProcessProtocol.processExited is required. "
- "%s.%s must implement it." % (
- FakeProto.__module__, FakeProto.__name__))
- self.assertIdentical(category, DeprecationWarning)
- # The stacklevel doesn't really make sense for this kind of
- # deprecation. Requiring it to be 0 will at least avoid pointing to
- # any part of Twisted or a random part of the application's code, which
- # I think would be more misleading than having it point inside the
- # warning system itself. -exarkun
- self.assertEqual(stacklevel, 0)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_core.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_core.py
deleted file mode 100755
index 6b2161f6..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_core.py
+++ /dev/null
@@ -1,331 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorCore}.
-"""
-
-__metaclass__ = type
-
-import signal
-import time
-import inspect
-
-from twisted.internet.abstract import FileDescriptor
-from twisted.internet.error import ReactorAlreadyRunning, ReactorNotRestartable
-from twisted.internet.defer import Deferred
-from twisted.internet.test.reactormixins import ReactorBuilder
-
-
-class ObjectModelIntegrationMixin(object):
- """
- Helpers for tests about the object model of reactor-related objects.
- """
- def assertFullyNewStyle(self, instance):
- """
- Assert that the given object is an instance of a new-style class and
- that there are no classic classes in the inheritance hierarchy of
- that class.
-
- This is a beneficial condition because PyPy is better able to
- optimize attribute lookup on such classes.
- """
- self.assertIsInstance(instance, object)
- mro = inspect.getmro(type(instance))
- for subclass in mro:
- self.assertTrue(
- issubclass(subclass, object),
- "%r is not new-style" % (subclass,))
-
-
-
-class ObjectModelIntegrationTest(ReactorBuilder, ObjectModelIntegrationMixin):
- """
- Test details of object model integration against all reactors.
- """
-
- def test_newstyleReactor(self):
- """
- Checks that all reactors on a platform have method resolution order
- containing only new style classes.
- """
- reactor = self.buildReactor()
- self.assertFullyNewStyle(reactor)
-
-
-
-class SystemEventTestsBuilder(ReactorBuilder):
- """
- Builder defining tests relating to L{IReactorCore.addSystemEventTrigger}
- and L{IReactorCore.fireSystemEvent}.
- """
- def test_stopWhenNotStarted(self):
- """
- C{reactor.stop()} raises L{RuntimeError} when called when the reactor
- has not been started.
- """
- reactor = self.buildReactor()
- self.assertRaises(RuntimeError, reactor.stop)
-
-
- def test_stopWhenAlreadyStopped(self):
- """
- C{reactor.stop()} raises L{RuntimeError} when called after the reactor
- has been stopped.
- """
- reactor = self.buildReactor()
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- self.assertRaises(RuntimeError, reactor.stop)
-
-
- def test_callWhenRunningOrder(self):
- """
- Functions are run in the order that they were passed to
- L{reactor.callWhenRunning}.
- """
- reactor = self.buildReactor()
- events = []
- reactor.callWhenRunning(events.append, "first")
- reactor.callWhenRunning(events.append, "second")
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- self.assertEqual(events, ["first", "second"])
-
-
- def test_runningForStartupEvents(self):
- """
- The reactor is not running when C{"before"} C{"startup"} triggers are
- called and is running when C{"during"} and C{"after"} C{"startup"}
- triggers are called.
- """
- reactor = self.buildReactor()
- state = {}
- def beforeStartup():
- state['before'] = reactor.running
- def duringStartup():
- state['during'] = reactor.running
- def afterStartup():
- state['after'] = reactor.running
- reactor.addSystemEventTrigger("before", "startup", beforeStartup)
- reactor.addSystemEventTrigger("during", "startup", duringStartup)
- reactor.addSystemEventTrigger("after", "startup", afterStartup)
- reactor.callWhenRunning(reactor.stop)
- self.assertEqual(state, {})
- self.runReactor(reactor)
- self.assertEqual(
- state,
- {"before": False,
- "during": True,
- "after": True})
-
-
- def test_signalHandlersInstalledDuringStartup(self):
- """
- Signal handlers are installed in responsed to the C{"during"}
- C{"startup"}.
- """
- reactor = self.buildReactor()
- phase = [None]
- def beforeStartup():
- phase[0] = "before"
- def afterStartup():
- phase[0] = "after"
- reactor.addSystemEventTrigger("before", "startup", beforeStartup)
- reactor.addSystemEventTrigger("after", "startup", afterStartup)
-
- sawPhase = []
- def fakeSignal(signum, action):
- sawPhase.append(phase[0])
- self.patch(signal, 'signal', fakeSignal)
- reactor.callWhenRunning(reactor.stop)
- self.assertEqual(phase[0], None)
- self.assertEqual(sawPhase, [])
- self.runReactor(reactor)
- self.assertIn("before", sawPhase)
- self.assertEqual(phase[0], "after")
-
-
- def test_stopShutDownEvents(self):
- """
- C{reactor.stop()} fires all three phases of shutdown event triggers
- before it makes C{reactor.run()} return.
- """
- reactor = self.buildReactor()
- events = []
- reactor.addSystemEventTrigger(
- "before", "shutdown",
- lambda: events.append(("before", "shutdown")))
- reactor.addSystemEventTrigger(
- "during", "shutdown",
- lambda: events.append(("during", "shutdown")))
- reactor.addSystemEventTrigger(
- "after", "shutdown",
- lambda: events.append(("after", "shutdown")))
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- self.assertEqual(events, [("before", "shutdown"),
- ("during", "shutdown"),
- ("after", "shutdown")])
-
-
- def test_shutdownFiresTriggersAsynchronously(self):
- """
- C{"before"} C{"shutdown"} triggers are not run synchronously from
- L{reactor.stop}.
- """
- reactor = self.buildReactor()
- events = []
- reactor.addSystemEventTrigger(
- "before", "shutdown", events.append, "before shutdown")
- def stopIt():
- reactor.stop()
- events.append("stopped")
- reactor.callWhenRunning(stopIt)
- self.assertEqual(events, [])
- self.runReactor(reactor)
- self.assertEqual(events, ["stopped", "before shutdown"])
-
-
- def test_shutdownDisconnectsCleanly(self):
- """
- A L{IFileDescriptor.connectionLost} implementation which raises an
- exception does not prevent the remaining L{IFileDescriptor}s from
- having their C{connectionLost} method called.
- """
- lostOK = [False]
-
- # Subclass FileDescriptor to get logPrefix
- class ProblematicFileDescriptor(FileDescriptor):
- def connectionLost(self, reason):
- raise RuntimeError("simulated connectionLost error")
-
- class OKFileDescriptor(FileDescriptor):
- def connectionLost(self, reason):
- lostOK[0] = True
-
- reactor = self.buildReactor()
-
- # Unfortunately, it is necessary to patch removeAll to directly control
- # the order of the returned values. The test is only valid if
- # ProblematicFileDescriptor comes first. Also, return these
- # descriptors only the first time removeAll is called so that if it is
- # called again the file descriptors aren't re-disconnected.
- fds = iter([ProblematicFileDescriptor(), OKFileDescriptor()])
- reactor.removeAll = lambda: fds
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)
- self.assertTrue(lostOK[0])
-
-
- def test_multipleRun(self):
- """
- C{reactor.run()} raises L{ReactorAlreadyRunning} when called when
- the reactor is already running.
- """
- events = []
- def reentrantRun():
- self.assertRaises(ReactorAlreadyRunning, reactor.run)
- events.append("tested")
- reactor = self.buildReactor()
- reactor.callWhenRunning(reentrantRun)
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- self.assertEqual(events, ["tested"])
-
-
- def test_runWithAsynchronousBeforeStartupTrigger(self):
- """
- When there is a C{'before'} C{'startup'} trigger which returns an
- unfired L{Deferred}, C{reactor.run()} starts the reactor and does not
- return until after C{reactor.stop()} is called
- """
- events = []
- def trigger():
- events.append('trigger')
- d = Deferred()
- d.addCallback(callback)
- reactor.callLater(0, d.callback, None)
- return d
- def callback(ignored):
- events.append('callback')
- reactor.stop()
- reactor = self.buildReactor()
- reactor.addSystemEventTrigger('before', 'startup', trigger)
- self.runReactor(reactor)
- self.assertEqual(events, ['trigger', 'callback'])
-
-
- def test_iterate(self):
- """
- C{reactor.iterate()} does not block.
- """
- reactor = self.buildReactor()
- t = reactor.callLater(5, reactor.crash)
-
- start = time.time()
- reactor.iterate(0) # Shouldn't block
- elapsed = time.time() - start
-
- self.failUnless(elapsed < 2)
- t.cancel()
-
-
- def test_crash(self):
- """
- C{reactor.crash()} stops the reactor and does not fire shutdown
- triggers.
- """
- reactor = self.buildReactor()
- events = []
- reactor.addSystemEventTrigger(
- "before", "shutdown",
- lambda: events.append(("before", "shutdown")))
- reactor.callWhenRunning(reactor.callLater, 0, reactor.crash)
- self.runReactor(reactor)
- self.assertFalse(reactor.running)
- self.assertFalse(
- events,
- "Shutdown triggers invoked but they should not have been.")
-
-
- def test_runAfterCrash(self):
- """
- C{reactor.run()} restarts the reactor after it has been stopped by
- C{reactor.crash()}.
- """
- events = []
- def crash():
- events.append('crash')
- reactor.crash()
- reactor = self.buildReactor()
- reactor.callWhenRunning(crash)
- self.runReactor(reactor)
- def stop():
- events.append(('stop', reactor.running))
- reactor.stop()
- reactor.callWhenRunning(stop)
- self.runReactor(reactor)
- self.assertEqual(events, ['crash', ('stop', True)])
-
-
- def test_runAfterStop(self):
- """
- C{reactor.run()} raises L{ReactorNotRestartable} when called when
- the reactor is being run after getting stopped priorly.
- """
- events = []
- def restart():
- self.assertRaises(ReactorNotRestartable, reactor.run)
- events.append('tested')
- reactor = self.buildReactor()
- reactor.callWhenRunning(reactor.stop)
- reactor.addSystemEventTrigger('after', 'shutdown', restart)
- self.runReactor(reactor)
- self.assertEqual(events, ['tested'])
-
-
-
-globals().update(SystemEventTestsBuilder.makeTestCaseClasses())
-globals().update(ObjectModelIntegrationTest.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_default.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_default.py
deleted file mode 100755
index 635c0f9c..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_default.py
+++ /dev/null
@@ -1,83 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.default}.
-"""
-
-import select
-from twisted.trial.unittest import TestCase
-from twisted.python.runtime import Platform
-from twisted.internet.default import _getInstallFunction
-
-unix = Platform('posix', 'other')
-linux = Platform('posix', 'linux2')
-windows = Platform('nt', 'win32')
-osx = Platform('posix', 'darwin')
-
-
-class PollReactorTests(TestCase):
- """
- Tests for the cases of L{twisted.internet.default._getInstallFunction}
- in which it picks the poll(2) or epoll(7)-based reactors.
- """
-
- def assertIsPoll(self, install):
- """
- Assert the given function will install the poll() reactor, or select()
- if poll() is unavailable.
- """
- if hasattr(select, "poll"):
- self.assertEqual(
- install.__module__, 'twisted.internet.pollreactor')
- else:
- self.assertEqual(
- install.__module__, 'twisted.internet.selectreactor')
-
-
- def test_unix(self):
- """
- L{_getInstallFunction} chooses the poll reactor on arbitrary Unix
- platforms, falling back to select(2) if it is unavailable.
- """
- install = _getInstallFunction(unix)
- self.assertIsPoll(install)
-
-
- def test_linux(self):
- """
- L{_getInstallFunction} chooses the epoll reactor on Linux, or poll if
- epoll is unavailable.
- """
- install = _getInstallFunction(linux)
- try:
- from twisted.internet import epollreactor
- except ImportError:
- self.assertIsPoll(install)
- else:
- self.assertEqual(
- install.__module__, 'twisted.internet.epollreactor')
-
-
-
-class SelectReactorTests(TestCase):
- """
- Tests for the cases of L{twisted.internet.default._getInstallFunction}
- in which it picks the select(2)-based reactor.
- """
- def test_osx(self):
- """
- L{_getInstallFunction} chooses the select reactor on OS X.
- """
- install = _getInstallFunction(osx)
- self.assertEqual(
- install.__module__, 'twisted.internet.selectreactor')
-
-
- def test_windows(self):
- """
- L{_getInstallFunction} chooses the select reactor on Windows.
- """
- install = _getInstallFunction(windows)
- self.assertEqual(
- install.__module__, 'twisted.internet.selectreactor')
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_endpoints.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_endpoints.py
deleted file mode 100755
index 0f4fa682..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_endpoints.py
+++ /dev/null
@@ -1,2021 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-"""
-Test the C{I...Endpoint} implementations that wrap the L{IReactorTCP},
-L{IReactorSSL}, and L{IReactorUNIX} interfaces found in
-L{twisted.internet.endpoints}.
-"""
-from errno import EPERM
-from socket import AF_INET, AF_INET6, SOCK_STREAM, IPPROTO_TCP
-from zope.interface import implements
-from zope.interface.verify import verifyObject
-
-from twisted.trial import unittest
-from twisted.internet import error, interfaces, defer
-from twisted.internet import endpoints
-from twisted.internet.address import IPv4Address, IPv6Address, UNIXAddress
-from twisted.internet.protocol import ClientFactory, Protocol
-from twisted.test.proto_helpers import (
- MemoryReactor, RaisingMemoryReactor, StringTransport)
-from twisted.python.failure import Failure
-from twisted.python.systemd import ListenFDs
-from twisted.plugin import getPlugins
-
-from twisted import plugins
-from twisted.python.modules import getModule
-from twisted.python.filepath import FilePath
-from twisted.protocols import basic
-from twisted.internet import protocol, reactor, stdio
-from twisted.internet.stdio import PipeAddress
-
-
-pemPath = getModule("twisted.test").filePath.sibling("server.pem")
-casPath = getModule(__name__).filePath.sibling("fake_CAs")
-escapedPEMPathName = endpoints.quoteStringArgument(pemPath.path)
-escapedCAsPathName = endpoints.quoteStringArgument(casPath.path)
-
-try:
- from twisted.test.test_sslverify import makeCertificate
- from twisted.internet.ssl import CertificateOptions, Certificate, \
- KeyPair, PrivateCertificate
- from OpenSSL.SSL import ContextType
- testCertificate = Certificate.loadPEM(pemPath.getContent())
- testPrivateCertificate = PrivateCertificate.loadPEM(pemPath.getContent())
-
- skipSSL = False
-except ImportError:
- skipSSL = "OpenSSL is required to construct SSL Endpoints"
-
-
-class TestProtocol(Protocol):
- """
- Protocol whose only function is to callback deferreds on the
- factory when it is connected or disconnected.
- """
-
- def __init__(self):
- self.data = []
- self.connectionsLost = []
- self.connectionMadeCalls = 0
-
-
- def logPrefix(self):
- return "A Test Protocol"
-
-
- def connectionMade(self):
- self.connectionMadeCalls += 1
-
-
- def dataReceived(self, data):
- self.data.append(data)
-
-
- def connectionLost(self, reason):
- self.connectionsLost.append(reason)
-
-
-
-class TestHalfCloseableProtocol(TestProtocol):
- """
- A Protocol that implements L{IHalfCloseableProtocol} and records whether its
- C{readConnectionLost} and {writeConnectionLost} methods are called.
-
- @ivar readLost: A C{bool} indicating whether C{readConnectionLost} has been
- called.
-
- @ivar writeLost: A C{bool} indicating whether C{writeConnectionLost} has
- been called.
- """
- implements(interfaces.IHalfCloseableProtocol)
-
- def __init__(self):
- TestProtocol.__init__(self)
- self.readLost = False
- self.writeLost = False
-
-
- def readConnectionLost(self):
- self.readLost = True
-
-
- def writeConnectionLost(self):
- self.writeLost = True
-
-
-
-class TestFileDescriptorReceiverProtocol(TestProtocol):
- """
- A Protocol that implements L{IFileDescriptorReceiver} and records how its
- C{fileDescriptorReceived} method is called.
-
- @ivar receivedDescriptors: A C{list} containing all of the file descriptors
- passed to C{fileDescriptorReceived} calls made on this instance.
- """
- implements(interfaces.IFileDescriptorReceiver)
-
- def connectionMade(self):
- TestProtocol.connectionMade(self)
- self.receivedDescriptors = []
-
-
- def fileDescriptorReceived(self, descriptor):
- self.receivedDescriptors.append(descriptor)
-
-
-
-class TestFactory(ClientFactory):
- """
- Simple factory to be used both when connecting and listening. It contains
- two deferreds which are called back when my protocol connects and
- disconnects.
- """
-
- protocol = TestProtocol
-
-
-
-class WrappingFactoryTests(unittest.TestCase):
- """
- Test the behaviour of our ugly implementation detail C{_WrappingFactory}.
- """
- def test_doStart(self):
- """
- L{_WrappingFactory.doStart} passes through to the wrapped factory's
- C{doStart} method, allowing application-specific setup and logging.
- """
- factory = ClientFactory()
- wf = endpoints._WrappingFactory(factory)
- wf.doStart()
- self.assertEqual(1, factory.numPorts)
-
-
- def test_doStop(self):
- """
- L{_WrappingFactory.doStop} passes through to the wrapped factory's
- C{doStop} method, allowing application-specific cleanup and logging.
- """
- factory = ClientFactory()
- factory.numPorts = 3
- wf = endpoints._WrappingFactory(factory)
- wf.doStop()
- self.assertEqual(2, factory.numPorts)
-
-
- def test_failedBuildProtocol(self):
- """
- An exception raised in C{buildProtocol} of our wrappedFactory
- results in our C{onConnection} errback being fired.
- """
-
- class BogusFactory(ClientFactory):
- """
- A one off factory whose C{buildProtocol} raises an C{Exception}.
- """
-
- def buildProtocol(self, addr):
- raise ValueError("My protocol is poorly defined.")
-
-
- wf = endpoints._WrappingFactory(BogusFactory())
-
- wf.buildProtocol(None)
-
- d = self.assertFailure(wf._onConnection, ValueError)
- d.addCallback(lambda e: self.assertEqual(
- e.args,
- ("My protocol is poorly defined.",)))
-
- return d
-
-
- def test_logPrefixPassthrough(self):
- """
- If the wrapped protocol provides L{ILoggingContext}, whatever is
- returned from the wrapped C{logPrefix} method is returned from
- L{_WrappingProtocol.logPrefix}.
- """
- wf = endpoints._WrappingFactory(TestFactory())
- wp = wf.buildProtocol(None)
- self.assertEqual(wp.logPrefix(), "A Test Protocol")
-
-
- def test_logPrefixDefault(self):
- """
- If the wrapped protocol does not provide L{ILoggingContext}, the wrapped
- protocol's class name is returned from L{_WrappingProtocol.logPrefix}.
- """
- class NoProtocol(object):
- pass
- factory = TestFactory()
- factory.protocol = NoProtocol
- wf = endpoints._WrappingFactory(factory)
- wp = wf.buildProtocol(None)
- self.assertEqual(wp.logPrefix(), "NoProtocol")
-
-
- def test_wrappedProtocolDataReceived(self):
- """
- The wrapped C{Protocol}'s C{dataReceived} will get called when our
- C{_WrappingProtocol}'s C{dataReceived} gets called.
- """
- wf = endpoints._WrappingFactory(TestFactory())
- p = wf.buildProtocol(None)
- p.makeConnection(None)
-
- p.dataReceived('foo')
- self.assertEqual(p._wrappedProtocol.data, ['foo'])
-
- p.dataReceived('bar')
- self.assertEqual(p._wrappedProtocol.data, ['foo', 'bar'])
-
-
- def test_wrappedProtocolTransport(self):
- """
- Our transport is properly hooked up to the wrappedProtocol when a
- connection is made.
- """
- wf = endpoints._WrappingFactory(TestFactory())
- p = wf.buildProtocol(None)
-
- dummyTransport = object()
-
- p.makeConnection(dummyTransport)
-
- self.assertEqual(p.transport, dummyTransport)
-
- self.assertEqual(p._wrappedProtocol.transport, dummyTransport)
-
-
- def test_wrappedProtocolConnectionLost(self):
- """
- Our wrappedProtocol's connectionLost method is called when
- L{_WrappingProtocol.connectionLost} is called.
- """
- tf = TestFactory()
- wf = endpoints._WrappingFactory(tf)
- p = wf.buildProtocol(None)
-
- p.connectionLost("fail")
-
- self.assertEqual(p._wrappedProtocol.connectionsLost, ["fail"])
-
-
- def test_clientConnectionFailed(self):
- """
- Calls to L{_WrappingFactory.clientConnectionLost} should errback the
- L{_WrappingFactory._onConnection} L{Deferred}
- """
- wf = endpoints._WrappingFactory(TestFactory())
- expectedFailure = Failure(error.ConnectError(string="fail"))
-
- wf.clientConnectionFailed(
- None,
- expectedFailure)
-
- errors = []
- def gotError(f):
- errors.append(f)
-
- wf._onConnection.addErrback(gotError)
-
- self.assertEqual(errors, [expectedFailure])
-
-
- def test_wrappingProtocolFileDescriptorReceiver(self):
- """
- Our L{_WrappingProtocol} should be an L{IFileDescriptorReceiver} if the
- wrapped protocol is.
- """
- connectedDeferred = None
- applicationProtocol = TestFileDescriptorReceiverProtocol()
- wrapper = endpoints._WrappingProtocol(
- connectedDeferred, applicationProtocol)
- self.assertTrue(interfaces.IFileDescriptorReceiver.providedBy(wrapper))
- self.assertTrue(verifyObject(interfaces.IFileDescriptorReceiver, wrapper))
-
-
- def test_wrappingProtocolNotFileDescriptorReceiver(self):
- """
- Our L{_WrappingProtocol} does not provide L{IHalfCloseableProtocol} if
- the wrapped protocol doesn't.
- """
- tp = TestProtocol()
- p = endpoints._WrappingProtocol(None, tp)
- self.assertFalse(interfaces.IFileDescriptorReceiver.providedBy(p))
-
-
- def test_wrappedProtocolFileDescriptorReceived(self):
- """
- L{_WrappingProtocol.fileDescriptorReceived} calls the wrapped protocol's
- C{fileDescriptorReceived} method.
- """
- wrappedProtocol = TestFileDescriptorReceiverProtocol()
- wrapper = endpoints._WrappingProtocol(
- defer.Deferred(), wrappedProtocol)
- wrapper.makeConnection(StringTransport())
- wrapper.fileDescriptorReceived(42)
- self.assertEqual(wrappedProtocol.receivedDescriptors, [42])
-
-
- def test_wrappingProtocolHalfCloseable(self):
- """
- Our L{_WrappingProtocol} should be an L{IHalfCloseableProtocol} if the
- C{wrappedProtocol} is.
- """
- cd = object()
- hcp = TestHalfCloseableProtocol()
- p = endpoints._WrappingProtocol(cd, hcp)
- self.assertEqual(
- interfaces.IHalfCloseableProtocol.providedBy(p), True)
-
-
- def test_wrappingProtocolNotHalfCloseable(self):
- """
- Our L{_WrappingProtocol} should not provide L{IHalfCloseableProtocol}
- if the C{WrappedProtocol} doesn't.
- """
- tp = TestProtocol()
- p = endpoints._WrappingProtocol(None, tp)
- self.assertEqual(
- interfaces.IHalfCloseableProtocol.providedBy(p), False)
-
-
- def test_wrappedProtocolReadConnectionLost(self):
- """
- L{_WrappingProtocol.readConnectionLost} should proxy to the wrapped
- protocol's C{readConnectionLost}
- """
- hcp = TestHalfCloseableProtocol()
- p = endpoints._WrappingProtocol(None, hcp)
- p.readConnectionLost()
- self.assertEqual(hcp.readLost, True)
-
-
- def test_wrappedProtocolWriteConnectionLost(self):
- """
- L{_WrappingProtocol.writeConnectionLost} should proxy to the wrapped
- protocol's C{writeConnectionLost}
- """
- hcp = TestHalfCloseableProtocol()
- p = endpoints._WrappingProtocol(None, hcp)
- p.writeConnectionLost()
- self.assertEqual(hcp.writeLost, True)
-
-
-
-class ClientEndpointTestCaseMixin(object):
- """
- Generic test methods to be mixed into all client endpoint test classes.
- """
- def retrieveConnectedFactory(self, reactor):
- """
- Retrieve a single factory that has connected using the given reactor.
- (This behavior is valid for TCP and SSL but needs to be overridden for
- UNIX.)
-
- @param reactor: a L{MemoryReactor}
- """
- return self.expectedClients(reactor)[0][2]
-
-
- def test_endpointConnectSuccess(self):
- """
- A client endpoint can connect and returns a deferred who gets called
- back with a protocol instance.
- """
- proto = object()
- mreactor = MemoryReactor()
-
- clientFactory = object()
-
- ep, expectedArgs, ignoredDest = self.createClientEndpoint(
- mreactor, clientFactory)
-
- d = ep.connect(clientFactory)
-
- receivedProtos = []
-
- def checkProto(p):
- receivedProtos.append(p)
-
- d.addCallback(checkProto)
-
- factory = self.retrieveConnectedFactory(mreactor)
- factory._onConnection.callback(proto)
- self.assertEqual(receivedProtos, [proto])
-
- expectedClients = self.expectedClients(mreactor)
-
- self.assertEqual(len(expectedClients), 1)
- self.assertConnectArgs(expectedClients[0], expectedArgs)
-
-
- def test_endpointConnectFailure(self):
- """
- If an endpoint tries to connect to a non-listening port it gets
- a C{ConnectError} failure.
- """
- expectedError = error.ConnectError(string="Connection Failed")
-
- mreactor = RaisingMemoryReactor(connectException=expectedError)
-
- clientFactory = object()
-
- ep, ignoredArgs, ignoredDest = self.createClientEndpoint(
- mreactor, clientFactory)
-
- d = ep.connect(clientFactory)
-
- receivedExceptions = []
-
- def checkFailure(f):
- receivedExceptions.append(f.value)
-
- d.addErrback(checkFailure)
-
- self.assertEqual(receivedExceptions, [expectedError])
-
-
- def test_endpointConnectingCancelled(self):
- """
- Calling L{Deferred.cancel} on the L{Deferred} returned from
- L{IStreamClientEndpoint.connect} is errbacked with an expected
- L{ConnectingCancelledError} exception.
- """
- mreactor = MemoryReactor()
-
- clientFactory = object()
-
- ep, ignoredArgs, address = self.createClientEndpoint(
- mreactor, clientFactory)
-
- d = ep.connect(clientFactory)
-
- receivedFailures = []
-
- def checkFailure(f):
- receivedFailures.append(f)
-
- d.addErrback(checkFailure)
-
- d.cancel()
- # When canceled, the connector will immediately notify its factory that
- # the connection attempt has failed due to a UserError.
- attemptFactory = self.retrieveConnectedFactory(mreactor)
- attemptFactory.clientConnectionFailed(None, Failure(error.UserError()))
- # This should be a feature of MemoryReactor: <http://tm.tl/5630>.
-
- self.assertEqual(len(receivedFailures), 1)
-
- failure = receivedFailures[0]
-
- self.assertIsInstance(failure.value, error.ConnectingCancelledError)
- self.assertEqual(failure.value.address, address)
-
-
- def test_endpointConnectNonDefaultArgs(self):
- """
- The endpoint should pass it's connectArgs parameter to the reactor's
- listen methods.
- """
- factory = object()
-
- mreactor = MemoryReactor()
-
- ep, expectedArgs, ignoredHost = self.createClientEndpoint(
- mreactor, factory,
- **self.connectArgs())
-
- ep.connect(factory)
-
- expectedClients = self.expectedClients(mreactor)
-
- self.assertEqual(len(expectedClients), 1)
- self.assertConnectArgs(expectedClients[0], expectedArgs)
-
-
-
-class ServerEndpointTestCaseMixin(object):
- """
- Generic test methods to be mixed into all client endpoint test classes.
- """
- def test_endpointListenSuccess(self):
- """
- An endpoint can listen and returns a deferred that gets called back
- with a port instance.
- """
- mreactor = MemoryReactor()
-
- factory = object()
-
- ep, expectedArgs, expectedHost = self.createServerEndpoint(
- mreactor, factory)
-
- d = ep.listen(factory)
-
- receivedHosts = []
-
- def checkPortAndServer(port):
- receivedHosts.append(port.getHost())
-
- d.addCallback(checkPortAndServer)
-
- self.assertEqual(receivedHosts, [expectedHost])
- self.assertEqual(self.expectedServers(mreactor), [expectedArgs])
-
-
- def test_endpointListenFailure(self):
- """
- When an endpoint tries to listen on an already listening port, a
- C{CannotListenError} failure is errbacked.
- """
- factory = object()
- exception = error.CannotListenError('', 80, factory)
- mreactor = RaisingMemoryReactor(listenException=exception)
-
- ep, ignoredArgs, ignoredDest = self.createServerEndpoint(
- mreactor, factory)
-
- d = ep.listen(object())
-
- receivedExceptions = []
-
- def checkFailure(f):
- receivedExceptions.append(f.value)
-
- d.addErrback(checkFailure)
-
- self.assertEqual(receivedExceptions, [exception])
-
-
- def test_endpointListenNonDefaultArgs(self):
- """
- The endpoint should pass it's listenArgs parameter to the reactor's
- listen methods.
- """
- factory = object()
-
- mreactor = MemoryReactor()
-
- ep, expectedArgs, ignoredHost = self.createServerEndpoint(
- mreactor, factory,
- **self.listenArgs())
-
- ep.listen(factory)
-
- expectedServers = self.expectedServers(mreactor)
-
- self.assertEqual(expectedServers, [expectedArgs])
-
-
-
-class EndpointTestCaseMixin(ServerEndpointTestCaseMixin,
- ClientEndpointTestCaseMixin):
- """
- Generic test methods to be mixed into all endpoint test classes.
- """
-
-
-
-class StdioFactory(protocol.Factory):
- protocol = basic.LineReceiver
-
-
-
-class StandardIOEndpointsTestCase(unittest.TestCase):
- """
- Tests for Standard I/O Endpoints
- """
- def setUp(self):
- self.ep = endpoints.StandardIOEndpoint(reactor)
-
-
- def test_standardIOInstance(self):
- """
- The endpoint creates an L{endpoints.StandardIO} instance.
- """
- self.d = self.ep.listen(StdioFactory())
- def checkInstanceAndLoseConnection(stdioOb):
- self.assertIsInstance(stdioOb, stdio.StandardIO)
- stdioOb.loseConnection()
- self.d.addCallback(checkInstanceAndLoseConnection)
- return self.d
-
-
- def test_reactor(self):
- """
- The reactor passed to the endpoint is set as its _reactor attribute.
- """
- self.assertEqual(self.ep._reactor, reactor)
-
-
- def test_protocol(self):
- """
- The protocol used in the endpoint is a L{basic.LineReceiver} instance.
- """
- self.d = self.ep.listen(StdioFactory())
- def checkProtocol(stdioOb):
- from twisted.python.runtime import platform
- if platform.isWindows():
- self.assertIsInstance(stdioOb.proto, basic.LineReceiver)
- else:
- self.assertIsInstance(stdioOb.protocol, basic.LineReceiver)
- stdioOb.loseConnection()
- self.d.addCallback(checkProtocol)
- return self.d
-
-
- def test_address(self):
- """
- The address passed to the factory's buildProtocol in the endpoint
- should be a PipeAddress instance.
- """
- class TestAddrFactory(protocol.Factory):
- protocol = basic.LineReceiver
- _address = None
- def buildProtocol(self, addr):
- self._address = addr
- p = self.protocol()
- p.factory = self
- return p
- def getAddress(self):
- return self._address
-
- myFactory = TestAddrFactory()
- self.d = self.ep.listen(myFactory)
- def checkAddress(stdioOb):
- self.assertIsInstance(myFactory.getAddress(), PipeAddress)
- stdioOb.loseConnection()
- self.d.addCallback(checkAddress)
- return self.d
-
-
-
-class TCP4EndpointsTestCase(EndpointTestCaseMixin, unittest.TestCase):
- """
- Tests for TCP IPv4 Endpoints.
- """
-
- def expectedServers(self, reactor):
- """
- @return: List of calls to L{IReactorTCP.listenTCP}
- """
- return reactor.tcpServers
-
-
- def expectedClients(self, reactor):
- """
- @return: List of calls to L{IReactorTCP.connectTCP}
- """
- return reactor.tcpClients
-
-
- def assertConnectArgs(self, receivedArgs, expectedArgs):
- """
- Compare host, port, timeout, and bindAddress in C{receivedArgs}
- to C{expectedArgs}. We ignore the factory because we don't
- only care what protocol comes out of the
- C{IStreamClientEndpoint.connect} call.
-
- @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{timeout}, C{bindAddress}) that was passed to
- L{IReactorTCP.connectTCP}.
- @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{timeout}, C{bindAddress}) that we expect to have been passed
- to L{IReactorTCP.connectTCP}.
- """
- (host, port, ignoredFactory, timeout, bindAddress) = receivedArgs
- (expectedHost, expectedPort, _ignoredFactory,
- expectedTimeout, expectedBindAddress) = expectedArgs
-
- self.assertEqual(host, expectedHost)
- self.assertEqual(port, expectedPort)
- self.assertEqual(timeout, expectedTimeout)
- self.assertEqual(bindAddress, expectedBindAddress)
-
-
- def connectArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to connect.
- """
- return {'timeout': 10, 'bindAddress': ('localhost', 49595)}
-
-
- def listenArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to listen
- """
- return {'backlog': 100, 'interface': '127.0.0.1'}
-
-
- def createServerEndpoint(self, reactor, factory, **listenArgs):
- """
- Create an L{TCP4ServerEndpoint} and return the values needed to verify
- its behaviour.
-
- @param reactor: A fake L{IReactorTCP} that L{TCP4ServerEndpoint} can
- call L{IReactorTCP.listenTCP} on.
- @param factory: The thing that we expect to be passed to our
- L{IStreamServerEndpoint.listen} implementation.
- @param listenArgs: Optional dictionary of arguments to
- L{IReactorTCP.listenTCP}.
- """
- address = IPv4Address("TCP", "0.0.0.0", 0)
-
- if listenArgs is None:
- listenArgs = {}
-
- return (endpoints.TCP4ServerEndpoint(reactor,
- address.port,
- **listenArgs),
- (address.port, factory,
- listenArgs.get('backlog', 50),
- listenArgs.get('interface', '')),
- address)
-
-
- def createClientEndpoint(self, reactor, clientFactory, **connectArgs):
- """
- Create an L{TCP4ClientEndpoint} and return the values needed to verify
- its behavior.
-
- @param reactor: A fake L{IReactorTCP} that L{TCP4ClientEndpoint} can
- call L{IReactorTCP.connectTCP} on.
- @param clientFactory: The thing that we expect to be passed to our
- L{IStreamClientEndpoint.connect} implementation.
- @param connectArgs: Optional dictionary of arguments to
- L{IReactorTCP.connectTCP}
- """
- address = IPv4Address("TCP", "localhost", 80)
-
- return (endpoints.TCP4ClientEndpoint(reactor,
- address.host,
- address.port,
- **connectArgs),
- (address.host, address.port, clientFactory,
- connectArgs.get('timeout', 30),
- connectArgs.get('bindAddress', None)),
- address)
-
-
-
-class TCP6EndpointsTestCase(EndpointTestCaseMixin, unittest.TestCase):
- """
- Tests for TCP IPv6 Endpoints.
- """
-
- def expectedServers(self, reactor):
- """
- @return: List of calls to L{IReactorTCP.listenTCP}
- """
- return reactor.tcpServers
-
-
- def expectedClients(self, reactor):
- """
- @return: List of calls to L{IReactorTCP.connectTCP}
- """
- return reactor.tcpClients
-
-
- def assertConnectArgs(self, receivedArgs, expectedArgs):
- """
- Compare host, port, timeout, and bindAddress in C{receivedArgs}
- to C{expectedArgs}. We ignore the factory because we don't
- only care what protocol comes out of the
- C{IStreamClientEndpoint.connect} call.
-
- @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{timeout}, C{bindAddress}) that was passed to
- L{IReactorTCP.connectTCP}.
- @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{timeout}, C{bindAddress}) that we expect to have been passed
- to L{IReactorTCP.connectTCP}.
- """
- (host, port, ignoredFactory, timeout, bindAddress) = receivedArgs
- (expectedHost, expectedPort, _ignoredFactory,
- expectedTimeout, expectedBindAddress) = expectedArgs
-
- self.assertEqual(host, expectedHost)
- self.assertEqual(port, expectedPort)
- self.assertEqual(timeout, expectedTimeout)
- self.assertEqual(bindAddress, expectedBindAddress)
-
-
- def connectArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to connect.
- """
- return {'timeout': 10, 'bindAddress': ('localhost', 49595)}
-
-
- def listenArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to listen
- """
- return {'backlog': 100, 'interface': '::1'}
-
-
- def createServerEndpoint(self, reactor, factory, **listenArgs):
- """
- Create a L{TCP6ServerEndpoint} and return the values needed to verify
- its behaviour.
-
- @param reactor: A fake L{IReactorTCP} that L{TCP6ServerEndpoint} can
- call L{IReactorTCP.listenTCP} on.
- @param factory: The thing that we expect to be passed to our
- L{IStreamServerEndpoint.listen} implementation.
- @param listenArgs: Optional dictionary of arguments to
- L{IReactorTCP.listenTCP}.
- """
- interface = listenArgs.get('interface', '::')
- address = IPv6Address("TCP", interface, 0)
-
- if listenArgs is None:
- listenArgs = {}
-
- return (endpoints.TCP6ServerEndpoint(reactor,
- address.port,
- **listenArgs),
- (address.port, factory,
- listenArgs.get('backlog', 50),
- interface),
- address)
-
-
- def createClientEndpoint(self, reactor, clientFactory, **connectArgs):
- """
- Create a L{TCP6ClientEndpoint} and return the values needed to verify
- its behavior.
-
- @param reactor: A fake L{IReactorTCP} that L{TCP6ClientEndpoint} can
- call L{IReactorTCP.connectTCP} on.
- @param clientFactory: The thing that we expect to be passed to our
- L{IStreamClientEndpoint.connect} implementation.
- @param connectArgs: Optional dictionary of arguments to
- L{IReactorTCP.connectTCP}
- """
- address = IPv6Address("TCP", "::1", 80)
-
- return (endpoints.TCP6ClientEndpoint(reactor,
- address.host,
- address.port,
- **connectArgs),
- (address.host, address.port, clientFactory,
- connectArgs.get('timeout', 30),
- connectArgs.get('bindAddress', None)),
- address)
-
-
-class TCP6EndpointNameResolutionTestCase(ClientEndpointTestCaseMixin,
- unittest.TestCase):
- """
- Tests for a TCP IPv6 Client Endpoint pointed at a hostname instead
- of an IPv6 address literal.
- """
-
-
- def createClientEndpoint(self, reactor, clientFactory, **connectArgs):
- """
- Create a L{TCP6ClientEndpoint} and return the values needed to verify
- its behavior.
-
- @param reactor: A fake L{IReactorTCP} that L{TCP6ClientEndpoint} can
- call L{IReactorTCP.connectTCP} on.
- @param clientFactory: The thing that we expect to be passed to our
- L{IStreamClientEndpoint.connect} implementation.
- @param connectArgs: Optional dictionary of arguments to
- L{IReactorTCP.connectTCP}
- """
- address = IPv6Address("TCP", "::2", 80)
- self.ep = endpoints.TCP6ClientEndpoint(reactor,
- 'ipv6.example.com',
- address.port,
- **connectArgs)
-
- def testNameResolution(host):
- self.assertEqual("ipv6.example.com", host)
- data = [(AF_INET6, SOCK_STREAM, IPPROTO_TCP, '', ('::2', 0, 0, 0)),
- (AF_INET6, SOCK_STREAM, IPPROTO_TCP, '', ('::3', 0, 0, 0)),
- (AF_INET6, SOCK_STREAM, IPPROTO_TCP, '', ('::4', 0, 0, 0))]
- return defer.succeed(data)
-
- self.ep._nameResolution = testNameResolution
-
- return (self.ep,
- (address.host, address.port, clientFactory,
- connectArgs.get('timeout', 30),
- connectArgs.get('bindAddress', None)),
- address)
-
-
- def connectArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to connect.
- """
- return {'timeout': 10, 'bindAddress': ('localhost', 49595)}
-
-
- def expectedClients(self, reactor):
- """
- @return: List of calls to L{IReactorTCP.connectTCP}
- """
- return reactor.tcpClients
-
-
- def assertConnectArgs(self, receivedArgs, expectedArgs):
- """
- Compare host, port, timeout, and bindAddress in C{receivedArgs}
- to C{expectedArgs}. We ignore the factory because we don't
- only care what protocol comes out of the
- C{IStreamClientEndpoint.connect} call.
-
- @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{timeout}, C{bindAddress}) that was passed to
- L{IReactorTCP.connectTCP}.
- @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{timeout}, C{bindAddress}) that we expect to have been passed
- to L{IReactorTCP.connectTCP}.
- """
- (host, port, ignoredFactory, timeout, bindAddress) = receivedArgs
- (expectedHost, expectedPort, _ignoredFactory,
- expectedTimeout, expectedBindAddress) = expectedArgs
-
- self.assertEqual(host, expectedHost)
- self.assertEqual(port, expectedPort)
- self.assertEqual(timeout, expectedTimeout)
- self.assertEqual(bindAddress, expectedBindAddress)
-
-
- def test_nameResolution(self):
- """
- While resolving host names, _nameResolution calls
- _deferToThread with _getaddrinfo.
- """
- calls = []
-
- def fakeDeferToThread(f, *args, **kwargs):
- calls.append((f, args, kwargs))
- return defer.Deferred()
-
- endpoint = endpoints.TCP6ClientEndpoint(reactor, 'ipv6.example.com',
- 1234)
- fakegetaddrinfo = object()
- endpoint._getaddrinfo = fakegetaddrinfo
- endpoint._deferToThread = fakeDeferToThread
- endpoint.connect(TestFactory())
- self.assertEqual(
- [(fakegetaddrinfo, ("ipv6.example.com", 0, AF_INET6), {})], calls)
-
-
-
-class SSL4EndpointsTestCase(EndpointTestCaseMixin,
- unittest.TestCase):
- """
- Tests for SSL Endpoints.
- """
- if skipSSL:
- skip = skipSSL
-
- def expectedServers(self, reactor):
- """
- @return: List of calls to L{IReactorSSL.listenSSL}
- """
- return reactor.sslServers
-
-
- def expectedClients(self, reactor):
- """
- @return: List of calls to L{IReactorSSL.connectSSL}
- """
- return reactor.sslClients
-
-
- def assertConnectArgs(self, receivedArgs, expectedArgs):
- """
- Compare host, port, contextFactory, timeout, and bindAddress in
- C{receivedArgs} to C{expectedArgs}. We ignore the factory because we
- don't only care what protocol comes out of the
- C{IStreamClientEndpoint.connect} call.
-
- @param receivedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{contextFactory}, C{timeout}, C{bindAddress}) that was passed to
- L{IReactorSSL.connectSSL}.
- @param expectedArgs: C{tuple} of (C{host}, C{port}, C{factory},
- C{contextFactory}, C{timeout}, C{bindAddress}) that we expect to
- have been passed to L{IReactorSSL.connectSSL}.
- """
- (host, port, ignoredFactory, contextFactory, timeout,
- bindAddress) = receivedArgs
-
- (expectedHost, expectedPort, _ignoredFactory, expectedContextFactory,
- expectedTimeout, expectedBindAddress) = expectedArgs
-
- self.assertEqual(host, expectedHost)
- self.assertEqual(port, expectedPort)
- self.assertEqual(contextFactory, expectedContextFactory)
- self.assertEqual(timeout, expectedTimeout)
- self.assertEqual(bindAddress, expectedBindAddress)
-
-
- def connectArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to connect.
- """
- return {'timeout': 10, 'bindAddress': ('localhost', 49595)}
-
-
- def listenArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to listen
- """
- return {'backlog': 100, 'interface': '127.0.0.1'}
-
-
- def setUp(self):
- """
- Set up client and server SSL contexts for use later.
- """
- self.sKey, self.sCert = makeCertificate(
- O="Server Test Certificate",
- CN="server")
- self.cKey, self.cCert = makeCertificate(
- O="Client Test Certificate",
- CN="client")
- self.serverSSLContext = CertificateOptions(
- privateKey=self.sKey,
- certificate=self.sCert,
- requireCertificate=False)
- self.clientSSLContext = CertificateOptions(
- requireCertificate=False)
-
-
- def createServerEndpoint(self, reactor, factory, **listenArgs):
- """
- Create an L{SSL4ServerEndpoint} and return the tools to verify its
- behaviour.
-
- @param factory: The thing that we expect to be passed to our
- L{IStreamServerEndpoint.listen} implementation.
- @param reactor: A fake L{IReactorSSL} that L{SSL4ServerEndpoint} can
- call L{IReactorSSL.listenSSL} on.
- @param listenArgs: Optional dictionary of arguments to
- L{IReactorSSL.listenSSL}.
- """
- address = IPv4Address("TCP", "0.0.0.0", 0)
-
- return (endpoints.SSL4ServerEndpoint(reactor,
- address.port,
- self.serverSSLContext,
- **listenArgs),
- (address.port, factory, self.serverSSLContext,
- listenArgs.get('backlog', 50),
- listenArgs.get('interface', '')),
- address)
-
-
- def createClientEndpoint(self, reactor, clientFactory, **connectArgs):
- """
- Create an L{SSL4ClientEndpoint} and return the values needed to verify
- its behaviour.
-
- @param reactor: A fake L{IReactorSSL} that L{SSL4ClientEndpoint} can
- call L{IReactorSSL.connectSSL} on.
- @param clientFactory: The thing that we expect to be passed to our
- L{IStreamClientEndpoint.connect} implementation.
- @param connectArgs: Optional dictionary of arguments to
- L{IReactorSSL.connectSSL}
- """
- address = IPv4Address("TCP", "localhost", 80)
-
- if connectArgs is None:
- connectArgs = {}
-
- return (endpoints.SSL4ClientEndpoint(reactor,
- address.host,
- address.port,
- self.clientSSLContext,
- **connectArgs),
- (address.host, address.port, clientFactory,
- self.clientSSLContext,
- connectArgs.get('timeout', 30),
- connectArgs.get('bindAddress', None)),
- address)
-
-
-
-class UNIXEndpointsTestCase(EndpointTestCaseMixin,
- unittest.TestCase):
- """
- Tests for UnixSocket Endpoints.
- """
-
- def retrieveConnectedFactory(self, reactor):
- """
- Override L{EndpointTestCaseMixin.retrieveConnectedFactory} to account
- for different index of 'factory' in C{connectUNIX} args.
- """
- return self.expectedClients(reactor)[0][1]
-
- def expectedServers(self, reactor):
- """
- @return: List of calls to L{IReactorUNIX.listenUNIX}
- """
- return reactor.unixServers
-
-
- def expectedClients(self, reactor):
- """
- @return: List of calls to L{IReactorUNIX.connectUNIX}
- """
- return reactor.unixClients
-
-
- def assertConnectArgs(self, receivedArgs, expectedArgs):
- """
- Compare path, timeout, checkPID in C{receivedArgs} to C{expectedArgs}.
- We ignore the factory because we don't only care what protocol comes
- out of the C{IStreamClientEndpoint.connect} call.
-
- @param receivedArgs: C{tuple} of (C{path}, C{timeout}, C{checkPID})
- that was passed to L{IReactorUNIX.connectUNIX}.
- @param expectedArgs: C{tuple} of (C{path}, C{timeout}, C{checkPID})
- that we expect to have been passed to L{IReactorUNIX.connectUNIX}.
- """
-
- (path, ignoredFactory, timeout, checkPID) = receivedArgs
-
- (expectedPath, _ignoredFactory, expectedTimeout,
- expectedCheckPID) = expectedArgs
-
- self.assertEqual(path, expectedPath)
- self.assertEqual(timeout, expectedTimeout)
- self.assertEqual(checkPID, expectedCheckPID)
-
-
- def connectArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to connect.
- """
- return {'timeout': 10, 'checkPID': 1}
-
-
- def listenArgs(self):
- """
- @return: C{dict} of keyword arguments to pass to listen
- """
- return {'backlog': 100, 'mode': 0600, 'wantPID': 1}
-
-
- def createServerEndpoint(self, reactor, factory, **listenArgs):
- """
- Create an L{UNIXServerEndpoint} and return the tools to verify its
- behaviour.
-
- @param reactor: A fake L{IReactorUNIX} that L{UNIXServerEndpoint} can
- call L{IReactorUNIX.listenUNIX} on.
- @param factory: The thing that we expect to be passed to our
- L{IStreamServerEndpoint.listen} implementation.
- @param listenArgs: Optional dictionary of arguments to
- L{IReactorUNIX.listenUNIX}.
- """
- address = UNIXAddress(self.mktemp())
-
- return (endpoints.UNIXServerEndpoint(reactor, address.name,
- **listenArgs),
- (address.name, factory,
- listenArgs.get('backlog', 50),
- listenArgs.get('mode', 0666),
- listenArgs.get('wantPID', 0)),
- address)
-
-
- def createClientEndpoint(self, reactor, clientFactory, **connectArgs):
- """
- Create an L{UNIXClientEndpoint} and return the values needed to verify
- its behaviour.
-
- @param reactor: A fake L{IReactorUNIX} that L{UNIXClientEndpoint} can
- call L{IReactorUNIX.connectUNIX} on.
- @param clientFactory: The thing that we expect to be passed to our
- L{IStreamClientEndpoint.connect} implementation.
- @param connectArgs: Optional dictionary of arguments to
- L{IReactorUNIX.connectUNIX}
- """
- address = UNIXAddress(self.mktemp())
-
- return (endpoints.UNIXClientEndpoint(reactor, address.name,
- **connectArgs),
- (address.name, clientFactory,
- connectArgs.get('timeout', 30),
- connectArgs.get('checkPID', 0)),
- address)
-
-
-
-class ParserTestCase(unittest.TestCase):
- """
- Tests for L{endpoints._parseServer}, the low-level parsing logic.
- """
-
- f = "Factory"
-
- def parse(self, *a, **kw):
- """
- Provide a hook for test_strports to substitute the deprecated API.
- """
- return endpoints._parseServer(*a, **kw)
-
-
- def test_simpleTCP(self):
- """
- Simple strings with a 'tcp:' prefix should be parsed as TCP.
- """
- self.assertEqual(self.parse('tcp:80', self.f),
- ('TCP', (80, self.f), {'interface':'', 'backlog':50}))
-
-
- def test_interfaceTCP(self):
- """
- TCP port descriptions parse their 'interface' argument as a string.
- """
- self.assertEqual(
- self.parse('tcp:80:interface=127.0.0.1', self.f),
- ('TCP', (80, self.f), {'interface':'127.0.0.1', 'backlog':50}))
-
-
- def test_backlogTCP(self):
- """
- TCP port descriptions parse their 'backlog' argument as an integer.
- """
- self.assertEqual(self.parse('tcp:80:backlog=6', self.f),
- ('TCP', (80, self.f),
- {'interface':'', 'backlog':6}))
-
-
- def test_simpleUNIX(self):
- """
- L{endpoints._parseServer} returns a C{'UNIX'} port description with
- defaults for C{'mode'}, C{'backlog'}, and C{'wantPID'} when passed a
- string with the C{'unix:'} prefix and no other parameter values.
- """
- self.assertEqual(
- self.parse('unix:/var/run/finger', self.f),
- ('UNIX', ('/var/run/finger', self.f),
- {'mode': 0666, 'backlog': 50, 'wantPID': True}))
-
-
- def test_modeUNIX(self):
- """
- C{mode} can be set by including C{"mode=<some integer>"}.
- """
- self.assertEqual(
- self.parse('unix:/var/run/finger:mode=0660', self.f),
- ('UNIX', ('/var/run/finger', self.f),
- {'mode': 0660, 'backlog': 50, 'wantPID': True}))
-
-
- def test_wantPIDUNIX(self):
- """
- C{wantPID} can be set to false by included C{"lockfile=0"}.
- """
- self.assertEqual(
- self.parse('unix:/var/run/finger:lockfile=0', self.f),
- ('UNIX', ('/var/run/finger', self.f),
- {'mode': 0666, 'backlog': 50, 'wantPID': False}))
-
-
- def test_escape(self):
- """
- Backslash can be used to escape colons and backslashes in port
- descriptions.
- """
- self.assertEqual(
- self.parse(r'unix:foo\:bar\=baz\:qux\\', self.f),
- ('UNIX', ('foo:bar=baz:qux\\', self.f),
- {'mode': 0666, 'backlog': 50, 'wantPID': True}))
-
-
- def test_quoteStringArgument(self):
- """
- L{endpoints.quoteStringArgument} should quote backslashes and colons
- for interpolation into L{endpoints.serverFromString} and
- L{endpoints.clientFactory} arguments.
- """
- self.assertEqual(endpoints.quoteStringArgument("some : stuff \\"),
- "some \\: stuff \\\\")
-
-
- def test_impliedEscape(self):
- """
- In strports descriptions, '=' in a parameter value does not need to be
- quoted; it will simply be parsed as part of the value.
- """
- self.assertEqual(
- self.parse(r'unix:address=foo=bar', self.f),
- ('UNIX', ('foo=bar', self.f),
- {'mode': 0666, 'backlog': 50, 'wantPID': True}))
-
-
- def test_nonstandardDefault(self):
- """
- For compatibility with the old L{twisted.application.strports.parse},
- the third 'mode' argument may be specified to L{endpoints.parse} to
- indicate a default other than TCP.
- """
- self.assertEqual(
- self.parse('filename', self.f, 'unix'),
- ('UNIX', ('filename', self.f),
- {'mode': 0666, 'backlog': 50, 'wantPID': True}))
-
-
- def test_unknownType(self):
- """
- L{strports.parse} raises C{ValueError} when given an unknown endpoint
- type.
- """
- self.assertRaises(ValueError, self.parse, "bogus-type:nothing", self.f)
-
-
-
-class ServerStringTests(unittest.TestCase):
- """
- Tests for L{twisted.internet.endpoints.serverFromString}.
- """
-
- def test_tcp(self):
- """
- When passed a TCP strports description, L{endpoints.serverFromString}
- returns a L{TCP4ServerEndpoint} instance initialized with the values
- from the string.
- """
- reactor = object()
- server = endpoints.serverFromString(
- reactor, "tcp:1234:backlog=12:interface=10.0.0.1")
- self.assertIsInstance(server, endpoints.TCP4ServerEndpoint)
- self.assertIdentical(server._reactor, reactor)
- self.assertEqual(server._port, 1234)
- self.assertEqual(server._backlog, 12)
- self.assertEqual(server._interface, "10.0.0.1")
-
-
- def test_ssl(self):
- """
- When passed an SSL strports description, L{endpoints.serverFromString}
- returns a L{SSL4ServerEndpoint} instance initialized with the values
- from the string.
- """
- reactor = object()
- server = endpoints.serverFromString(
- reactor,
- "ssl:1234:backlog=12:privateKey=%s:"
- "certKey=%s:interface=10.0.0.1" % (escapedPEMPathName,
- escapedPEMPathName))
- self.assertIsInstance(server, endpoints.SSL4ServerEndpoint)
- self.assertIdentical(server._reactor, reactor)
- self.assertEqual(server._port, 1234)
- self.assertEqual(server._backlog, 12)
- self.assertEqual(server._interface, "10.0.0.1")
- ctx = server._sslContextFactory.getContext()
- self.assertIsInstance(ctx, ContextType)
-
- if skipSSL:
- test_ssl.skip = skipSSL
-
-
- def test_unix(self):
- """
- When passed a UNIX strports description, L{endpoint.serverFromString}
- returns a L{UNIXServerEndpoint} instance initialized with the values
- from the string.
- """
- reactor = object()
- endpoint = endpoints.serverFromString(
- reactor,
- "unix:/var/foo/bar:backlog=7:mode=0123:lockfile=1")
- self.assertIsInstance(endpoint, endpoints.UNIXServerEndpoint)
- self.assertIdentical(endpoint._reactor, reactor)
- self.assertEqual(endpoint._address, "/var/foo/bar")
- self.assertEqual(endpoint._backlog, 7)
- self.assertEqual(endpoint._mode, 0123)
- self.assertEqual(endpoint._wantPID, True)
-
-
- def test_implicitDefaultNotAllowed(self):
- """
- The older service-based API (L{twisted.internet.strports.service})
- allowed an implicit default of 'tcp' so that TCP ports could be
- specified as a simple integer, but we've since decided that's a bad
- idea, and the new API does not accept an implicit default argument; you
- have to say 'tcp:' now. If you try passing an old implicit port number
- to the new API, you'll get a C{ValueError}.
- """
- value = self.assertRaises(
- ValueError, endpoints.serverFromString, None, "4321")
- self.assertEqual(
- str(value),
- "Unqualified strport description passed to 'service'."
- "Use qualified endpoint descriptions; for example, 'tcp:4321'.")
-
-
- def test_unknownType(self):
- """
- L{endpoints.serverFromString} raises C{ValueError} when given an
- unknown endpoint type.
- """
- value = self.assertRaises(
- # faster-than-light communication not supported
- ValueError, endpoints.serverFromString, None,
- "ftl:andromeda/carcosa/hali/2387")
- self.assertEqual(
- str(value),
- "Unknown endpoint type: 'ftl'")
-
-
- def test_typeFromPlugin(self):
- """
- L{endpoints.serverFromString} looks up plugins of type
- L{IStreamServerEndpoint} and constructs endpoints from them.
- """
- # Set up a plugin which will only be accessible for the duration of
- # this test.
- addFakePlugin(self)
- # Plugin is set up: now actually test.
- notAReactor = object()
- fakeEndpoint = endpoints.serverFromString(
- notAReactor, "fake:hello:world:yes=no:up=down")
- from twisted.plugins.fakeendpoint import fake
- self.assertIdentical(fakeEndpoint.parser, fake)
- self.assertEqual(fakeEndpoint.args, (notAReactor, 'hello', 'world'))
- self.assertEqual(fakeEndpoint.kwargs, dict(yes='no', up='down'))
-
-
-
-def addFakePlugin(testCase, dropinSource="fakeendpoint.py"):
- """
- For the duration of C{testCase}, add a fake plugin to twisted.plugins which
- contains some sample endpoint parsers.
- """
- import sys
- savedModules = sys.modules.copy()
- savedPluginPath = plugins.__path__
- def cleanup():
- sys.modules.clear()
- sys.modules.update(savedModules)
- plugins.__path__[:] = savedPluginPath
- testCase.addCleanup(cleanup)
- fp = FilePath(testCase.mktemp())
- fp.createDirectory()
- getModule(__name__).filePath.sibling(dropinSource).copyTo(
- fp.child(dropinSource))
- plugins.__path__.append(fp.path)
-
-
-
-class ClientStringTests(unittest.TestCase):
- """
- Tests for L{twisted.internet.endpoints.clientFromString}.
- """
-
- def test_tcp(self):
- """
- When passed a TCP strports description, L{endpoints.clientFromString}
- returns a L{TCP4ClientEndpoint} instance initialized with the values
- from the string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "tcp:host=example.com:port=1234:timeout=7:bindAddress=10.0.0.2")
- self.assertIsInstance(client, endpoints.TCP4ClientEndpoint)
- self.assertIdentical(client._reactor, reactor)
- self.assertEqual(client._host, "example.com")
- self.assertEqual(client._port, 1234)
- self.assertEqual(client._timeout, 7)
- self.assertEqual(client._bindAddress, "10.0.0.2")
-
-
- def test_tcpPositionalArgs(self):
- """
- When passed a TCP strports description using positional arguments,
- L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint} instance
- initialized with the values from the string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "tcp:example.com:1234:timeout=7:bindAddress=10.0.0.2")
- self.assertIsInstance(client, endpoints.TCP4ClientEndpoint)
- self.assertIdentical(client._reactor, reactor)
- self.assertEqual(client._host, "example.com")
- self.assertEqual(client._port, 1234)
- self.assertEqual(client._timeout, 7)
- self.assertEqual(client._bindAddress, "10.0.0.2")
-
-
- def test_tcpHostPositionalArg(self):
- """
- When passed a TCP strports description specifying host as a positional
- argument, L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint}
- instance initialized with the values from the string.
- """
- reactor = object()
-
- client = endpoints.clientFromString(
- reactor,
- "tcp:example.com:port=1234:timeout=7:bindAddress=10.0.0.2")
- self.assertEqual(client._host, "example.com")
- self.assertEqual(client._port, 1234)
-
-
- def test_tcpPortPositionalArg(self):
- """
- When passed a TCP strports description specifying port as a positional
- argument, L{endpoints.clientFromString} returns a L{TCP4ClientEndpoint}
- instance initialized with the values from the string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "tcp:host=example.com:1234:timeout=7:bindAddress=10.0.0.2")
- self.assertEqual(client._host, "example.com")
- self.assertEqual(client._port, 1234)
-
-
- def test_tcpDefaults(self):
- """
- A TCP strports description may omit I{timeout} or I{bindAddress} to
- allow the default to be used.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "tcp:host=example.com:port=1234")
- self.assertEqual(client._timeout, 30)
- self.assertEqual(client._bindAddress, None)
-
-
- def test_unix(self):
- """
- When passed a UNIX strports description, L{endpoints.clientFromString}
- returns a L{UNIXClientEndpoint} instance initialized with the values
- from the string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "unix:path=/var/foo/bar:lockfile=1:timeout=9")
- self.assertIsInstance(client, endpoints.UNIXClientEndpoint)
- self.assertIdentical(client._reactor, reactor)
- self.assertEqual(client._path, "/var/foo/bar")
- self.assertEqual(client._timeout, 9)
- self.assertEqual(client._checkPID, True)
-
-
- def test_unixDefaults(self):
- """
- A UNIX strports description may omit I{lockfile} or I{timeout} to allow
- the defaults to be used.
- """
- client = endpoints.clientFromString(object(), "unix:path=/var/foo/bar")
- self.assertEqual(client._timeout, 30)
- self.assertEqual(client._checkPID, False)
-
-
- def test_unixPathPositionalArg(self):
- """
- When passed a UNIX strports description specifying path as a positional
- argument, L{endpoints.clientFromString} returns a L{UNIXClientEndpoint}
- instance initialized with the values from the string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "unix:/var/foo/bar:lockfile=1:timeout=9")
- self.assertIsInstance(client, endpoints.UNIXClientEndpoint)
- self.assertIdentical(client._reactor, reactor)
- self.assertEqual(client._path, "/var/foo/bar")
- self.assertEqual(client._timeout, 9)
- self.assertEqual(client._checkPID, True)
-
-
- def test_typeFromPlugin(self):
- """
- L{endpoints.clientFromString} looks up plugins of type
- L{IStreamClientEndpoint} and constructs endpoints from them.
- """
- addFakePlugin(self)
- notAReactor = object()
- clientEndpoint = endpoints.clientFromString(
- notAReactor, "cfake:alpha:beta:cee=dee:num=1")
- from twisted.plugins.fakeendpoint import fakeClient
- self.assertIdentical(clientEndpoint.parser, fakeClient)
- self.assertEqual(clientEndpoint.args, ('alpha', 'beta'))
- self.assertEqual(clientEndpoint.kwargs, dict(cee='dee', num='1'))
-
-
- def test_unknownType(self):
- """
- L{endpoints.serverFromString} raises C{ValueError} when given an
- unknown endpoint type.
- """
- value = self.assertRaises(
- # faster-than-light communication not supported
- ValueError, endpoints.clientFromString, None,
- "ftl:andromeda/carcosa/hali/2387")
- self.assertEqual(
- str(value),
- "Unknown endpoint type: 'ftl'")
-
-
-
-class SSLClientStringTests(unittest.TestCase):
- """
- Tests for L{twisted.internet.endpoints.clientFromString} which require SSL.
- """
-
- if skipSSL:
- skip = skipSSL
-
- def test_ssl(self):
- """
- When passed an SSL strports description, L{clientFromString} returns a
- L{SSL4ClientEndpoint} instance initialized with the values from the
- string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "ssl:host=example.net:port=4321:privateKey=%s:"
- "certKey=%s:bindAddress=10.0.0.3:timeout=3:caCertsDir=%s" %
- (escapedPEMPathName,
- escapedPEMPathName,
- escapedCAsPathName))
- self.assertIsInstance(client, endpoints.SSL4ClientEndpoint)
- self.assertIdentical(client._reactor, reactor)
- self.assertEqual(client._host, "example.net")
- self.assertEqual(client._port, 4321)
- self.assertEqual(client._timeout, 3)
- self.assertEqual(client._bindAddress, "10.0.0.3")
- certOptions = client._sslContextFactory
- self.assertIsInstance(certOptions, CertificateOptions)
- ctx = certOptions.getContext()
- self.assertIsInstance(ctx, ContextType)
- self.assertEqual(Certificate(certOptions.certificate),
- testCertificate)
- privateCert = PrivateCertificate(certOptions.certificate)
- privateCert._setPrivateKey(KeyPair(certOptions.privateKey))
- self.assertEqual(privateCert, testPrivateCertificate)
- expectedCerts = [
- Certificate.loadPEM(x.getContent()) for x in
- [casPath.child("thing1.pem"), casPath.child("thing2.pem")]
- if x.basename().lower().endswith('.pem')
- ]
- self.assertEqual(sorted((Certificate(x) for x in certOptions.caCerts),
- key=lambda cert: cert.digest()),
- sorted(expectedCerts,
- key=lambda cert: cert.digest()))
-
-
- def test_sslPositionalArgs(self):
- """
- When passed an SSL strports description, L{clientFromString} returns a
- L{SSL4ClientEndpoint} instance initialized with the values from the
- string.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor,
- "ssl:example.net:4321:privateKey=%s:"
- "certKey=%s:bindAddress=10.0.0.3:timeout=3:caCertsDir=%s" %
- (escapedPEMPathName,
- escapedPEMPathName,
- escapedCAsPathName))
- self.assertIsInstance(client, endpoints.SSL4ClientEndpoint)
- self.assertIdentical(client._reactor, reactor)
- self.assertEqual(client._host, "example.net")
- self.assertEqual(client._port, 4321)
- self.assertEqual(client._timeout, 3)
- self.assertEqual(client._bindAddress, "10.0.0.3")
-
-
- def test_unreadableCertificate(self):
- """
- If a certificate in the directory is unreadable,
- L{endpoints._loadCAsFromDir} will ignore that certificate.
- """
- class UnreadableFilePath(FilePath):
- def getContent(self):
- data = FilePath.getContent(self)
- # There is a duplicate of thing2.pem, so ignore anything that
- # looks like it.
- if data == casPath.child("thing2.pem").getContent():
- raise IOError(EPERM)
- else:
- return data
- casPathClone = casPath.child("ignored").parent()
- casPathClone.clonePath = UnreadableFilePath
- self.assertEqual(
- [Certificate(x) for x in endpoints._loadCAsFromDir(casPathClone)],
- [Certificate.loadPEM(casPath.child("thing1.pem").getContent())])
-
-
- def test_sslSimple(self):
- """
- When passed an SSL strports description without any extra parameters,
- L{clientFromString} returns a simple non-verifying endpoint that will
- speak SSL.
- """
- reactor = object()
- client = endpoints.clientFromString(
- reactor, "ssl:host=simple.example.org:port=4321")
- certOptions = client._sslContextFactory
- self.assertIsInstance(certOptions, CertificateOptions)
- self.assertEqual(certOptions.verify, False)
- ctx = certOptions.getContext()
- self.assertIsInstance(ctx, ContextType)
-
-
-
-class AdoptedStreamServerEndpointTestCase(ServerEndpointTestCaseMixin,
- unittest.TestCase):
- """
- Tests for adopted socket-based stream server endpoints.
- """
- def _createStubbedAdoptedEndpoint(self, reactor, fileno, addressFamily):
- """
- Create an L{AdoptedStreamServerEndpoint} which may safely be used with
- an invalid file descriptor. This is convenient for a number of unit
- tests.
- """
- e = endpoints.AdoptedStreamServerEndpoint(reactor, fileno, addressFamily)
- # Stub out some syscalls which would fail, given our invalid file
- # descriptor.
- e._close = lambda fd: None
- e._setNonBlocking = lambda fd: None
- return e
-
-
- def createServerEndpoint(self, reactor, factory):
- """
- Create a new L{AdoptedStreamServerEndpoint} for use by a test.
-
- @return: A three-tuple:
- - The endpoint
- - A tuple of the arguments expected to be passed to the underlying
- reactor method
- - An IAddress object which will match the result of
- L{IListeningPort.getHost} on the port returned by the endpoint.
- """
- fileno = 12
- addressFamily = AF_INET
- endpoint = self._createStubbedAdoptedEndpoint(
- reactor, fileno, addressFamily)
- # Magic numbers come from the implementation of MemoryReactor
- address = IPv4Address("TCP", "0.0.0.0", 1234)
- return (endpoint, (fileno, addressFamily, factory), address)
-
-
- def expectedServers(self, reactor):
- """
- @return: The ports which were actually adopted by C{reactor} via calls
- to its L{IReactorSocket.adoptStreamPort} implementation.
- """
- return reactor.adoptedPorts
-
-
- def listenArgs(self):
- """
- @return: A C{dict} of additional keyword arguments to pass to the
- C{createServerEndpoint}.
- """
- return {}
-
-
- def test_singleUse(self):
- """
- L{AdoptedStreamServerEndpoint.listen} can only be used once. The file
- descriptor given is closed after the first use, and subsequent calls to
- C{listen} return a L{Deferred} that fails with L{AlreadyListened}.
- """
- reactor = MemoryReactor()
- endpoint = self._createStubbedAdoptedEndpoint(reactor, 13, AF_INET)
- endpoint.listen(object())
- d = self.assertFailure(endpoint.listen(object()), error.AlreadyListened)
- def listenFailed(ignored):
- self.assertEqual(1, len(reactor.adoptedPorts))
- d.addCallback(listenFailed)
- return d
-
-
- def test_descriptionNonBlocking(self):
- """
- L{AdoptedStreamServerEndpoint.listen} sets the file description given to
- it to non-blocking.
- """
- reactor = MemoryReactor()
- endpoint = self._createStubbedAdoptedEndpoint(reactor, 13, AF_INET)
- events = []
- def setNonBlocking(fileno):
- events.append(("setNonBlocking", fileno))
- endpoint._setNonBlocking = setNonBlocking
-
- d = endpoint.listen(object())
- def listened(ignored):
- self.assertEqual([("setNonBlocking", 13)], events)
- d.addCallback(listened)
- return d
-
-
- def test_descriptorClosed(self):
- """
- L{AdoptedStreamServerEndpoint.listen} closes its file descriptor after
- adding it to the reactor with L{IReactorSocket.adoptStreamPort}.
- """
- reactor = MemoryReactor()
- endpoint = self._createStubbedAdoptedEndpoint(reactor, 13, AF_INET)
- events = []
- def close(fileno):
- events.append(("close", fileno, len(reactor.adoptedPorts)))
- endpoint._close = close
-
- d = endpoint.listen(object())
- def listened(ignored):
- self.assertEqual([("close", 13, 1)], events)
- d.addCallback(listened)
- return d
-
-
-
-class SystemdEndpointPluginTests(unittest.TestCase):
- """
- Unit tests for the systemd stream server endpoint and endpoint string
- description parser.
-
- @see: U{systemd<http://www.freedesktop.org/wiki/Software/systemd>}
- """
-
- _parserClass = endpoints._SystemdParser
-
- def test_pluginDiscovery(self):
- """
- L{endpoints._SystemdParser} is found as a plugin for
- L{interfaces.IStreamServerEndpointStringParser} interface.
- """
- parsers = list(getPlugins(
- interfaces.IStreamServerEndpointStringParser))
- for p in parsers:
- if isinstance(p, self._parserClass):
- break
- else:
- self.fail("Did not find systemd parser in %r" % (parsers,))
-
-
- def test_interface(self):
- """
- L{endpoints._SystemdParser} instances provide
- L{interfaces.IStreamServerEndpointStringParser}.
- """
- parser = self._parserClass()
- self.assertTrue(verifyObject(
- interfaces.IStreamServerEndpointStringParser, parser))
-
-
- def _parseStreamServerTest(self, addressFamily, addressFamilyString):
- """
- Helper for unit tests for L{endpoints._SystemdParser.parseStreamServer}
- for different address families.
-
- Handling of the address family given will be verify. If there is a
- problem a test-failing exception will be raised.
-
- @param addressFamily: An address family constant, like L{socket.AF_INET}.
-
- @param addressFamilyString: A string which should be recognized by the
- parser as representing C{addressFamily}.
- """
- reactor = object()
- descriptors = [5, 6, 7, 8, 9]
- index = 3
-
- parser = self._parserClass()
- parser._sddaemon = ListenFDs(descriptors)
-
- server = parser.parseStreamServer(
- reactor, domain=addressFamilyString, index=str(index))
- self.assertIdentical(server.reactor, reactor)
- self.assertEqual(server.addressFamily, addressFamily)
- self.assertEqual(server.fileno, descriptors[index])
-
-
- def test_parseStreamServerINET(self):
- """
- IPv4 can be specified using the string C{"INET"}.
- """
- self._parseStreamServerTest(AF_INET, "INET")
-
-
- def test_parseStreamServerINET6(self):
- """
- IPv6 can be specified using the string C{"INET6"}.
- """
- self._parseStreamServerTest(AF_INET6, "INET6")
-
-
- def test_parseStreamServerUNIX(self):
- """
- A UNIX domain socket can be specified using the string C{"UNIX"}.
- """
- try:
- from socket import AF_UNIX
- except ImportError:
- raise unittest.SkipTest("Platform lacks AF_UNIX support")
- else:
- self._parseStreamServerTest(AF_UNIX, "UNIX")
-
-
-
-class TCP6ServerEndpointPluginTests(unittest.TestCase):
- """
- Unit tests for the TCP IPv6 stream server endpoint string description parser.
- """
- _parserClass = endpoints._TCP6ServerParser
-
- def test_pluginDiscovery(self):
- """
- L{endpoints._TCP6ServerParser} is found as a plugin for
- L{interfaces.IStreamServerEndpointStringParser} interface.
- """
- parsers = list(getPlugins(
- interfaces.IStreamServerEndpointStringParser))
- for p in parsers:
- if isinstance(p, self._parserClass):
- break
- else:
- self.fail("Did not find TCP6ServerEndpoint parser in %r" % (parsers,))
-
-
- def test_interface(self):
- """
- L{endpoints._TCP6ServerParser} instances provide
- L{interfaces.IStreamServerEndpointStringParser}.
- """
- parser = self._parserClass()
- self.assertTrue(verifyObject(
- interfaces.IStreamServerEndpointStringParser, parser))
-
-
- def test_stringDescription(self):
- """
- L{serverFromString} returns a L{TCP6ServerEndpoint} instance with a 'tcp6'
- endpoint string description.
- """
- ep = endpoints.serverFromString(MemoryReactor(),
- "tcp6:8080:backlog=12:interface=\:\:1")
- self.assertIsInstance(ep, endpoints.TCP6ServerEndpoint)
- self.assertIsInstance(ep._reactor, MemoryReactor)
- self.assertEqual(ep._port, 8080)
- self.assertEqual(ep._backlog, 12)
- self.assertEqual(ep._interface, '::1')
-
-
-
-class StandardIOEndpointPluginTests(unittest.TestCase):
- """
- Unit tests for the Standard I/O endpoint string description parser.
- """
- _parserClass = endpoints._StandardIOParser
-
- def test_pluginDiscovery(self):
- """
- L{endpoints._StandardIOParser} is found as a plugin for
- L{interfaces.IStreamServerEndpointStringParser} interface.
- """
- parsers = list(getPlugins(
- interfaces.IStreamServerEndpointStringParser))
- for p in parsers:
- if isinstance(p, self._parserClass):
- break
- else:
- self.fail("Did not find StandardIOEndpoint parser in %r" % (parsers,))
-
-
- def test_interface(self):
- """
- L{endpoints._StandardIOParser} instances provide
- L{interfaces.IStreamServerEndpointStringParser}.
- """
- parser = self._parserClass()
- self.assertTrue(verifyObject(
- interfaces.IStreamServerEndpointStringParser, parser))
-
-
- def test_stringDescription(self):
- """
- L{serverFromString} returns a L{StandardIOEndpoint} instance with a 'stdio'
- endpoint string description.
- """
- ep = endpoints.serverFromString(MemoryReactor(), "stdio:")
- self.assertIsInstance(ep, endpoints.StandardIOEndpoint)
- self.assertIsInstance(ep._reactor, MemoryReactor)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_epollreactor.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_epollreactor.py
deleted file mode 100755
index b8363ee8..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_epollreactor.py
+++ /dev/null
@@ -1,246 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.epollreactor}.
-"""
-
-from twisted.trial.unittest import TestCase
-try:
- from twisted.internet.epollreactor import _ContinuousPolling
-except ImportError:
- _ContinuousPolling = None
-from twisted.internet.task import Clock
-from twisted.internet.error import ConnectionDone
-
-
-
-class Descriptor(object):
- """
- Records reads and writes, as if it were a C{FileDescriptor}.
- """
-
- def __init__(self):
- self.events = []
-
-
- def fileno(self):
- return 1
-
-
- def doRead(self):
- self.events.append("read")
-
-
- def doWrite(self):
- self.events.append("write")
-
-
- def connectionLost(self, reason):
- reason.trap(ConnectionDone)
- self.events.append("lost")
-
-
-
-class ContinuousPollingTests(TestCase):
- """
- L{_ContinuousPolling} can be used to read and write from C{FileDescriptor}
- objects.
- """
-
- def test_addReader(self):
- """
- Adding a reader when there was previously no reader starts up a
- C{LoopingCall}.
- """
- poller = _ContinuousPolling(Clock())
- self.assertEqual(poller._loop, None)
- reader = object()
- self.assertFalse(poller.isReading(reader))
- poller.addReader(reader)
- self.assertNotEqual(poller._loop, None)
- self.assertTrue(poller._loop.running)
- self.assertIdentical(poller._loop.clock, poller._reactor)
- self.assertTrue(poller.isReading(reader))
-
-
- def test_addWriter(self):
- """
- Adding a writer when there was previously no writer starts up a
- C{LoopingCall}.
- """
- poller = _ContinuousPolling(Clock())
- self.assertEqual(poller._loop, None)
- writer = object()
- self.assertFalse(poller.isWriting(writer))
- poller.addWriter(writer)
- self.assertNotEqual(poller._loop, None)
- self.assertTrue(poller._loop.running)
- self.assertIdentical(poller._loop.clock, poller._reactor)
- self.assertTrue(poller.isWriting(writer))
-
-
- def test_removeReader(self):
- """
- Removing a reader stops the C{LoopingCall}.
- """
- poller = _ContinuousPolling(Clock())
- reader = object()
- poller.addReader(reader)
- poller.removeReader(reader)
- self.assertEqual(poller._loop, None)
- self.assertEqual(poller._reactor.getDelayedCalls(), [])
- self.assertFalse(poller.isReading(reader))
-
-
- def test_removeWriter(self):
- """
- Removing a writer stops the C{LoopingCall}.
- """
- poller = _ContinuousPolling(Clock())
- writer = object()
- poller.addWriter(writer)
- poller.removeWriter(writer)
- self.assertEqual(poller._loop, None)
- self.assertEqual(poller._reactor.getDelayedCalls(), [])
- self.assertFalse(poller.isWriting(writer))
-
-
- def test_removeUnknown(self):
- """
- Removing unknown readers and writers silently does nothing.
- """
- poller = _ContinuousPolling(Clock())
- poller.removeWriter(object())
- poller.removeReader(object())
-
-
- def test_multipleReadersAndWriters(self):
- """
- Adding multiple readers and writers results in a single
- C{LoopingCall}.
- """
- poller = _ContinuousPolling(Clock())
- writer = object()
- poller.addWriter(writer)
- self.assertNotEqual(poller._loop, None)
- poller.addWriter(object())
- self.assertNotEqual(poller._loop, None)
- poller.addReader(object())
- self.assertNotEqual(poller._loop, None)
- poller.addReader(object())
- poller.removeWriter(writer)
- self.assertNotEqual(poller._loop, None)
- self.assertTrue(poller._loop.running)
- self.assertEqual(len(poller._reactor.getDelayedCalls()), 1)
-
-
- def test_readerPolling(self):
- """
- Adding a reader causes its C{doRead} to be called every 1
- milliseconds.
- """
- reactor = Clock()
- poller = _ContinuousPolling(reactor)
- desc = Descriptor()
- poller.addReader(desc)
- self.assertEqual(desc.events, [])
- reactor.advance(0.00001)
- self.assertEqual(desc.events, ["read"])
- reactor.advance(0.00001)
- self.assertEqual(desc.events, ["read", "read"])
- reactor.advance(0.00001)
- self.assertEqual(desc.events, ["read", "read", "read"])
-
-
- def test_writerPolling(self):
- """
- Adding a writer causes its C{doWrite} to be called every 1
- milliseconds.
- """
- reactor = Clock()
- poller = _ContinuousPolling(reactor)
- desc = Descriptor()
- poller.addWriter(desc)
- self.assertEqual(desc.events, [])
- reactor.advance(0.001)
- self.assertEqual(desc.events, ["write"])
- reactor.advance(0.001)
- self.assertEqual(desc.events, ["write", "write"])
- reactor.advance(0.001)
- self.assertEqual(desc.events, ["write", "write", "write"])
-
-
- def test_connectionLostOnRead(self):
- """
- If a C{doRead} returns a value indicating disconnection,
- C{connectionLost} is called on it.
- """
- reactor = Clock()
- poller = _ContinuousPolling(reactor)
- desc = Descriptor()
- desc.doRead = lambda: ConnectionDone()
- poller.addReader(desc)
- self.assertEqual(desc.events, [])
- reactor.advance(0.001)
- self.assertEqual(desc.events, ["lost"])
-
-
- def test_connectionLostOnWrite(self):
- """
- If a C{doWrite} returns a value indicating disconnection,
- C{connectionLost} is called on it.
- """
- reactor = Clock()
- poller = _ContinuousPolling(reactor)
- desc = Descriptor()
- desc.doWrite = lambda: ConnectionDone()
- poller.addWriter(desc)
- self.assertEqual(desc.events, [])
- reactor.advance(0.001)
- self.assertEqual(desc.events, ["lost"])
-
-
- def test_removeAll(self):
- """
- L{_ContinuousPolling.removeAll} removes all descriptors and returns
- the readers and writers.
- """
- poller = _ContinuousPolling(Clock())
- reader = object()
- writer = object()
- both = object()
- poller.addReader(reader)
- poller.addReader(both)
- poller.addWriter(writer)
- poller.addWriter(both)
- removed = poller.removeAll()
- self.assertEqual(poller.getReaders(), [])
- self.assertEqual(poller.getWriters(), [])
- self.assertEqual(len(removed), 3)
- self.assertEqual(set(removed), set([reader, writer, both]))
-
-
- def test_getReaders(self):
- """
- L{_ContinuousPolling.getReaders} returns a list of the read
- descriptors.
- """
- poller = _ContinuousPolling(Clock())
- reader = object()
- poller.addReader(reader)
- self.assertIn(reader, poller.getReaders())
-
-
- def test_getWriters(self):
- """
- L{_ContinuousPolling.getWriters} returns a list of the write
- descriptors.
- """
- poller = _ContinuousPolling(Clock())
- writer = object()
- poller.addWriter(writer)
- self.assertIn(writer, poller.getWriters())
-
- if _ContinuousPolling is None:
- skip = "epoll not supported in this environment."
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_fdset.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_fdset.py
deleted file mode 100755
index f05ca08f..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_fdset.py
+++ /dev/null
@@ -1,394 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorFDSet}.
-"""
-
-__metaclass__ = type
-
-import os, socket, traceback
-
-from zope.interface import implements
-
-from twisted.python.runtime import platform
-from twisted.trial.unittest import SkipTest
-from twisted.internet.interfaces import IReactorFDSet, IReadDescriptor
-from twisted.internet.abstract import FileDescriptor
-from twisted.internet.test.reactormixins import ReactorBuilder
-
-# twisted.internet.tcp nicely defines some names with proper values on
-# several different platforms.
-from twisted.internet.tcp import EINPROGRESS, EWOULDBLOCK
-
-
-def socketpair():
- serverSocket = socket.socket()
- serverSocket.bind(('127.0.0.1', 0))
- serverSocket.listen(1)
- try:
- client = socket.socket()
- try:
- client.setblocking(False)
- try:
- client.connect(('127.0.0.1', serverSocket.getsockname()[1]))
- except socket.error, e:
- if e.args[0] not in (EINPROGRESS, EWOULDBLOCK):
- raise
- server, addr = serverSocket.accept()
- except:
- client.close()
- raise
- finally:
- serverSocket.close()
-
- return client, server
-
-
-class ReactorFDSetTestsBuilder(ReactorBuilder):
- """
- Builder defining tests relating to L{IReactorFDSet}.
- """
- requiredInterfaces = [IReactorFDSet]
-
- def _connectedPair(self):
- """
- Return the two sockets which make up a new TCP connection.
- """
- client, server = socketpair()
- self.addCleanup(client.close)
- self.addCleanup(server.close)
- return client, server
-
-
- def _simpleSetup(self):
- reactor = self.buildReactor()
-
- client, server = self._connectedPair()
-
- fd = FileDescriptor(reactor)
- fd.fileno = client.fileno
-
- return reactor, fd, server
-
-
- def test_addReader(self):
- """
- C{reactor.addReader()} accepts an L{IReadDescriptor} provider and calls
- its C{doRead} method when there may be data available on its C{fileno}.
- """
- reactor, fd, server = self._simpleSetup()
-
- def removeAndStop():
- reactor.removeReader(fd)
- reactor.stop()
- fd.doRead = removeAndStop
- reactor.addReader(fd)
- server.sendall('x')
-
- # The reactor will only stop if it calls fd.doRead.
- self.runReactor(reactor)
- # Nothing to assert, just be glad we got this far.
-
-
- def test_removeReader(self):
- """
- L{reactor.removeReader()} accepts an L{IReadDescriptor} provider
- previously passed to C{reactor.addReader()} and causes it to no longer
- be monitored for input events.
- """
- reactor, fd, server = self._simpleSetup()
-
- def fail():
- self.fail("doRead should not be called")
- fd.doRead = fail
-
- reactor.addReader(fd)
- reactor.removeReader(fd)
- server.sendall('x')
-
- # Give the reactor two timed event passes to notice that there's I/O
- # (if it is incorrectly watching for I/O).
- reactor.callLater(0, reactor.callLater, 0, reactor.stop)
-
- self.runReactor(reactor)
- # Getting here means the right thing happened probably.
-
-
- def test_addWriter(self):
- """
- C{reactor.addWriter()} accepts an L{IWriteDescriptor} provider and
- calls its C{doWrite} method when it may be possible to write to its
- C{fileno}.
- """
- reactor, fd, server = self._simpleSetup()
-
- def removeAndStop():
- reactor.removeWriter(fd)
- reactor.stop()
- fd.doWrite = removeAndStop
- reactor.addWriter(fd)
-
- self.runReactor(reactor)
- # Getting here is great.
-
-
- def _getFDTest(self, kind):
- """
- Helper for getReaders and getWriters tests.
- """
- reactor = self.buildReactor()
- get = getattr(reactor, 'get' + kind + 's')
- add = getattr(reactor, 'add' + kind)
- remove = getattr(reactor, 'remove' + kind)
-
- client, server = self._connectedPair()
-
- self.assertNotIn(client, get())
- self.assertNotIn(server, get())
-
- add(client)
- self.assertIn(client, get())
- self.assertNotIn(server, get())
-
- remove(client)
- self.assertNotIn(client, get())
- self.assertNotIn(server, get())
-
-
- def test_getReaders(self):
- """
- L{IReactorFDSet.getReaders} reflects the additions and removals made
- with L{IReactorFDSet.addReader} and L{IReactorFDSet.removeReader}.
- """
- self._getFDTest('Reader')
-
-
- def test_removeWriter(self):
- """
- L{reactor.removeWriter()} accepts an L{IWriteDescriptor} provider
- previously passed to C{reactor.addWriter()} and causes it to no longer
- be monitored for outputability.
- """
- reactor, fd, server = self._simpleSetup()
-
- def fail():
- self.fail("doWrite should not be called")
- fd.doWrite = fail
-
- reactor.addWriter(fd)
- reactor.removeWriter(fd)
-
- # Give the reactor two timed event passes to notice that there's I/O
- # (if it is incorrectly watching for I/O).
- reactor.callLater(0, reactor.callLater, 0, reactor.stop)
-
- self.runReactor(reactor)
- # Getting here means the right thing happened probably.
-
-
- def test_getWriters(self):
- """
- L{IReactorFDSet.getWriters} reflects the additions and removals made
- with L{IReactorFDSet.addWriter} and L{IReactorFDSet.removeWriter}.
- """
- self._getFDTest('Writer')
-
-
- def test_removeAll(self):
- """
- C{reactor.removeAll()} removes all registered L{IReadDescriptor}
- providers and all registered L{IWriteDescriptor} providers and returns
- them.
- """
- reactor = self.buildReactor()
-
- reactor, fd, server = self._simpleSetup()
-
- fd.doRead = lambda: self.fail("doRead should not be called")
- fd.doWrite = lambda: self.fail("doWrite should not be called")
-
- server.sendall('x')
-
- reactor.addReader(fd)
- reactor.addWriter(fd)
-
- removed = reactor.removeAll()
-
- # Give the reactor two timed event passes to notice that there's I/O
- # (if it is incorrectly watching for I/O).
- reactor.callLater(0, reactor.callLater, 0, reactor.stop)
-
- self.runReactor(reactor)
- # Getting here means the right thing happened probably.
-
- self.assertEqual(removed, [fd])
-
-
- def test_removedFromReactor(self):
- """
- A descriptor's C{fileno} method should not be called after the
- descriptor has been removed from the reactor.
- """
- reactor = self.buildReactor()
- descriptor = RemovingDescriptor(reactor)
- reactor.callWhenRunning(descriptor.start)
- self.runReactor(reactor)
- self.assertEqual(descriptor.calls, [])
-
-
- def test_negativeOneFileDescriptor(self):
- """
- If L{FileDescriptor.fileno} returns C{-1}, the descriptor is removed
- from the reactor.
- """
- reactor = self.buildReactor()
-
- client, server = self._connectedPair()
-
- class DisappearingDescriptor(FileDescriptor):
- _fileno = server.fileno()
-
- _received = ""
-
- def fileno(self):
- return self._fileno
-
- def doRead(self):
- self._fileno = -1
- self._received += server.recv(1)
- client.send('y')
-
- def connectionLost(self, reason):
- reactor.stop()
-
- descriptor = DisappearingDescriptor(reactor)
- reactor.addReader(descriptor)
- client.send('x')
- self.runReactor(reactor)
- self.assertEqual(descriptor._received, "x")
-
-
- def test_lostFileDescriptor(self):
- """
- The file descriptor underlying a FileDescriptor may be closed and
- replaced by another at some point. Bytes which arrive on the new
- descriptor must not be delivered to the FileDescriptor which was
- originally registered with the original descriptor of the same number.
-
- Practically speaking, this is difficult or impossible to detect. The
- implementation relies on C{fileno} raising an exception if the original
- descriptor has gone away. If C{fileno} continues to return the original
- file descriptor value, the reactor may deliver events from that
- descriptor. This is a best effort attempt to ease certain debugging
- situations. Applications should not rely on it intentionally.
- """
- reactor = self.buildReactor()
-
- name = reactor.__class__.__name__
- if name in ('EPollReactor', 'KQueueReactor', 'CFReactor'):
- # Closing a file descriptor immediately removes it from the epoll
- # set without generating a notification. That means epollreactor
- # will not call any methods on Victim after the close, so there's
- # no chance to notice the socket is no longer valid.
- raise SkipTest("%r cannot detect lost file descriptors" % (name,))
-
- client, server = self._connectedPair()
-
- class Victim(FileDescriptor):
- """
- This L{FileDescriptor} will have its socket closed out from under it
- and another socket will take its place. It will raise a
- socket.error from C{fileno} after this happens (because socket
- objects remember whether they have been closed), so as long as the
- reactor calls the C{fileno} method the problem will be detected.
- """
- def fileno(self):
- return server.fileno()
-
- def doRead(self):
- raise Exception("Victim.doRead should never be called")
-
- def connectionLost(self, reason):
- """
- When the problem is detected, the reactor should disconnect this
- file descriptor. When that happens, stop the reactor so the
- test ends.
- """
- reactor.stop()
-
- reactor.addReader(Victim())
-
- # Arrange for the socket to be replaced at some unspecified time.
- # Significantly, this will not be while any I/O processing code is on
- # the stack. It is something that happens independently and cannot be
- # relied upon to happen at a convenient time, such as within a call to
- # doRead.
- def messItUp():
- newC, newS = self._connectedPair()
- fileno = server.fileno()
- server.close()
- os.dup2(newS.fileno(), fileno)
- newC.send("x")
- reactor.callLater(0, messItUp)
-
- self.runReactor(reactor)
-
- # If the implementation feels like logging the exception raised by
- # MessedUp.fileno, that's fine.
- self.flushLoggedErrors(socket.error)
- if platform.isWindows():
- test_lostFileDescriptor.skip = (
- "Cannot duplicate socket filenos on Windows")
-
-
-
-class RemovingDescriptor(object):
- """
- A read descriptor which removes itself from the reactor as soon as it
- gets a chance to do a read and keeps track of when its own C{fileno}
- method is called.
-
- @ivar insideReactor: A flag which is true as long as the reactor has
- this descriptor as a reader.
-
- @ivar calls: A list of the bottom of the call stack for any call to
- C{fileno} when C{insideReactor} is false.
- """
- implements(IReadDescriptor)
-
-
- def __init__(self, reactor):
- self.reactor = reactor
- self.insideReactor = False
- self.calls = []
- self.read, self.write = socketpair()
-
-
- def start(self):
- self.insideReactor = True
- self.reactor.addReader(self)
- self.write.send('a')
-
-
- def logPrefix(self):
- return 'foo'
-
-
- def doRead(self):
- self.reactor.removeReader(self)
- self.insideReactor = False
- self.reactor.stop()
-
-
- def fileno(self):
- if not self.insideReactor:
- self.calls.append(traceback.extract_stack(limit=5)[:-1])
- return self.read.fileno()
-
-
- def connectionLost(self, reason):
- pass
-
-
-globals().update(ReactorFDSetTestsBuilder.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_filedescriptor.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_filedescriptor.py
deleted file mode 100755
index 5537a673..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_filedescriptor.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Whitebox tests for L{twisted.internet.abstract.FileDescriptor}.
-"""
-
-from zope.interface.verify import verifyClass
-
-from twisted.internet.abstract import FileDescriptor
-from twisted.internet.interfaces import IPushProducer
-from twisted.trial.unittest import TestCase
-
-
-
-class FileDescriptorTests(TestCase):
- """
- Tests for L{FileDescriptor}.
- """
- def test_writeWithUnicodeRaisesException(self):
- """
- L{FileDescriptor.write} doesn't accept unicode data.
- """
- fileDescriptor = FileDescriptor()
- self.assertRaises(TypeError, fileDescriptor.write, u'foo')
-
-
- def test_writeSequenceWithUnicodeRaisesException(self):
- """
- L{FileDescriptor.writeSequence} doesn't accept unicode data.
- """
- fileDescriptor = FileDescriptor()
- self.assertRaises(
- TypeError, fileDescriptor.writeSequence, ['foo', u'bar', 'baz'])
-
-
- def test_implementInterfaceIPushProducer(self):
- """
- L{FileDescriptor} should implement L{IPushProducer}.
- """
- self.assertTrue(verifyClass(IPushProducer, FileDescriptor))
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_glibbase.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_glibbase.py
deleted file mode 100755
index 0bf79d8a..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_glibbase.py
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for twisted.internet.glibbase.
-"""
-
-import sys
-from twisted.trial.unittest import TestCase
-from twisted.internet._glibbase import ensureNotImported
-
-
-
-class EnsureNotImportedTests(TestCase):
- """
- L{ensureNotImported} protects against unwanted past and future imports.
- """
-
- def test_ensureWhenNotImported(self):
- """
- If the specified modules have never been imported, and import
- prevention is requested, L{ensureNotImported} makes sure they will not
- be imported in the future.
- """
- modules = {}
- self.patch(sys, "modules", modules)
- ensureNotImported(["m1", "m2"], "A message.",
- preventImports=["m1", "m2", "m3"])
- self.assertEquals(modules, {"m1": None, "m2": None, "m3": None})
-
-
- def test_ensureWhenNotImportedDontPrevent(self):
- """
- If the specified modules have never been imported, and import
- prevention is not requested, L{ensureNotImported} has no effect.
- """
- modules = {}
- self.patch(sys, "modules", modules)
- ensureNotImported(["m1", "m2"], "A message.")
- self.assertEquals(modules, {})
-
-
- def test_ensureWhenFailedToImport(self):
- """
- If the specified modules have been set to C{None} in C{sys.modules},
- L{ensureNotImported} does not complain.
- """
- modules = {"m2": None}
- self.patch(sys, "modules", modules)
- ensureNotImported(["m1", "m2"], "A message.", preventImports=["m1", "m2"])
- self.assertEquals(modules, {"m1": None, "m2": None})
-
-
- def test_ensureFailsWhenImported(self):
- """
- If one of the specified modules has been previously imported,
- L{ensureNotImported} raises an exception.
- """
- module = object()
- modules = {"m2": module}
- self.patch(sys, "modules", modules)
- e = self.assertRaises(ImportError, ensureNotImported,
- ["m1", "m2"], "A message.",
- preventImports=["m1", "m2"])
- self.assertEquals(modules, {"m2": module})
- self.assertEquals(e.args, ("A message.",))
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtk3reactor.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtk3reactor.py
deleted file mode 100755
index 60a20e0c..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtk3reactor.py
+++ /dev/null
@@ -1,152 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-GI/GTK3 reactor tests.
-"""
-
-try:
- from twisted.internet import gireactor, gtk3reactor
- from gi.repository import Gtk, Gio
-except ImportError:
- gireactor = None
-
-from twisted.internet.error import ReactorAlreadyRunning
-from twisted.trial.unittest import TestCase, SkipTest
-from twisted.internet.test.reactormixins import ReactorBuilder
-
-
-
-class GtkApplicationRegistration(ReactorBuilder, TestCase):
- """
- GtkApplication and GApplication are supported by
- L{twisted.internet.gtk3reactor} and L{twisted.internet.gireactor}.
-
- We inherit from L{ReactorBuilder} in order to use some of its
- reactor-running infrastructure, but don't need its test-creation
- functionality.
- """
- if gireactor is None:
- skip = "gtk3/gi not importable"
-
-
- def runReactor(self, app, reactor):
- """
- Register the app, run the reactor, make sure app was activated, and
- that reactor was running, and that reactor can be stopped.
- """
- if not hasattr(app, "quit"):
- raise SkipTest("Version of PyGObject is too old.")
-
- result = []
- def stop():
- result.append("stopped")
- reactor.stop()
- def activate(widget):
- result.append("activated")
- reactor.callLater(0, stop)
- app.connect('activate', activate)
-
- # We want reactor.stop() to *always* stop the event loop, even if
- # someone has called hold() on the application and never done the
- # corresponding release() -- for more details see
- # http://developer.gnome.org/gio/unstable/GApplication.html.
- app.hold()
-
- reactor.registerGApplication(app)
- ReactorBuilder.runReactor(self, reactor)
- self.assertEqual(result, ["activated", "stopped"])
-
-
- def test_gApplicationActivate(self):
- """
- L{Gio.Application} instances can be registered with a gireactor.
- """
- reactor = gireactor.GIReactor(useGtk=False)
- self.addCleanup(self.unbuildReactor, reactor)
- app = Gio.Application(
- application_id='com.twistedmatrix.trial.gireactor',
- flags=Gio.ApplicationFlags.FLAGS_NONE)
-
- self.runReactor(app, reactor)
-
-
- def test_gtkApplicationActivate(self):
- """
- L{Gtk.Application} instances can be registered with a gtk3reactor.
- """
- reactor = gtk3reactor.Gtk3Reactor()
- self.addCleanup(self.unbuildReactor, reactor)
- app = Gtk.Application(
- application_id='com.twistedmatrix.trial.gtk3reactor',
- flags=Gio.ApplicationFlags.FLAGS_NONE)
-
- self.runReactor(app, reactor)
-
-
- def test_portable(self):
- """
- L{gireactor.PortableGIReactor} doesn't support application
- registration at this time.
- """
- reactor = gireactor.PortableGIReactor()
- self.addCleanup(self.unbuildReactor, reactor)
- app = Gio.Application(
- application_id='com.twistedmatrix.trial.gireactor',
- flags=Gio.ApplicationFlags.FLAGS_NONE)
- self.assertRaises(NotImplementedError,
- reactor.registerGApplication, app)
-
-
- def test_noQuit(self):
- """
- Older versions of PyGObject lack C{Application.quit}, and so won't
- allow registration.
- """
- reactor = gireactor.GIReactor(useGtk=False)
- self.addCleanup(self.unbuildReactor, reactor)
- # An app with no "quit" method:
- app = object()
- exc = self.assertRaises(RuntimeError, reactor.registerGApplication, app)
- self.assertTrue(exc.args[0].startswith(
- "Application registration is not"))
-
-
- def test_cantRegisterAfterRun(self):
- """
- It is not possible to register a C{Application} after the reactor has
- already started.
- """
- reactor = gireactor.GIReactor(useGtk=False)
- self.addCleanup(self.unbuildReactor, reactor)
- app = Gio.Application(
- application_id='com.twistedmatrix.trial.gireactor',
- flags=Gio.ApplicationFlags.FLAGS_NONE)
-
- def tryRegister():
- exc = self.assertRaises(ReactorAlreadyRunning,
- reactor.registerGApplication, app)
- self.assertEqual(exc.args[0],
- "Can't register application after reactor was started.")
- reactor.stop()
- reactor.callLater(0, tryRegister)
- ReactorBuilder.runReactor(self, reactor)
-
-
- def test_cantRegisterTwice(self):
- """
- It is not possible to register more than one C{Application}.
- """
- reactor = gireactor.GIReactor(useGtk=False)
- self.addCleanup(self.unbuildReactor, reactor)
- app = Gio.Application(
- application_id='com.twistedmatrix.trial.gireactor',
- flags=Gio.ApplicationFlags.FLAGS_NONE)
- reactor.registerGApplication(app)
- app2 = Gio.Application(
- application_id='com.twistedmatrix.trial.gireactor2',
- flags=Gio.ApplicationFlags.FLAGS_NONE)
- exc = self.assertRaises(RuntimeError,
- reactor.registerGApplication, app2)
- self.assertEqual(exc.args[0],
- "Can't register more than one application instance.")
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtkreactor.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtkreactor.py
deleted file mode 100755
index 78039c00..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_gtkreactor.py
+++ /dev/null
@@ -1,95 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests to ensure all attributes of L{twisted.internet.gtkreactor} are
-deprecated.
-"""
-
-import sys
-
-from twisted.trial.unittest import TestCase
-
-
-class GtkReactorDeprecation(TestCase):
- """
- Tests to ensure all attributes of L{twisted.internet.gtkreactor} are
- deprecated.
- """
-
- class StubGTK:
- class GDK:
- INPUT_READ = None
- def input_add(self, *params):
- pass
-
- class StubPyGTK:
- def require(self, something):
- pass
-
- def setUp(self):
- """
- Create a stub for the module 'gtk' if it does not exist, so that it can
- be imported without errors or warnings.
- """
- self.mods = sys.modules.copy()
- sys.modules['gtk'] = self.StubGTK()
- sys.modules['pygtk'] = self.StubPyGTK()
-
-
- def tearDown(self):
- """
- Return sys.modules to the way it was before the test.
- """
- sys.modules.clear()
- sys.modules.update(self.mods)
-
-
- def lookForDeprecationWarning(self, testmethod, attributeName):
- warningsShown = self.flushWarnings([testmethod])
- self.assertEqual(len(warningsShown), 1)
- self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
- self.assertEqual(
- warningsShown[0]['message'],
- "twisted.internet.gtkreactor." + attributeName + " "
- "was deprecated in Twisted 10.1.0: All new applications should be "
- "written with gtk 2.x, which is supported by "
- "twisted.internet.gtk2reactor.")
-
-
- def test_gtkReactor(self):
- """
- Test deprecation of L{gtkreactor.GtkReactor}
- """
- from twisted.internet import gtkreactor
- gtkreactor.GtkReactor();
- self.lookForDeprecationWarning(self.test_gtkReactor, "GtkReactor")
-
-
- def test_portableGtkReactor(self):
- """
- Test deprecation of L{gtkreactor.GtkReactor}
- """
- from twisted.internet import gtkreactor
- gtkreactor.PortableGtkReactor()
- self.lookForDeprecationWarning(self.test_portableGtkReactor,
- "PortableGtkReactor")
-
-
- def test_install(self):
- """
- Test deprecation of L{gtkreactor.install}
- """
- from twisted.internet import gtkreactor
- self.assertRaises(AssertionError, gtkreactor.install)
- self.lookForDeprecationWarning(self.test_install, "install")
-
-
- def test_portableInstall(self):
- """
- Test deprecation of L{gtkreactor.portableInstall}
- """
- from twisted.internet import gtkreactor
- self.assertRaises(AssertionError, gtkreactor.portableInstall)
- self.lookForDeprecationWarning(self.test_portableInstall,
- "portableInstall")
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inlinecb.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inlinecb.py
deleted file mode 100755
index 7b818d2d..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inlinecb.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Conditional import of C{inlinecb_tests} for Python 2.5 and greater.
-"""
-import sys
-
-__all__ = ['NonLocalExitTests']
-
-if sys.version_info[:2] >= (2, 5):
- from twisted.internet.test.inlinecb_tests import NonLocalExitTests
-
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inotify.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inotify.py
deleted file mode 100755
index a0035622..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_inotify.py
+++ /dev/null
@@ -1,504 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for the inotify wrapper in L{twisted.internet.inotify}.
-"""
-
-from twisted.internet import defer, reactor
-from twisted.python import filepath, runtime
-from twisted.trial import unittest
-
-try:
- from twisted.python import _inotify
-except ImportError:
- inotify = None
-else:
- from twisted.internet import inotify
-
-
-
-class TestINotify(unittest.TestCase):
- """
- Define all the tests for the basic functionality exposed by
- L{inotify.INotify}.
- """
- if not runtime.platform.supportsINotify():
- skip = "This platform doesn't support INotify."
-
- def setUp(self):
- self.dirname = filepath.FilePath(self.mktemp())
- self.dirname.createDirectory()
- self.inotify = inotify.INotify()
- self.inotify.startReading()
- self.addCleanup(self.inotify.loseConnection)
-
-
- def test_initializationErrors(self):
- """
- L{inotify.INotify} emits a C{RuntimeError} when initialized
- in an environment that doesn't support inotify as we expect it.
-
- We just try to raise an exception for every possible case in
- the for loop in L{inotify.INotify._inotify__init__}.
- """
- class FakeINotify:
- def init(self):
- raise inotify.INotifyError()
- self.patch(inotify.INotify, '_inotify', FakeINotify())
- self.assertRaises(inotify.INotifyError, inotify.INotify)
-
-
- def _notificationTest(self, mask, operation, expectedPath=None):
- """
- Test notification from some filesystem operation.
-
- @param mask: The event mask to use when setting up the watch.
-
- @param operation: A function which will be called with the
- name of a file in the watched directory and which should
- trigger the event.
-
- @param expectedPath: Optionally, the name of the path which is
- expected to come back in the notification event; this will
- also be passed to C{operation} (primarily useful when the
- operation is being done to the directory itself, not a
- file in it).
-
- @return: A L{Deferred} which fires successfully when the
- expected event has been received or fails otherwise.
- """
- if expectedPath is None:
- expectedPath = self.dirname.child("foo.bar")
- notified = defer.Deferred()
- def cbNotified((watch, filename, events)):
- self.assertEqual(filename, expectedPath)
- self.assertTrue(events & mask)
- notified.addCallback(cbNotified)
-
- self.inotify.watch(
- self.dirname, mask=mask,
- callbacks=[lambda *args: notified.callback(args)])
- operation(expectedPath)
- return notified
-
-
- def test_access(self):
- """
- Reading from a file in a monitored directory sends an
- C{inotify.IN_ACCESS} event to the callback.
- """
- def operation(path):
- path.setContent("foo")
- path.getContent()
-
- return self._notificationTest(inotify.IN_ACCESS, operation)
-
-
- def test_modify(self):
- """
- Writing to a file in a monitored directory sends an
- C{inotify.IN_MODIFY} event to the callback.
- """
- def operation(path):
- fObj = path.open("w")
- fObj.write('foo')
- fObj.close()
-
- return self._notificationTest(inotify.IN_MODIFY, operation)
-
-
- def test_attrib(self):
- """
- Changing the metadata of a a file in a monitored directory
- sends an C{inotify.IN_ATTRIB} event to the callback.
- """
- def operation(path):
- path.touch()
- path.touch()
-
- return self._notificationTest(inotify.IN_ATTRIB, operation)
-
-
- def test_closeWrite(self):
- """
- Closing a file which was open for writing in a monitored
- directory sends an C{inotify.IN_CLOSE_WRITE} event to the
- callback.
- """
- def operation(path):
- fObj = path.open("w")
- fObj.close()
-
- return self._notificationTest(inotify.IN_CLOSE_WRITE, operation)
-
-
- def test_closeNoWrite(self):
- """
- Closing a file which was open for reading but not writing in a
- monitored directory sends an C{inotify.IN_CLOSE_NOWRITE} event
- to the callback.
- """
- def operation(path):
- path.touch()
- fObj = path.open("r")
- fObj.close()
-
- return self._notificationTest(inotify.IN_CLOSE_NOWRITE, operation)
-
-
- def test_open(self):
- """
- Opening a file in a monitored directory sends an
- C{inotify.IN_OPEN} event to the callback.
- """
- def operation(path):
- fObj = path.open("w")
- fObj.close()
-
- return self._notificationTest(inotify.IN_OPEN, operation)
-
-
- def test_movedFrom(self):
- """
- Moving a file out of a monitored directory sends an
- C{inotify.IN_MOVED_FROM} event to the callback.
- """
- def operation(path):
- fObj = path.open("w")
- fObj.close()
- path.moveTo(filepath.FilePath(self.mktemp()))
-
- return self._notificationTest(inotify.IN_MOVED_FROM, operation)
-
-
- def test_movedTo(self):
- """
- Moving a file into a monitored directory sends an
- C{inotify.IN_MOVED_TO} event to the callback.
- """
- def operation(path):
- p = filepath.FilePath(self.mktemp())
- p.touch()
- p.moveTo(path)
-
- return self._notificationTest(inotify.IN_MOVED_TO, operation)
-
-
- def test_create(self):
- """
- Creating a file in a monitored directory sends an
- C{inotify.IN_CREATE} event to the callback.
- """
- def operation(path):
- fObj = path.open("w")
- fObj.close()
-
- return self._notificationTest(inotify.IN_CREATE, operation)
-
-
- def test_delete(self):
- """
- Deleting a file in a monitored directory sends an
- C{inotify.IN_DELETE} event to the callback.
- """
- def operation(path):
- path.touch()
- path.remove()
-
- return self._notificationTest(inotify.IN_DELETE, operation)
-
-
- def test_deleteSelf(self):
- """
- Deleting the monitored directory itself sends an
- C{inotify.IN_DELETE_SELF} event to the callback.
- """
- def operation(path):
- path.remove()
-
- return self._notificationTest(
- inotify.IN_DELETE_SELF, operation, expectedPath=self.dirname)
-
-
- def test_moveSelf(self):
- """
- Renaming the monitored directory itself sends an
- C{inotify.IN_MOVE_SELF} event to the callback.
- """
- def operation(path):
- path.moveTo(filepath.FilePath(self.mktemp()))
-
- return self._notificationTest(
- inotify.IN_MOVE_SELF, operation, expectedPath=self.dirname)
-
-
- def test_simpleSubdirectoryAutoAdd(self):
- """
- L{inotify.INotify} when initialized with autoAdd==True adds
- also adds the created subdirectories to the watchlist.
- """
- def _callback(wp, filename, mask):
- # We are notified before we actually process new
- # directories, so we need to defer this check.
- def _():
- try:
- self.assertTrue(self.inotify._isWatched(subdir))
- d.callback(None)
- except Exception:
- d.errback()
- reactor.callLater(0, _)
-
- checkMask = inotify.IN_ISDIR | inotify.IN_CREATE
- self.inotify.watch(
- self.dirname, mask=checkMask, autoAdd=True,
- callbacks=[_callback])
- subdir = self.dirname.child('test')
- d = defer.Deferred()
- subdir.createDirectory()
- return d
-
-
- def test_simpleDeleteDirectory(self):
- """
- L{inotify.INotify} removes a directory from the watchlist when
- it's removed from the filesystem.
- """
- calls = []
- def _callback(wp, filename, mask):
- # We are notified before we actually process new
- # directories, so we need to defer this check.
- def _():
- try:
- self.assertTrue(self.inotify._isWatched(subdir))
- subdir.remove()
- except Exception:
- d.errback()
- def _eb():
- # second call, we have just removed the subdir
- try:
- self.assertTrue(not self.inotify._isWatched(subdir))
- d.callback(None)
- except Exception:
- d.errback()
-
- if not calls:
- # first call, it's the create subdir
- calls.append(filename)
- reactor.callLater(0, _)
-
- else:
- reactor.callLater(0, _eb)
-
- checkMask = inotify.IN_ISDIR | inotify.IN_CREATE
- self.inotify.watch(
- self.dirname, mask=checkMask, autoAdd=True,
- callbacks=[_callback])
- subdir = self.dirname.child('test')
- d = defer.Deferred()
- subdir.createDirectory()
- return d
-
-
- def test_ignoreDirectory(self):
- """
- L{inotify.INotify.ignore} removes a directory from the watchlist
- """
- self.inotify.watch(self.dirname, autoAdd=True)
- self.assertTrue(self.inotify._isWatched(self.dirname))
- self.inotify.ignore(self.dirname)
- self.assertFalse(self.inotify._isWatched(self.dirname))
-
-
- def test_humanReadableMask(self):
- """
- L{inotify.humaReadableMask} translates all the possible event
- masks to a human readable string.
- """
- for mask, value in inotify._FLAG_TO_HUMAN:
- self.assertEqual(inotify.humanReadableMask(mask)[0], value)
-
- checkMask = (
- inotify.IN_CLOSE_WRITE | inotify.IN_ACCESS | inotify.IN_OPEN)
- self.assertEqual(
- set(inotify.humanReadableMask(checkMask)),
- set(['close_write', 'access', 'open']))
-
-
- def test_recursiveWatch(self):
- """
- L{inotify.INotify.watch} with recursive==True will add all the
- subdirectories under the given path to the watchlist.
- """
- subdir = self.dirname.child('test')
- subdir2 = subdir.child('test2')
- subdir3 = subdir2.child('test3')
- subdir3.makedirs()
- dirs = [subdir, subdir2, subdir3]
- self.inotify.watch(self.dirname, recursive=True)
- # let's even call this twice so that we test that nothing breaks
- self.inotify.watch(self.dirname, recursive=True)
- for d in dirs:
- self.assertTrue(self.inotify._isWatched(d))
-
-
- def test_connectionLostError(self):
- """
- L{inotify.INotify.connectionLost} if there's a problem while closing
- the fd shouldn't raise the exception but should log the error
- """
- import os
- in_ = inotify.INotify()
- os.close(in_._fd)
- in_.loseConnection()
- self.flushLoggedErrors()
-
- def test_noAutoAddSubdirectory(self):
- """
- L{inotify.INotify.watch} with autoAdd==False will stop inotify
- from watching subdirectories created under the watched one.
- """
- def _callback(wp, fp, mask):
- # We are notified before we actually process new
- # directories, so we need to defer this check.
- def _():
- try:
- self.assertFalse(self.inotify._isWatched(subdir.path))
- d.callback(None)
- except Exception:
- d.errback()
- reactor.callLater(0, _)
-
- checkMask = inotify.IN_ISDIR | inotify.IN_CREATE
- self.inotify.watch(
- self.dirname, mask=checkMask, autoAdd=False,
- callbacks=[_callback])
- subdir = self.dirname.child('test')
- d = defer.Deferred()
- subdir.createDirectory()
- return d
-
-
- def test_seriesOfWatchAndIgnore(self):
- """
- L{inotify.INotify} will watch a filepath for events even if the same
- path is repeatedly added/removed/re-added to the watchpoints.
- """
- expectedPath = self.dirname.child("foo.bar2")
- expectedPath.touch()
-
- notified = defer.Deferred()
- def cbNotified((ignored, filename, events)):
- self.assertEqual(filename, expectedPath)
- self.assertTrue(events & inotify.IN_DELETE_SELF)
-
- def callIt(*args):
- notified.callback(args)
-
- # Watch, ignore, watch again to get into the state being tested.
- self.assertTrue(self.inotify.watch(expectedPath, callbacks=[callIt]))
- self.inotify.ignore(expectedPath)
- self.assertTrue(
- self.inotify.watch(
- expectedPath, mask=inotify.IN_DELETE_SELF, callbacks=[callIt]))
-
- notified.addCallback(cbNotified)
-
- # Apparently in kernel version < 2.6.25, inofify has a bug in the way
- # similar events are coalesced. So, be sure to generate a different
- # event here than the touch() at the top of this method might have
- # generated.
- expectedPath.remove()
-
- return notified
-
-
- def test_ignoreFilePath(self):
- """
- L{inotify.INotify} will ignore a filepath after it has been removed from
- the watch list.
- """
- expectedPath = self.dirname.child("foo.bar2")
- expectedPath.touch()
- expectedPath2 = self.dirname.child("foo.bar3")
- expectedPath2.touch()
-
- notified = defer.Deferred()
- def cbNotified((ignored, filename, events)):
- self.assertEqual(filename, expectedPath2)
- self.assertTrue(events & inotify.IN_DELETE_SELF)
-
- def callIt(*args):
- notified.callback(args)
-
- self.assertTrue(
- self.inotify.watch(
- expectedPath, inotify.IN_DELETE_SELF, callbacks=[callIt]))
- notified.addCallback(cbNotified)
-
- self.assertTrue(
- self.inotify.watch(
- expectedPath2, inotify.IN_DELETE_SELF, callbacks=[callIt]))
-
- self.inotify.ignore(expectedPath)
-
- expectedPath.remove()
- expectedPath2.remove()
-
- return notified
-
-
- def test_ignoreNonWatchedFile(self):
- """
- L{inotify.INotify} will raise KeyError if a non-watched filepath is
- ignored.
- """
- expectedPath = self.dirname.child("foo.ignored")
- expectedPath.touch()
-
- self.assertRaises(KeyError, self.inotify.ignore, expectedPath)
-
-
- def test_complexSubdirectoryAutoAdd(self):
- """
- L{inotify.INotify} with autoAdd==True for a watched path
- generates events for every file or directory already present
- in a newly created subdirectory under the watched one.
-
- This tests that we solve a race condition in inotify even though
- we may generate duplicate events.
- """
- calls = set()
- def _callback(wp, filename, mask):
- calls.add(filename)
- if len(calls) == 6:
- try:
- self.assertTrue(self.inotify._isWatched(subdir))
- self.assertTrue(self.inotify._isWatched(subdir2))
- self.assertTrue(self.inotify._isWatched(subdir3))
- created = someFiles + [subdir, subdir2, subdir3]
- self.assertEqual(len(calls), len(created))
- self.assertEqual(calls, set(created))
- except Exception:
- d.errback()
- else:
- d.callback(None)
-
- checkMask = inotify.IN_ISDIR | inotify.IN_CREATE
- self.inotify.watch(
- self.dirname, mask=checkMask, autoAdd=True,
- callbacks=[_callback])
- subdir = self.dirname.child('test')
- subdir2 = subdir.child('test2')
- subdir3 = subdir2.child('test3')
- d = defer.Deferred()
- subdir3.makedirs()
-
- someFiles = [subdir.child('file1.dat'),
- subdir2.child('file2.dat'),
- subdir3.child('file3.dat')]
- # Add some files in pretty much all the directories so that we
- # see that we process all of them.
- for i, filename in enumerate(someFiles):
- filename.setContent(filename.path)
- return d
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_interfaces.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_interfaces.py
deleted file mode 100755
index f9f60dab..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_interfaces.py
+++ /dev/null
@@ -1,53 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.interfaces}.
-"""
-
-from twisted.trial import unittest
-
-
-class TestIFinishableConsumer(unittest.TestCase):
- """
- L{IFinishableConsumer} is deprecated.
- """
-
- def lookForDeprecationWarning(self, testmethod):
- """
- Importing C{testmethod} emits a deprecation warning.
- """
- warningsShown = self.flushWarnings([testmethod])
- self.assertEqual(len(warningsShown), 1)
- self.assertIdentical(warningsShown[0]['category'], DeprecationWarning)
- self.assertEqual(
- warningsShown[0]['message'],
- "twisted.internet.interfaces.IFinishableConsumer "
- "was deprecated in Twisted 11.1.0: Please use IConsumer "
- "(and IConsumer.unregisterProducer) instead.")
-
-
- def test_deprecationWithDirectImport(self):
- """
- Importing L{IFinishableConsumer} causes a deprecation warning
- """
- from twisted.internet.interfaces import IFinishableConsumer
- self.lookForDeprecationWarning(
- TestIFinishableConsumer.test_deprecationWithDirectImport)
-
-
- def test_deprecationWithIndirectImport(self):
- """
- Importing L{interfaces} and implementing
- L{interfaces.IFinishableConsumer} causes a deprecation warning
- """
- from zope.interface import implements
- from twisted.internet import interfaces
-
- class FakeIFinishableConsumer:
- implements(interfaces.IFinishableConsumer)
- def finish(self):
- pass
-
- self.lookForDeprecationWarning(
- TestIFinishableConsumer.test_deprecationWithIndirectImport)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_iocp.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_iocp.py
deleted file mode 100755
index 76d7646a..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_iocp.py
+++ /dev/null
@@ -1,150 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.iocpreactor}.
-"""
-
-import errno
-from array import array
-from struct import pack
-from socket import AF_INET6, AF_INET, SOCK_STREAM, SOL_SOCKET, error, socket
-
-from zope.interface.verify import verifyClass
-
-from twisted.trial import unittest
-from twisted.python.log import msg
-from twisted.internet.interfaces import IPushProducer
-
-try:
- from twisted.internet.iocpreactor import iocpsupport as _iocp, tcp, udp
- from twisted.internet.iocpreactor.reactor import IOCPReactor, EVENTS_PER_LOOP, KEY_NORMAL
- from twisted.internet.iocpreactor.interfaces import IReadWriteHandle
- from twisted.internet.iocpreactor.const import SO_UPDATE_ACCEPT_CONTEXT
- from twisted.internet.iocpreactor.abstract import FileHandle
-except ImportError:
- skip = 'This test only applies to IOCPReactor'
-
-try:
- socket(AF_INET6, SOCK_STREAM).close()
-except error, e:
- ipv6Skip = str(e)
-else:
- ipv6Skip = None
-
-class SupportTests(unittest.TestCase):
- """
- Tests for L{twisted.internet.iocpreactor.iocpsupport}, low-level reactor
- implementation helpers.
- """
- def _acceptAddressTest(self, family, localhost):
- """
- Create a C{SOCK_STREAM} connection to localhost using a socket with an
- address family of C{family} and assert that the result of
- L{iocpsupport.get_accept_addrs} is consistent with the result of
- C{socket.getsockname} and C{socket.getpeername}.
- """
- msg("family = %r" % (family,))
- port = socket(family, SOCK_STREAM)
- self.addCleanup(port.close)
- port.bind(('', 0))
- port.listen(1)
- client = socket(family, SOCK_STREAM)
- self.addCleanup(client.close)
- client.setblocking(False)
- try:
- client.connect((localhost, port.getsockname()[1]))
- except error, (errnum, message):
- self.assertIn(errnum, (errno.EINPROGRESS, errno.EWOULDBLOCK))
-
- server = socket(family, SOCK_STREAM)
- self.addCleanup(server.close)
- buff = array('c', '\0' * 256)
- self.assertEqual(
- 0, _iocp.accept(port.fileno(), server.fileno(), buff, None))
- server.setsockopt(
- SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, pack('P', server.fileno()))
- self.assertEqual(
- (family, client.getpeername()[:2], client.getsockname()[:2]),
- _iocp.get_accept_addrs(server.fileno(), buff))
-
-
- def test_ipv4AcceptAddress(self):
- """
- L{iocpsupport.get_accept_addrs} returns a three-tuple of address
- information about the socket associated with the file descriptor passed
- to it. For a connection using IPv4:
-
- - the first element is C{AF_INET}
- - the second element is a two-tuple of a dotted decimal notation IPv4
- address and a port number giving the peer address of the connection
- - the third element is the same type giving the host address of the
- connection
- """
- self._acceptAddressTest(AF_INET, '127.0.0.1')
-
-
- def test_ipv6AcceptAddress(self):
- """
- Like L{test_ipv4AcceptAddress}, but for IPv6 connections. In this case:
-
- - the first element is C{AF_INET6}
- - the second element is a two-tuple of a hexadecimal IPv6 address
- literal and a port number giving the peer address of the connection
- - the third element is the same type giving the host address of the
- connection
- """
- self._acceptAddressTest(AF_INET6, '::1')
- if ipv6Skip is not None:
- test_ipv6AcceptAddress.skip = ipv6Skip
-
-
-
-class IOCPReactorTestCase(unittest.TestCase):
- def test_noPendingTimerEvents(self):
- """
- Test reactor behavior (doIteration) when there are no pending time
- events.
- """
- ir = IOCPReactor()
- ir.wakeUp()
- self.failIf(ir.doIteration(None))
-
-
- def test_reactorInterfaces(self):
- """
- Verify that IOCP socket-representing classes implement IReadWriteHandle
- """
- self.assertTrue(verifyClass(IReadWriteHandle, tcp.Connection))
- self.assertTrue(verifyClass(IReadWriteHandle, udp.Port))
-
-
- def test_fileHandleInterfaces(self):
- """
- Verify that L{Filehandle} implements L{IPushProducer}.
- """
- self.assertTrue(verifyClass(IPushProducer, FileHandle))
-
-
- def test_maxEventsPerIteration(self):
- """
- Verify that we don't lose an event when more than EVENTS_PER_LOOP
- events occur in the same reactor iteration
- """
- class FakeFD:
- counter = 0
- def logPrefix(self):
- return 'FakeFD'
- def cb(self, rc, bytes, evt):
- self.counter += 1
-
- ir = IOCPReactor()
- fd = FakeFD()
- event = _iocp.Event(fd.cb, fd)
- for _ in range(EVENTS_PER_LOOP + 1):
- ir.port.postEvent(0, KEY_NORMAL, event)
- ir.doIteration(None)
- self.assertEqual(fd.counter, EVENTS_PER_LOOP)
- ir.doIteration(0)
- self.assertEqual(fd.counter, EVENTS_PER_LOOP + 1)
-
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_main.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_main.py
deleted file mode 100755
index 12c8a3f2..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_main.py
+++ /dev/null
@@ -1,38 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.main}.
-"""
-
-from twisted.trial import unittest
-from twisted.internet.error import ReactorAlreadyInstalledError
-from twisted.internet.main import installReactor
-
-
-class InstallReactorTests(unittest.TestCase):
- """
- Tests for L{installReactor}
- """
-
- def test_alreadyInstalled(self):
- """
- If a reactor is already installed, L{installReactor} raises
- L{ReactorAlreadyInstalledError}.
- """
- # Because this test runs in trial, assume a reactor is already
- # installed.
- self.assertRaises(ReactorAlreadyInstalledError, installReactor,
- object())
-
-
- def test_errorIsAnAssertionError(self):
- """
- For backwards compatibility, L{ReactorAlreadyInstalledError} is an
- L{AssertionError}.
- """
- self.assertTrue(issubclass(ReactorAlreadyInstalledError,
- AssertionError))
-
-
-
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_newtls.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_newtls.py
deleted file mode 100755
index a196cb51..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_newtls.py
+++ /dev/null
@@ -1,194 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet._newtls}.
-"""
-
-from twisted.trial import unittest
-from twisted.internet.test.reactormixins import ReactorBuilder, runProtocolsWithReactor
-from twisted.internet.test.reactormixins import ConnectableProtocol
-from twisted.internet.test.test_tls import SSLCreator, TLSMixin
-from twisted.internet.test.test_tls import StartTLSClientCreator
-from twisted.internet.test.test_tls import ContextGeneratingMixin
-from twisted.internet.test.test_tcp import TCPCreator
-try:
- from twisted.protocols import tls
- from twisted.internet import _newtls
-except ImportError:
- _newtls = None
-
-
-class BypassTLSTests(unittest.TestCase):
- """
- Tests for the L{_newtls._BypassTLS} class.
- """
-
- if not _newtls:
- skip = "Couldn't import _newtls, perhaps pyOpenSSL is old or missing"
-
- def test_loseConnectionPassThrough(self):
- """
- C{_BypassTLS.loseConnection} calls C{loseConnection} on the base
- class, while preserving any default argument in the base class'
- C{loseConnection} implementation.
- """
- default = object()
- result = []
-
- class FakeTransport(object):
- def loseConnection(self, _connDone=default):
- result.append(_connDone)
-
- bypass = _newtls._BypassTLS(FakeTransport, FakeTransport())
-
- # The default from FakeTransport is used:
- bypass.loseConnection()
- self.assertEqual(result, [default])
-
- # And we can pass our own:
- notDefault = object()
- bypass.loseConnection(notDefault)
- self.assertEqual(result, [default, notDefault])
-
-
-
-class FakeProducer(object):
- """
- A producer that does nothing.
- """
-
- def pauseProducing(self):
- pass
-
-
- def resumeProducing(self):
- pass
-
-
- def stopProducing(self):
- pass
-
-
-
-class ProducerProtocol(ConnectableProtocol):
- """
- Register a producer, unregister it, and verify the producer hooks up to
- innards of C{TLSMemoryBIOProtocol}.
- """
-
- def __init__(self, producer, result):
- self.producer = producer
- self.result = result
-
-
- def connectionMade(self):
- if not isinstance(self.transport.protocol,
- tls.TLSMemoryBIOProtocol):
- # Either the test or the code have a bug...
- raise RuntimeError("TLSMemoryBIOProtocol not hooked up.")
-
- self.transport.registerProducer(self.producer, True)
- # The producer was registered with the TLSMemoryBIOProtocol:
- self.result.append(self.transport.protocol._producer._producer)
-
- self.transport.unregisterProducer()
- # The producer was unregistered from the TLSMemoryBIOProtocol:
- self.result.append(self.transport.protocol._producer)
- self.transport.loseConnection()
-
-
-
-class ProducerTestsMixin(ReactorBuilder, TLSMixin, ContextGeneratingMixin):
- """
- Test the new TLS code integrates C{TLSMemoryBIOProtocol} correctly.
- """
-
- if not _newtls:
- skip = "Could not import twisted.internet._newtls"
-
- def test_producerSSLFromStart(self):
- """
- C{registerProducer} and C{unregisterProducer} on TLS transports
- created as SSL from the get go are passed to the
- C{TLSMemoryBIOProtocol}, not the underlying transport directly.
- """
- result = []
- producer = FakeProducer()
-
- runProtocolsWithReactor(self, ConnectableProtocol(),
- ProducerProtocol(producer, result),
- SSLCreator())
- self.assertEqual(result, [producer, None])
-
-
- def test_producerAfterStartTLS(self):
- """
- C{registerProducer} and C{unregisterProducer} on TLS transports
- created by C{startTLS} are passed to the C{TLSMemoryBIOProtocol}, not
- the underlying transport directly.
- """
- result = []
- producer = FakeProducer()
-
- runProtocolsWithReactor(self, ConnectableProtocol(),
- ProducerProtocol(producer, result),
- StartTLSClientCreator())
- self.assertEqual(result, [producer, None])
-
-
- def startTLSAfterRegisterProducer(self, streaming):
- """
- When a producer is registered, and then startTLS is called,
- the producer is re-registered with the C{TLSMemoryBIOProtocol}.
- """
- clientContext = self.getClientContext()
- serverContext = self.getServerContext()
- result = []
- producer = FakeProducer()
-
- class RegisterTLSProtocol(ConnectableProtocol):
- def connectionMade(self):
- self.transport.registerProducer(producer, streaming)
- self.transport.startTLS(serverContext)
- # Store TLSMemoryBIOProtocol and underlying transport producer
- # status:
- if streaming:
- # _ProducerMembrane -> producer:
- result.append(self.transport.protocol._producer._producer)
- result.append(self.transport.producer._producer)
- else:
- # _ProducerMembrane -> _PullToPush -> producer:
- result.append(
- self.transport.protocol._producer._producer._producer)
- result.append(self.transport.producer._producer._producer)
- self.transport.unregisterProducer()
- self.transport.loseConnection()
-
- class StartTLSProtocol(ConnectableProtocol):
- def connectionMade(self):
- self.transport.startTLS(clientContext)
-
- runProtocolsWithReactor(self, RegisterTLSProtocol(),
- StartTLSProtocol(), TCPCreator())
- self.assertEqual(result, [producer, producer])
-
-
- def test_startTLSAfterRegisterProducerStreaming(self):
- """
- When a streaming producer is registered, and then startTLS is called,
- the producer is re-registered with the C{TLSMemoryBIOProtocol}.
- """
- self.startTLSAfterRegisterProducer(True)
-
-
- def test_startTLSAfterRegisterProducerNonStreaming(self):
- """
- When a non-streaming producer is registered, and then startTLS is
- called, the producer is re-registered with the
- C{TLSMemoryBIOProtocol}.
- """
- self.startTLSAfterRegisterProducer(False)
-
-
-globals().update(ProducerTestsMixin.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_pollingfile.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_pollingfile.py
deleted file mode 100755
index 75022adf..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_pollingfile.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet._pollingfile}.
-"""
-
-from twisted.python.runtime import platform
-from twisted.trial.unittest import TestCase
-
-if platform.isWindows():
- from twisted.internet import _pollingfile
-else:
- _pollingfile = None
-
-
-
-class TestPollableWritePipe(TestCase):
- """
- Tests for L{_pollingfile._PollableWritePipe}.
- """
-
- def test_writeUnicode(self):
- """
- L{_pollingfile._PollableWritePipe.write} raises a C{TypeError} if an
- attempt is made to append unicode data to the output buffer.
- """
- p = _pollingfile._PollableWritePipe(1, lambda: None)
- self.assertRaises(TypeError, p.write, u"test")
-
-
- def test_writeSequenceUnicode(self):
- """
- L{_pollingfile._PollableWritePipe.writeSequence} raises a C{TypeError}
- if unicode data is part of the data sequence to be appended to the
- output buffer.
- """
- p = _pollingfile._PollableWritePipe(1, lambda: None)
- self.assertRaises(TypeError, p.writeSequence, [u"test"])
- self.assertRaises(TypeError, p.writeSequence, (u"test", ))
-
-
-
-
-if _pollingfile is None:
- TestPollableWritePipe.skip = "Test will run only on Windows."
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixbase.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixbase.py
deleted file mode 100755
index 2e0c2ec4..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixbase.py
+++ /dev/null
@@ -1,387 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.posixbase} and supporting code.
-"""
-
-from twisted.python.compat import set
-from twisted.trial.unittest import TestCase
-from twisted.internet.defer import Deferred
-from twisted.internet.posixbase import PosixReactorBase, _Waker
-from twisted.internet.protocol import ServerFactory
-
-
-skipSockets = None
-try:
- from twisted.internet import unix
-except ImportError:
- skipSockets = "Platform does not support AF_UNIX sockets"
-
-from twisted.internet.tcp import Port
-from twisted.internet import reactor
-from twisted.test.test_unix import ClientProto
-
-class TrivialReactor(PosixReactorBase):
- def __init__(self):
- self._readers = {}
- self._writers = {}
- PosixReactorBase.__init__(self)
-
-
- def addReader(self, reader):
- self._readers[reader] = True
-
-
- def removeReader(self, reader):
- del self._readers[reader]
-
-
- def addWriter(self, writer):
- self._writers[writer] = True
-
-
- def removeWriter(self, writer):
- del self._writers[writer]
-
-
-
-class PosixReactorBaseTests(TestCase):
- """
- Tests for L{PosixReactorBase}.
- """
-
- def _checkWaker(self, reactor):
- self.assertIsInstance(reactor.waker, _Waker)
- self.assertIn(reactor.waker, reactor._internalReaders)
- self.assertIn(reactor.waker, reactor._readers)
-
-
- def test_wakerIsInternalReader(self):
- """
- When L{PosixReactorBase} is instantiated, it creates a waker and adds
- it to its internal readers set.
- """
- reactor = TrivialReactor()
- self._checkWaker(reactor)
-
-
- def test_removeAllSkipsInternalReaders(self):
- """
- Any L{IReadDescriptors} in L{PosixReactorBase._internalReaders} are
- left alone by L{PosixReactorBase._removeAll}.
- """
- reactor = TrivialReactor()
- extra = object()
- reactor._internalReaders.add(extra)
- reactor.addReader(extra)
- reactor._removeAll(reactor._readers, reactor._writers)
- self._checkWaker(reactor)
- self.assertIn(extra, reactor._internalReaders)
- self.assertIn(extra, reactor._readers)
-
-
- def test_removeAllReturnsRemovedDescriptors(self):
- """
- L{PosixReactorBase._removeAll} returns a list of removed
- L{IReadDescriptor} and L{IWriteDescriptor} objects.
- """
- reactor = TrivialReactor()
- reader = object()
- writer = object()
- reactor.addReader(reader)
- reactor.addWriter(writer)
- removed = reactor._removeAll(
- reactor._readers, reactor._writers)
- self.assertEqual(set(removed), set([reader, writer]))
- self.assertNotIn(reader, reactor._readers)
- self.assertNotIn(writer, reactor._writers)
-
-
- def test_IReactorArbitraryIsDeprecated(self):
- """
- L{twisted.internet.interfaces.IReactorArbitrary} is redundant with
- L{twisted.internet.interfaces.IReactorFDSet} and is deprecated.
- """
- from twisted.internet import interfaces
- interfaces.IReactorArbitrary
-
- warningsShown = self.flushWarnings(
- [self.test_IReactorArbitraryIsDeprecated])
- self.assertEqual(len(warningsShown), 1)
- self.assertEqual(warningsShown[0]['category'], DeprecationWarning)
- self.assertEqual(
- "twisted.internet.interfaces.IReactorArbitrary was deprecated "
- "in Twisted 10.1.0: See IReactorFDSet.",
- warningsShown[0]['message'])
-
-
- def test_listenWithIsDeprecated(self):
- """
- L{PosixReactorBase} implements the deprecated L{IReactorArbitrary}, and
- L{PosixReactorBase.listenWith} is a part of that interface. To avoid
- unnecessary deprecation warnings when importing posixbase, the
- L{twisted.internet.interfaces._IReactorArbitrary} alias that doesn't
- have the deprecation warning is imported, and instead
- L{PosixReactorBase.listenWith} generates its own deprecation warning.
- """
- class fakePort:
- def __init__(self, *args, **kw):
- pass
-
- def startListening(self):
- pass
-
- reactor = TrivialReactor()
- reactor.listenWith(fakePort)
-
- warnings = self.flushWarnings([self.test_listenWithIsDeprecated])
- self.assertEqual(len(warnings), 1)
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(
- "listenWith is deprecated since Twisted 10.1. "
- "See IReactorFDSet.",
- warnings[0]['message'])
-
-
- def test_connectWithIsDeprecated(self):
- """
- L{PosixReactorBase} implements the deprecated L{IReactorArbitrary}, and
- L{PosixReactorBase.connectWith} is a part of that interface. To avoid
- unnecessary deprecation warnings when importing posixbase, the
- L{twisted.internet.interfaces._IReactorArbitrary} alias that doesn't
- have the deprecation warning is imported, and instead
- L{PosixReactorBase.connectWith} generates its own deprecation warning.
- """
- class fakeConnector:
- def __init__(self, *args, **kw):
- pass
-
- def connect(self):
- pass
-
- reactor = TrivialReactor()
- reactor.connectWith(fakeConnector)
-
- warnings = self.flushWarnings([self.test_connectWithIsDeprecated])
- self.assertEqual(len(warnings), 1)
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(
- "connectWith is deprecated since Twisted 10.1. "
- "See IReactorFDSet.",
- warnings[0]['message'])
-
-
-
-class TCPPortTests(TestCase):
- """
- Tests for L{twisted.internet.tcp.Port}.
- """
-
- if not isinstance(reactor, PosixReactorBase):
- skip = "Non-posixbase reactor"
-
- def test_connectionLostFailed(self):
- """
- L{Port.stopListening} returns a L{Deferred} which errbacks if
- L{Port.connectionLost} raises an exception.
- """
- port = Port(12345, ServerFactory())
- port.connected = True
- port.connectionLost = lambda reason: 1 // 0
- return self.assertFailure(port.stopListening(), ZeroDivisionError)
-
-
-
-class TimeoutReportReactor(PosixReactorBase):
- """
- A reactor which is just barely runnable and which cannot monitor any
- readers or writers, and which fires a L{Deferred} with the timeout
- passed to its C{doIteration} method as soon as that method is invoked.
- """
- def __init__(self):
- PosixReactorBase.__init__(self)
- self.iterationTimeout = Deferred()
- self.now = 100
-
-
- def addReader(self, reader):
- """
- Ignore the reader. This is necessary because the waker will be
- added. However, we won't actually monitor it for any events.
- """
-
-
- def removeAll(self):
- """
- There are no readers or writers, so there is nothing to remove.
- This will be called when the reactor stops, though, so it must be
- implemented.
- """
- return []
-
-
- def seconds(self):
- """
- Override the real clock with a deterministic one that can be easily
- controlled in a unit test.
- """
- return self.now
-
-
- def doIteration(self, timeout):
- d = self.iterationTimeout
- if d is not None:
- self.iterationTimeout = None
- d.callback(timeout)
-
-
-
-class IterationTimeoutTests(TestCase):
- """
- Tests for the timeout argument L{PosixReactorBase.run} calls
- L{PosixReactorBase.doIteration} with in the presence of various delayed
- calls.
- """
- def _checkIterationTimeout(self, reactor):
- timeout = []
- reactor.iterationTimeout.addCallback(timeout.append)
- reactor.iterationTimeout.addCallback(lambda ignored: reactor.stop())
- reactor.run()
- return timeout[0]
-
-
- def test_noCalls(self):
- """
- If there are no delayed calls, C{doIteration} is called with a
- timeout of C{None}.
- """
- reactor = TimeoutReportReactor()
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, None)
-
-
- def test_delayedCall(self):
- """
- If there is a delayed call, C{doIteration} is called with a timeout
- which is the difference between the current time and the time at
- which that call is to run.
- """
- reactor = TimeoutReportReactor()
- reactor.callLater(100, lambda: None)
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, 100)
-
-
- def test_timePasses(self):
- """
- If a delayed call is scheduled and then some time passes, the
- timeout passed to C{doIteration} is reduced by the amount of time
- which passed.
- """
- reactor = TimeoutReportReactor()
- reactor.callLater(100, lambda: None)
- reactor.now += 25
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, 75)
-
-
- def test_multipleDelayedCalls(self):
- """
- If there are several delayed calls, C{doIteration} is called with a
- timeout which is the difference between the current time and the
- time at which the earlier of the two calls is to run.
- """
- reactor = TimeoutReportReactor()
- reactor.callLater(50, lambda: None)
- reactor.callLater(10, lambda: None)
- reactor.callLater(100, lambda: None)
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, 10)
-
-
- def test_resetDelayedCall(self):
- """
- If a delayed call is reset, the timeout passed to C{doIteration} is
- based on the interval between the time when reset is called and the
- new delay of the call.
- """
- reactor = TimeoutReportReactor()
- call = reactor.callLater(50, lambda: None)
- reactor.now += 25
- call.reset(15)
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, 15)
-
-
- def test_delayDelayedCall(self):
- """
- If a delayed call is re-delayed, the timeout passed to
- C{doIteration} is based on the remaining time before the call would
- have been made and the additional amount of time passed to the delay
- method.
- """
- reactor = TimeoutReportReactor()
- call = reactor.callLater(50, lambda: None)
- reactor.now += 10
- call.delay(20)
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, 60)
-
-
- def test_cancelDelayedCall(self):
- """
- If the only delayed call is canceled, C{None} is the timeout passed
- to C{doIteration}.
- """
- reactor = TimeoutReportReactor()
- call = reactor.callLater(50, lambda: None)
- call.cancel()
- timeout = self._checkIterationTimeout(reactor)
- self.assertEqual(timeout, None)
-
-
-
-class ConnectedDatagramPortTestCase(TestCase):
- """
- Test connected datagram UNIX sockets.
- """
- if skipSockets is not None:
- skip = skipSockets
-
-
- def test_connectionFailedDoesntCallLoseConnection(self):
- """
- L{ConnectedDatagramPort} does not call the deprecated C{loseConnection}
- in L{ConnectedDatagramPort.connectionFailed}.
- """
- def loseConnection():
- """
- Dummy C{loseConnection} method. C{loseConnection} is deprecated and
- should not get called.
- """
- self.fail("loseConnection is deprecated and should not get called.")
-
- port = unix.ConnectedDatagramPort(None, ClientProto())
- port.loseConnection = loseConnection
- port.connectionFailed("goodbye")
-
-
- def test_connectionFailedCallsStopListening(self):
- """
- L{ConnectedDatagramPort} calls L{ConnectedDatagramPort.stopListening}
- instead of the deprecated C{loseConnection} in
- L{ConnectedDatagramPort.connectionFailed}.
- """
- self.called = False
-
- def stopListening():
- """
- Dummy C{stopListening} method.
- """
- self.called = True
-
- port = unix.ConnectedDatagramPort(None, ClientProto())
- port.stopListening = stopListening
- port.connectionFailed("goodbye")
- self.assertEqual(self.called, True)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixprocess.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixprocess.py
deleted file mode 100755
index f7abd55b..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_posixprocess.py
+++ /dev/null
@@ -1,340 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for POSIX-based L{IReactorProcess} implementations.
-"""
-
-import errno, os, sys
-
-try:
- import fcntl
-except ImportError:
- platformSkip = "non-POSIX platform"
-else:
- from twisted.internet import process
- platformSkip = None
-
-from twisted.trial.unittest import TestCase
-
-
-class FakeFile(object):
- """
- A dummy file object which records when it is closed.
- """
- def __init__(self, testcase, fd):
- self.testcase = testcase
- self.fd = fd
-
-
- def close(self):
- self.testcase._files.remove(self.fd)
-
-
-
-class FakeResourceModule(object):
- """
- Fake version of L{resource} which hard-codes a particular rlimit for maximum
- open files.
-
- @ivar _limit: The value to return for the hard limit of number of open files.
- """
- RLIMIT_NOFILE = 1
-
- def __init__(self, limit):
- self._limit = limit
-
-
- def getrlimit(self, no):
- """
- A fake of L{resource.getrlimit} which returns a pre-determined result.
- """
- if no == self.RLIMIT_NOFILE:
- return [0, self._limit]
- return [123, 456]
-
-
-
-class FDDetectorTests(TestCase):
- """
- Tests for _FDDetector class in twisted.internet.process, which detects
- which function to drop in place for the _listOpenFDs method.
-
- @ivar devfs: A flag indicating whether the filesystem fake will indicate
- that /dev/fd exists.
-
- @ivar accurateDevFDResults: A flag indicating whether the /dev/fd fake
- returns accurate open file information.
-
- @ivar procfs: A flag indicating whether the filesystem fake will indicate
- that /proc/<pid>/fd exists.
- """
- skip = platformSkip
-
- devfs = False
- accurateDevFDResults = False
-
- procfs = False
-
- def getpid(self):
- """
- Fake os.getpid, always return the same thing
- """
- return 123
-
-
- def listdir(self, arg):
- """
- Fake os.listdir, depending on what mode we're in to simulate behaviour.
-
- @param arg: the directory to list
- """
- accurate = map(str, self._files)
- if self.procfs and arg == ('/proc/%d/fd' % (self.getpid(),)):
- return accurate
- if self.devfs and arg == '/dev/fd':
- if self.accurateDevFDResults:
- return accurate
- return ["0", "1", "2"]
- raise OSError()
-
-
- def openfile(self, fname, mode):
- """
- This is a mock for L{open}. It keeps track of opened files so extra
- descriptors can be returned from the mock for L{os.listdir} when used on
- one of the list-of-filedescriptors directories.
-
- A L{FakeFile} is returned which can be closed to remove the new
- descriptor from the open list.
- """
- # Find the smallest unused file descriptor and give it to the new file.
- f = FakeFile(self, min(set(range(1024)) - set(self._files)))
- self._files.append(f.fd)
- return f
-
-
- def hideResourceModule(self):
- """
- Make the L{resource} module unimportable for the remainder of the
- current test method.
- """
- sys.modules['resource'] = None
-
-
- def revealResourceModule(self, limit):
- """
- Make a L{FakeResourceModule} instance importable at the L{resource}
- name.
-
- @param limit: The value which will be returned for the hard limit of
- number of open files by the fake resource module's C{getrlimit}
- function.
- """
- sys.modules['resource'] = FakeResourceModule(limit)
-
-
- def replaceResourceModule(self, value):
- """
- Restore the original resource module to L{sys.modules}.
- """
- if value is None:
- try:
- del sys.modules['resource']
- except KeyError:
- pass
- else:
- sys.modules['resource'] = value
-
-
- def setUp(self):
- """
- Set up the tests, giving ourselves a detector object to play with and
- setting up its testable knobs to refer to our mocked versions.
- """
- self.detector = process._FDDetector()
- self.detector.listdir = self.listdir
- self.detector.getpid = self.getpid
- self.detector.openfile = self.openfile
- self._files = [0, 1, 2]
- self.addCleanup(
- self.replaceResourceModule, sys.modules.get('resource'))
-
-
- def test_selectFirstWorking(self):
- """
- L{FDDetector._getImplementation} returns the first method from its
- C{_implementations} list which returns results which reflect a newly
- opened file descriptor.
- """
- def failWithException():
- raise ValueError("This does not work")
-
- def failWithWrongResults():
- return [0, 1, 2]
-
- def correct():
- return self._files[:]
-
- self.detector._implementations = [
- failWithException, failWithWrongResults, correct]
-
- self.assertIdentical(correct, self.detector._getImplementation())
-
-
- def test_selectLast(self):
- """
- L{FDDetector._getImplementation} returns the last method from its
- C{_implementations} list if none of the implementations manage to return
- results which reflect a newly opened file descriptor.
- """
- def failWithWrongResults():
- return [3, 5, 9]
-
- def failWithOtherWrongResults():
- return [0, 1, 2]
-
- self.detector._implementations = [
- failWithWrongResults, failWithOtherWrongResults]
-
- self.assertIdentical(
- failWithOtherWrongResults, self.detector._getImplementation())
-
-
- def test_identityOfListOpenFDsChanges(self):
- """
- Check that the identity of _listOpenFDs changes after running
- _listOpenFDs the first time, but not after the second time it's run.
-
- In other words, check that the monkey patching actually works.
- """
- # Create a new instance
- detector = process._FDDetector()
-
- first = detector._listOpenFDs.func_name
- detector._listOpenFDs()
- second = detector._listOpenFDs.func_name
- detector._listOpenFDs()
- third = detector._listOpenFDs.func_name
-
- self.assertNotEqual(first, second)
- self.assertEqual(second, third)
-
-
- def test_devFDImplementation(self):
- """
- L{_FDDetector._devFDImplementation} raises L{OSError} if there is no
- I{/dev/fd} directory, otherwise it returns the basenames of its children
- interpreted as integers.
- """
- self.devfs = False
- self.assertRaises(OSError, self.detector._devFDImplementation)
- self.devfs = True
- self.accurateDevFDResults = False
- self.assertEqual([0, 1, 2], self.detector._devFDImplementation())
-
-
- def test_procFDImplementation(self):
- """
- L{_FDDetector._procFDImplementation} raises L{OSError} if there is no
- I{/proc/<pid>/fd} directory, otherwise it returns the basenames of its
- children interpreted as integers.
- """
- self.procfs = False
- self.assertRaises(OSError, self.detector._procFDImplementation)
- self.procfs = True
- self.assertEqual([0, 1, 2], self.detector._procFDImplementation())
-
-
- def test_resourceFDImplementation(self):
- """
- L{_FDDetector._fallbackFDImplementation} uses the L{resource} module if
- it is available, returning a range of integers from 0 to the the
- minimum of C{1024} and the hard I{NOFILE} limit.
- """
- # When the resource module is here, use its value.
- self.revealResourceModule(512)
- self.assertEqual(
- range(512), self.detector._fallbackFDImplementation())
-
- # But limit its value to the arbitrarily selected value 1024.
- self.revealResourceModule(2048)
- self.assertEqual(
- range(1024), self.detector._fallbackFDImplementation())
-
-
- def test_fallbackFDImplementation(self):
- """
- L{_FDDetector._fallbackFDImplementation}, the implementation of last
- resort, succeeds with a fixed range of integers from 0 to 1024 when the
- L{resource} module is not importable.
- """
- self.hideResourceModule()
- self.assertEqual(range(1024), self.detector._fallbackFDImplementation())
-
-
-
-class FileDescriptorTests(TestCase):
- """
- Tests for L{twisted.internet.process._listOpenFDs}
- """
- skip = platformSkip
-
- def test_openFDs(self):
- """
- File descriptors returned by L{_listOpenFDs} are mostly open.
-
- This test assumes that zero-legth writes fail with EBADF on closed
- file descriptors.
- """
- for fd in process._listOpenFDs():
- try:
- fcntl.fcntl(fd, fcntl.F_GETFL)
- except IOError, err:
- self.assertEqual(
- errno.EBADF, err.errno,
- "fcntl(%d, F_GETFL) failed with unexpected errno %d" % (
- fd, err.errno))
-
-
- def test_expectedFDs(self):
- """
- L{_listOpenFDs} lists expected file descriptors.
- """
- # This is a tricky test. A priori, there is no way to know what file
- # descriptors are open now, so there is no way to know what _listOpenFDs
- # should return. Work around this by creating some new file descriptors
- # which we can know the state of and then just making assertions about
- # their presence or absence in the result.
-
- # Expect a file we just opened to be listed.
- f = file(os.devnull)
- openfds = process._listOpenFDs()
- self.assertIn(f.fileno(), openfds)
-
- # Expect a file we just closed not to be listed - with a caveat. The
- # implementation may need to open a file to discover the result. That
- # open file descriptor will be allocated the same number as the one we
- # just closed. So, instead, create a hole in the file descriptor space
- # to catch that internal descriptor and make the assertion about a
- # different closed file descriptor.
-
- # This gets allocated a file descriptor larger than f's, since nothing
- # has been closed since we opened f.
- fd = os.dup(f.fileno())
-
- # But sanity check that; if it fails the test is invalid.
- self.assertTrue(
- fd > f.fileno(),
- "Expected duplicate file descriptor to be greater than original")
-
- try:
- # Get rid of the original, creating the hole. The copy should still
- # be open, of course.
- f.close()
- self.assertIn(fd, process._listOpenFDs())
- finally:
- # Get rid of the copy now
- os.close(fd)
- # And it should not appear in the result.
- self.assertNotIn(fd, process._listOpenFDs())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_process.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_process.py
deleted file mode 100755
index c56c225a..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_process.py
+++ /dev/null
@@ -1,711 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorProcess}.
-"""
-
-__metaclass__ = type
-
-import os, sys, signal, threading
-
-from twisted.trial.unittest import TestCase, SkipTest
-from twisted.internet.test.reactormixins import ReactorBuilder
-from twisted.python.compat import set
-from twisted.python.log import msg, err
-from twisted.python.runtime import platform
-from twisted.python.filepath import FilePath
-from twisted.internet import utils
-from twisted.internet.interfaces import IReactorProcess, IProcessTransport
-from twisted.internet.defer import Deferred, succeed
-from twisted.internet.protocol import ProcessProtocol
-from twisted.internet.error import ProcessDone, ProcessTerminated
-from twisted.internet import _signals
-
-
-
-class _ShutdownCallbackProcessProtocol(ProcessProtocol):
- """
- An L{IProcessProtocol} which fires a Deferred when the process it is
- associated with ends.
-
- @ivar received: A C{dict} mapping file descriptors to lists of bytes
- received from the child process on those file descriptors.
- """
- def __init__(self, whenFinished):
- self.whenFinished = whenFinished
- self.received = {}
-
-
- def childDataReceived(self, fd, bytes):
- self.received.setdefault(fd, []).append(bytes)
-
-
- def processEnded(self, reason):
- self.whenFinished.callback(None)
-
-
-
-class ProcessTestsBuilderBase(ReactorBuilder):
- """
- Base class for L{IReactorProcess} tests which defines some tests which
- can be applied to PTY or non-PTY uses of C{spawnProcess}.
-
- Subclasses are expected to set the C{usePTY} attribute to C{True} or
- C{False}.
- """
- requiredInterfaces = [IReactorProcess]
-
-
- def test_processTransportInterface(self):
- """
- L{IReactorProcess.spawnProcess} connects the protocol passed to it
- to a transport which provides L{IProcessTransport}.
- """
- ended = Deferred()
- protocol = _ShutdownCallbackProcessProtocol(ended)
-
- reactor = self.buildReactor()
- transport = reactor.spawnProcess(
- protocol, sys.executable, [sys.executable, "-c", ""],
- usePTY=self.usePTY)
-
- # The transport is available synchronously, so we can check it right
- # away (unlike many transport-based tests). This is convenient even
- # though it's probably not how the spawnProcess interface should really
- # work.
- # We're not using verifyObject here because part of
- # IProcessTransport is a lie - there are no getHost or getPeer
- # methods. See #1124.
- self.assertTrue(IProcessTransport.providedBy(transport))
-
- # Let the process run and exit so we don't leave a zombie around.
- ended.addCallback(lambda ignored: reactor.stop())
- self.runReactor(reactor)
-
-
- def _writeTest(self, write):
- """
- Helper for testing L{IProcessTransport} write functionality. This
- method spawns a child process and gives C{write} a chance to write some
- bytes to it. It then verifies that the bytes were actually written to
- it (by relying on the child process to echo them back).
-
- @param write: A two-argument callable. This is invoked with a process
- transport and some bytes to write to it.
- """
- reactor = self.buildReactor()
-
- ended = Deferred()
- protocol = _ShutdownCallbackProcessProtocol(ended)
-
- bytes = "hello, world" + os.linesep
- program = (
- "import sys\n"
- "sys.stdout.write(sys.stdin.readline())\n"
- )
-
- def startup():
- transport = reactor.spawnProcess(
- protocol, sys.executable, [sys.executable, "-c", program])
- try:
- write(transport, bytes)
- except:
- err(None, "Unhandled exception while writing")
- transport.signalProcess('KILL')
- reactor.callWhenRunning(startup)
-
- ended.addCallback(lambda ignored: reactor.stop())
-
- self.runReactor(reactor)
- self.assertEqual(bytes, "".join(protocol.received[1]))
-
-
- def test_write(self):
- """
- L{IProcessTransport.write} writes the specified C{str} to the standard
- input of the child process.
- """
- def write(transport, bytes):
- transport.write(bytes)
- self._writeTest(write)
-
-
- def test_writeSequence(self):
- """
- L{IProcessTransport.writeSequence} writes the specified C{list} of
- C{str} to the standard input of the child process.
- """
- def write(transport, bytes):
- transport.writeSequence(list(bytes))
- self._writeTest(write)
-
-
- def test_writeToChild(self):
- """
- L{IProcessTransport.writeToChild} writes the specified C{str} to the
- specified file descriptor of the child process.
- """
- def write(transport, bytes):
- transport.writeToChild(0, bytes)
- self._writeTest(write)
-
-
- def test_writeToChildBadFileDescriptor(self):
- """
- L{IProcessTransport.writeToChild} raises L{KeyError} if passed a file
- descriptor which is was not set up by L{IReactorProcess.spawnProcess}.
- """
- def write(transport, bytes):
- try:
- self.assertRaises(KeyError, transport.writeToChild, 13, bytes)
- finally:
- # Just get the process to exit so the test can complete
- transport.write(bytes)
- self._writeTest(write)
-
-
- def test_spawnProcessEarlyIsReaped(self):
- """
- If, before the reactor is started with L{IReactorCore.run}, a
- process is started with L{IReactorProcess.spawnProcess} and
- terminates, the process is reaped once the reactor is started.
- """
- reactor = self.buildReactor()
-
- # Create the process with no shared file descriptors, so that there
- # are no other events for the reactor to notice and "cheat" with.
- # We want to be sure it's really dealing with the process exiting,
- # not some associated event.
- if self.usePTY:
- childFDs = None
- else:
- childFDs = {}
-
- # Arrange to notice the SIGCHLD.
- signaled = threading.Event()
- def handler(*args):
- signaled.set()
- signal.signal(signal.SIGCHLD, handler)
-
- # Start a process - before starting the reactor!
- ended = Deferred()
- reactor.spawnProcess(
- _ShutdownCallbackProcessProtocol(ended), sys.executable,
- [sys.executable, "-c", ""], usePTY=self.usePTY, childFDs=childFDs)
-
- # Wait for the SIGCHLD (which might have been delivered before we got
- # here, but that's okay because the signal handler was installed above,
- # before we could have gotten it).
- signaled.wait(120)
- if not signaled.isSet():
- self.fail("Timed out waiting for child process to exit.")
-
- # Capture the processEnded callback.
- result = []
- ended.addCallback(result.append)
-
- if result:
- # The synchronous path through spawnProcess / Process.__init__ /
- # registerReapProcessHandler was encountered. There's no reason to
- # start the reactor, because everything is done already.
- return
-
- # Otherwise, though, start the reactor so it can tell us the process
- # exited.
- ended.addCallback(lambda ignored: reactor.stop())
- self.runReactor(reactor)
-
- # Make sure the reactor stopped because the Deferred fired.
- self.assertTrue(result)
-
- if getattr(signal, 'SIGCHLD', None) is None:
- test_spawnProcessEarlyIsReaped.skip = (
- "Platform lacks SIGCHLD, early-spawnProcess test can't work.")
-
-
- def test_processExitedWithSignal(self):
- """
- The C{reason} argument passed to L{IProcessProtocol.processExited} is a
- L{ProcessTerminated} instance if the child process exits with a signal.
- """
- sigName = 'TERM'
- sigNum = getattr(signal, 'SIG' + sigName)
- exited = Deferred()
- source = (
- "import sys\n"
- # Talk so the parent process knows the process is running. This is
- # necessary because ProcessProtocol.makeConnection may be called
- # before this process is exec'd. It would be unfortunate if we
- # SIGTERM'd the Twisted process while it was on its way to doing
- # the exec.
- "sys.stdout.write('x')\n"
- "sys.stdout.flush()\n"
- "sys.stdin.read()\n")
-
- class Exiter(ProcessProtocol):
- def childDataReceived(self, fd, data):
- msg('childDataReceived(%d, %r)' % (fd, data))
- self.transport.signalProcess(sigName)
-
- def childConnectionLost(self, fd):
- msg('childConnectionLost(%d)' % (fd,))
-
- def processExited(self, reason):
- msg('processExited(%r)' % (reason,))
- # Protect the Deferred from the failure so that it follows
- # the callback chain. This doesn't use the errback chain
- # because it wants to make sure reason is a Failure. An
- # Exception would also make an errback-based test pass, and
- # that would be wrong.
- exited.callback([reason])
-
- def processEnded(self, reason):
- msg('processEnded(%r)' % (reason,))
-
- reactor = self.buildReactor()
- reactor.callWhenRunning(
- reactor.spawnProcess, Exiter(), sys.executable,
- [sys.executable, "-c", source], usePTY=self.usePTY)
-
- def cbExited((failure,)):
- # Trapping implicitly verifies that it's a Failure (rather than
- # an exception) and explicitly makes sure it's the right type.
- failure.trap(ProcessTerminated)
- err = failure.value
- if platform.isWindows():
- # Windows can't really /have/ signals, so it certainly can't
- # report them as the reason for termination. Maybe there's
- # something better we could be doing here, anyway? Hard to
- # say. Anyway, this inconsistency between different platforms
- # is extremely unfortunate and I would remove it if I
- # could. -exarkun
- self.assertIdentical(err.signal, None)
- self.assertEqual(err.exitCode, 1)
- else:
- self.assertEqual(err.signal, sigNum)
- self.assertIdentical(err.exitCode, None)
-
- exited.addCallback(cbExited)
- exited.addErrback(err)
- exited.addCallback(lambda ign: reactor.stop())
-
- self.runReactor(reactor)
-
-
- def test_systemCallUninterruptedByChildExit(self):
- """
- If a child process exits while a system call is in progress, the system
- call should not be interfered with. In particular, it should not fail
- with EINTR.
-
- Older versions of Twisted installed a SIGCHLD handler on POSIX without
- using the feature exposed by the SA_RESTART flag to sigaction(2). The
- most noticable problem this caused was for blocking reads and writes to
- sometimes fail with EINTR.
- """
- reactor = self.buildReactor()
-
- # XXX Since pygobject/pygtk wants to use signal.set_wakeup_fd,
- # we aren't actually providing this functionality on the glib2
- # or gtk2 reactors yet. See #4286 for the possibility of
- # improving this.
- skippedReactors = ["Glib2Reactor", "Gtk2Reactor", "PortableGtkReactor"]
- hasSigInterrupt = getattr(signal, "siginterrupt", None) is not None
- reactorClassName = reactor.__class__.__name__
- if reactorClassName in skippedReactors and not hasSigInterrupt:
- raise SkipTest(
- "%s is not supported without siginterrupt" % reactorClassName)
- if _signals.installHandler.__name__ == "_installHandlerUsingSignal":
- raise SkipTest("_signals._installHandlerUsingSignal doesn't support this feature")
-
- result = []
-
- def f():
- try:
- f1 = os.popen('%s -c "import time; time.sleep(0.1)"' %
- (sys.executable,))
- f2 = os.popen('%s -c "import time; time.sleep(0.5); print \'Foo\'"' %
- (sys.executable,))
- # The read call below will blow up with an EINTR from the
- # SIGCHLD from the first process exiting if we install a
- # SIGCHLD handler without SA_RESTART. (which we used to do)
- result.append(f2.read())
- finally:
- reactor.stop()
-
- reactor.callWhenRunning(f)
- self.runReactor(reactor)
- self.assertEqual(result, ["Foo\n"])
-
-
- def test_openFileDescriptors(self):
- """
- A spawned process has only stdin, stdout and stderr open
- (file descriptor 3 is also reported as open, because of the call to
- 'os.listdir()').
- """
- from twisted.python.runtime import platformType
- if platformType != "posix":
- raise SkipTest("Test only applies to POSIX platforms")
-
- here = FilePath(__file__)
- top = here.parent().parent().parent().parent()
- source = (
- "import sys",
- "sys.path.insert(0, '%s')" % (top.path,),
- "from twisted.internet import process",
- "sys.stdout.write(str(process._listOpenFDs()))",
- "sys.stdout.flush()")
-
- def checkOutput(output):
- self.assertEqual('[0, 1, 2, 3]', output)
-
- reactor = self.buildReactor()
-
- class Protocol(ProcessProtocol):
- def __init__(self):
- self.output = []
-
- def outReceived(self, data):
- self.output.append(data)
-
- def processEnded(self, reason):
- try:
- checkOutput("".join(self.output))
- finally:
- reactor.stop()
-
- proto = Protocol()
- reactor.callWhenRunning(
- reactor.spawnProcess, proto, sys.executable,
- [sys.executable, "-Wignore", "-c", "\n".join(source)],
- usePTY=self.usePTY)
- self.runReactor(reactor)
-
-
- def test_timelyProcessExited(self):
- """
- If a spawned process exits, C{processExited} will be called in a
- timely manner.
- """
- reactor = self.buildReactor()
-
- class ExitingProtocol(ProcessProtocol):
- exited = False
-
- def processExited(protoSelf, reason):
- protoSelf.exited = True
- reactor.stop()
- self.assertEqual(reason.value.exitCode, 0)
-
- protocol = ExitingProtocol()
- reactor.callWhenRunning(
- reactor.spawnProcess, protocol, sys.executable,
- [sys.executable, "-c", "raise SystemExit(0)"],
- usePTY=self.usePTY)
-
- # This will timeout if processExited isn't called:
- self.runReactor(reactor, timeout=30)
- self.assertEqual(protocol.exited, True)
-
-
-
-class ProcessTestsBuilder(ProcessTestsBuilderBase):
- """
- Builder defining tests relating to L{IReactorProcess} for child processes
- which do not have a PTY.
- """
- usePTY = False
-
- keepStdioOpenProgram = FilePath(__file__).sibling('process_helper.py').path
- if platform.isWindows():
- keepStdioOpenArg = "windows"
- else:
- # Just a value that doesn't equal "windows"
- keepStdioOpenArg = ""
-
- # Define this test here because PTY-using processes only have stdin and
- # stdout and the test would need to be different for that to work.
- def test_childConnectionLost(self):
- """
- L{IProcessProtocol.childConnectionLost} is called each time a file
- descriptor associated with a child process is closed.
- """
- connected = Deferred()
- lost = {0: Deferred(), 1: Deferred(), 2: Deferred()}
-
- class Closer(ProcessProtocol):
- def makeConnection(self, transport):
- connected.callback(transport)
-
- def childConnectionLost(self, childFD):
- lost[childFD].callback(None)
-
- source = (
- "import os, sys\n"
- "while 1:\n"
- " line = sys.stdin.readline().strip()\n"
- " if not line:\n"
- " break\n"
- " os.close(int(line))\n")
-
- reactor = self.buildReactor()
- reactor.callWhenRunning(
- reactor.spawnProcess, Closer(), sys.executable,
- [sys.executable, "-c", source], usePTY=self.usePTY)
-
- def cbConnected(transport):
- transport.write('2\n')
- return lost[2].addCallback(lambda ign: transport)
- connected.addCallback(cbConnected)
-
- def lostSecond(transport):
- transport.write('1\n')
- return lost[1].addCallback(lambda ign: transport)
- connected.addCallback(lostSecond)
-
- def lostFirst(transport):
- transport.write('\n')
- connected.addCallback(lostFirst)
- connected.addErrback(err)
-
- def cbEnded(ignored):
- reactor.stop()
- connected.addCallback(cbEnded)
-
- self.runReactor(reactor)
-
-
- # This test is here because PTYProcess never delivers childConnectionLost.
- def test_processEnded(self):
- """
- L{IProcessProtocol.processEnded} is called after the child process
- exits and L{IProcessProtocol.childConnectionLost} is called for each of
- its file descriptors.
- """
- ended = Deferred()
- lost = []
-
- class Ender(ProcessProtocol):
- def childDataReceived(self, fd, data):
- msg('childDataReceived(%d, %r)' % (fd, data))
- self.transport.loseConnection()
-
- def childConnectionLost(self, childFD):
- msg('childConnectionLost(%d)' % (childFD,))
- lost.append(childFD)
-
- def processExited(self, reason):
- msg('processExited(%r)' % (reason,))
-
- def processEnded(self, reason):
- msg('processEnded(%r)' % (reason,))
- ended.callback([reason])
-
- reactor = self.buildReactor()
- reactor.callWhenRunning(
- reactor.spawnProcess, Ender(), sys.executable,
- [sys.executable, self.keepStdioOpenProgram, "child",
- self.keepStdioOpenArg],
- usePTY=self.usePTY)
-
- def cbEnded((failure,)):
- failure.trap(ProcessDone)
- self.assertEqual(set(lost), set([0, 1, 2]))
- ended.addCallback(cbEnded)
-
- ended.addErrback(err)
- ended.addCallback(lambda ign: reactor.stop())
-
- self.runReactor(reactor)
-
-
- # This test is here because PTYProcess.loseConnection does not actually
- # close the file descriptors to the child process. This test needs to be
- # written fairly differently for PTYProcess.
- def test_processExited(self):
- """
- L{IProcessProtocol.processExited} is called when the child process
- exits, even if file descriptors associated with the child are still
- open.
- """
- exited = Deferred()
- allLost = Deferred()
- lost = []
-
- class Waiter(ProcessProtocol):
- def childDataReceived(self, fd, data):
- msg('childDataReceived(%d, %r)' % (fd, data))
-
- def childConnectionLost(self, childFD):
- msg('childConnectionLost(%d)' % (childFD,))
- lost.append(childFD)
- if len(lost) == 3:
- allLost.callback(None)
-
- def processExited(self, reason):
- msg('processExited(%r)' % (reason,))
- # See test_processExitedWithSignal
- exited.callback([reason])
- self.transport.loseConnection()
-
- reactor = self.buildReactor()
- reactor.callWhenRunning(
- reactor.spawnProcess, Waiter(), sys.executable,
- [sys.executable, self.keepStdioOpenProgram, "child",
- self.keepStdioOpenArg],
- usePTY=self.usePTY)
-
- def cbExited((failure,)):
- failure.trap(ProcessDone)
- msg('cbExited; lost = %s' % (lost,))
- self.assertEqual(lost, [])
- return allLost
- exited.addCallback(cbExited)
-
- def cbAllLost(ignored):
- self.assertEqual(set(lost), set([0, 1, 2]))
- exited.addCallback(cbAllLost)
-
- exited.addErrback(err)
- exited.addCallback(lambda ign: reactor.stop())
-
- self.runReactor(reactor)
-
-
- def makeSourceFile(self, sourceLines):
- """
- Write the given list of lines to a text file and return the absolute
- path to it.
- """
- script = self.mktemp()
- scriptFile = file(script, 'wt')
- scriptFile.write(os.linesep.join(sourceLines) + os.linesep)
- scriptFile.close()
- return os.path.abspath(script)
-
-
- def test_shebang(self):
- """
- Spawning a process with an executable which is a script starting
- with an interpreter definition line (#!) uses that interpreter to
- evaluate the script.
- """
- SHEBANG_OUTPUT = 'this is the shebang output'
-
- scriptFile = self.makeSourceFile([
- "#!%s" % (sys.executable,),
- "import sys",
- "sys.stdout.write('%s')" % (SHEBANG_OUTPUT,),
- "sys.stdout.flush()"])
- os.chmod(scriptFile, 0700)
-
- reactor = self.buildReactor()
-
- def cbProcessExited((out, err, code)):
- msg("cbProcessExited((%r, %r, %d))" % (out, err, code))
- self.assertEqual(out, SHEBANG_OUTPUT)
- self.assertEqual(err, "")
- self.assertEqual(code, 0)
-
- def shutdown(passthrough):
- reactor.stop()
- return passthrough
-
- def start():
- d = utils.getProcessOutputAndValue(scriptFile, reactor=reactor)
- d.addBoth(shutdown)
- d.addCallback(cbProcessExited)
- d.addErrback(err)
-
- reactor.callWhenRunning(start)
- self.runReactor(reactor)
-
-
- def test_processCommandLineArguments(self):
- """
- Arguments given to spawnProcess are passed to the child process as
- originally intended.
- """
- source = (
- # On Windows, stdout is not opened in binary mode by default,
- # so newline characters are munged on writing, interfering with
- # the tests.
- 'import sys, os\n'
- 'try:\n'
- ' import msvcrt\n'
- ' msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)\n'
- 'except ImportError:\n'
- ' pass\n'
- 'for arg in sys.argv[1:]:\n'
- ' sys.stdout.write(arg + chr(0))\n'
- ' sys.stdout.flush()')
-
- args = ['hello', '"', ' \t|<>^&', r'"\\"hello\\"', r'"foo\ bar baz\""']
- # Ensure that all non-NUL characters can be passed too.
- args.append(''.join(map(chr, xrange(1, 256))))
-
- reactor = self.buildReactor()
-
- def processFinished(output):
- output = output.split('\0')
- # Drop the trailing \0.
- output.pop()
- self.assertEqual(args, output)
-
- def shutdown(result):
- reactor.stop()
- return result
-
- def spawnChild():
- d = succeed(None)
- d.addCallback(lambda dummy: utils.getProcessOutput(
- sys.executable, ['-c', source] + args, reactor=reactor))
- d.addCallback(processFinished)
- d.addBoth(shutdown)
-
- reactor.callWhenRunning(spawnChild)
- self.runReactor(reactor)
-globals().update(ProcessTestsBuilder.makeTestCaseClasses())
-
-
-
-class PTYProcessTestsBuilder(ProcessTestsBuilderBase):
- """
- Builder defining tests relating to L{IReactorProcess} for child processes
- which have a PTY.
- """
- usePTY = True
-
- if platform.isWindows():
- skip = "PTYs are not supported on Windows."
- elif platform.isMacOSX():
- skippedReactors = {
- "twisted.internet.pollreactor.PollReactor":
- "OS X's poll() does not support PTYs"}
-globals().update(PTYProcessTestsBuilder.makeTestCaseClasses())
-
-
-
-class PotentialZombieWarningTests(TestCase):
- """
- Tests for L{twisted.internet.error.PotentialZombieWarning}.
- """
- def test_deprecated(self):
- """
- Accessing L{PotentialZombieWarning} via the
- I{PotentialZombieWarning} attribute of L{twisted.internet.error}
- results in a deprecation warning being emitted.
- """
- from twisted.internet import error
- error.PotentialZombieWarning
-
- warnings = self.flushWarnings([self.test_deprecated])
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(
- warnings[0]['message'],
- "twisted.internet.error.PotentialZombieWarning was deprecated in "
- "Twisted 10.0.0: There is no longer any potential for zombie "
- "process.")
- self.assertEqual(len(warnings), 1)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_protocol.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_protocol.py
deleted file mode 100755
index 18ef114c..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_protocol.py
+++ /dev/null
@@ -1,357 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.protocol}.
-"""
-
-from zope.interface.verify import verifyObject
-
-from twisted.python.failure import Failure
-from twisted.internet.interfaces import IProtocol, ILoggingContext
-from twisted.internet.defer import CancelledError
-from twisted.internet.protocol import Protocol, ClientCreator
-from twisted.internet.task import Clock
-from twisted.trial.unittest import TestCase
-from twisted.test.proto_helpers import MemoryReactor, StringTransport
-
-
-
-class MemoryConnector:
- _disconnected = False
-
- def disconnect(self):
- self._disconnected = True
-
-
-
-class MemoryReactorWithConnectorsAndTime(MemoryReactor, Clock):
- """
- An extension of L{MemoryReactor} which returns L{IConnector}
- providers from its C{connectTCP} method.
- """
- def __init__(self):
- MemoryReactor.__init__(self)
- Clock.__init__(self)
- self.connectors = []
-
-
- def connectTCP(self, *a, **kw):
- MemoryReactor.connectTCP(self, *a, **kw)
- connector = MemoryConnector()
- self.connectors.append(connector)
- return connector
-
-
- def connectUNIX(self, *a, **kw):
- MemoryReactor.connectUNIX(self, *a, **kw)
- connector = MemoryConnector()
- self.connectors.append(connector)
- return connector
-
-
- def connectSSL(self, *a, **kw):
- MemoryReactor.connectSSL(self, *a, **kw)
- connector = MemoryConnector()
- self.connectors.append(connector)
- return connector
-
-
-
-class ClientCreatorTests(TestCase):
- """
- Tests for L{twisted.internet.protocol.ClientCreator}.
- """
- def _basicConnectTest(self, check):
- """
- Helper for implementing a test to verify that one of the I{connect}
- methods of L{ClientCreator} passes the right arguments to the right
- reactor method.
-
- @param check: A function which will be invoked with a reactor and a
- L{ClientCreator} instance and which should call one of the
- L{ClientCreator}'s I{connect} methods and assert that all of its
- arguments except for the factory are passed on as expected to the
- reactor. The factory should be returned.
- """
- class SomeProtocol(Protocol):
- pass
-
- reactor = MemoryReactorWithConnectorsAndTime()
- cc = ClientCreator(reactor, SomeProtocol)
- factory = check(reactor, cc)
- protocol = factory.buildProtocol(None)
- self.assertIsInstance(protocol, SomeProtocol)
-
-
- def test_connectTCP(self):
- """
- L{ClientCreator.connectTCP} calls C{reactor.connectTCP} with the host
- and port information passed to it, and with a factory which will
- construct the protocol passed to L{ClientCreator.__init__}.
- """
- def check(reactor, cc):
- cc.connectTCP('example.com', 1234, 4321, ('1.2.3.4', 9876))
- host, port, factory, timeout, bindAddress = reactor.tcpClients.pop()
- self.assertEqual(host, 'example.com')
- self.assertEqual(port, 1234)
- self.assertEqual(timeout, 4321)
- self.assertEqual(bindAddress, ('1.2.3.4', 9876))
- return factory
- self._basicConnectTest(check)
-
-
- def test_connectUNIX(self):
- """
- L{ClientCreator.connectUNIX} calls C{reactor.connectUNIX} with the
- filename passed to it, and with a factory which will construct the
- protocol passed to L{ClientCreator.__init__}.
- """
- def check(reactor, cc):
- cc.connectUNIX('/foo/bar', 123, True)
- address, factory, timeout, checkPID = reactor.unixClients.pop()
- self.assertEqual(address, '/foo/bar')
- self.assertEqual(timeout, 123)
- self.assertEqual(checkPID, True)
- return factory
- self._basicConnectTest(check)
-
-
- def test_connectSSL(self):
- """
- L{ClientCreator.connectSSL} calls C{reactor.connectSSL} with the host,
- port, and context factory passed to it, and with a factory which will
- construct the protocol passed to L{ClientCreator.__init__}.
- """
- def check(reactor, cc):
- expectedContextFactory = object()
- cc.connectSSL('example.com', 1234, expectedContextFactory, 4321, ('4.3.2.1', 5678))
- host, port, factory, contextFactory, timeout, bindAddress = reactor.sslClients.pop()
- self.assertEqual(host, 'example.com')
- self.assertEqual(port, 1234)
- self.assertIdentical(contextFactory, expectedContextFactory)
- self.assertEqual(timeout, 4321)
- self.assertEqual(bindAddress, ('4.3.2.1', 5678))
- return factory
- self._basicConnectTest(check)
-
-
- def _cancelConnectTest(self, connect):
- """
- Helper for implementing a test to verify that cancellation of the
- L{Deferred} returned by one of L{ClientCreator}'s I{connect} methods is
- implemented to cancel the underlying connector.
-
- @param connect: A function which will be invoked with a L{ClientCreator}
- instance as an argument and which should call one its I{connect}
- methods and return the result.
-
- @return: A L{Deferred} which fires when the test is complete or fails if
- there is a problem.
- """
- reactor = MemoryReactorWithConnectorsAndTime()
- cc = ClientCreator(reactor, Protocol)
- d = connect(cc)
- connector = reactor.connectors.pop()
- self.assertFalse(connector._disconnected)
- d.cancel()
- self.assertTrue(connector._disconnected)
- return self.assertFailure(d, CancelledError)
-
-
- def test_cancelConnectTCP(self):
- """
- The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
- to abort the connection attempt before it completes.
- """
- def connect(cc):
- return cc.connectTCP('example.com', 1234)
- return self._cancelConnectTest(connect)
-
-
- def test_cancelConnectUNIX(self):
- """
- The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
- to abort the connection attempt before it completes.
- """
- def connect(cc):
- return cc.connectUNIX('/foo/bar')
- return self._cancelConnectTest(connect)
-
-
- def test_cancelConnectSSL(self):
- """
- The L{Deferred} returned by L{ClientCreator.connectTCP} can be cancelled
- to abort the connection attempt before it completes.
- """
- def connect(cc):
- return cc.connectSSL('example.com', 1234, object())
- return self._cancelConnectTest(connect)
-
-
- def _cancelConnectTimeoutTest(self, connect):
- """
- Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
- cancelled after the connection is set up but before it is fired with the
- resulting protocol instance.
- """
- reactor = MemoryReactorWithConnectorsAndTime()
- cc = ClientCreator(reactor, Protocol)
- d = connect(reactor, cc)
- connector = reactor.connectors.pop()
- # Sanity check - there is an outstanding delayed call to fire the
- # Deferred.
- self.assertEqual(len(reactor.getDelayedCalls()), 1)
-
- # Cancel the Deferred, disconnecting the transport just set up and
- # cancelling the delayed call.
- d.cancel()
-
- self.assertEqual(reactor.getDelayedCalls(), [])
-
- # A real connector implementation is responsible for disconnecting the
- # transport as well. For our purposes, just check that someone told the
- # connector to disconnect.
- self.assertTrue(connector._disconnected)
-
- return self.assertFailure(d, CancelledError)
-
-
- def test_cancelConnectTCPTimeout(self):
- """
- L{ClientCreator.connectTCP} inserts a very short delayed call between
- the time the connection is established and the time the L{Deferred}
- returned from one of its connect methods actually fires. If the
- L{Deferred} is cancelled in this interval, the established connection is
- closed, the timeout is cancelled, and the L{Deferred} fails with
- L{CancelledError}.
- """
- def connect(reactor, cc):
- d = cc.connectTCP('example.com', 1234)
- host, port, factory, timeout, bindAddress = reactor.tcpClients.pop()
- protocol = factory.buildProtocol(None)
- transport = StringTransport()
- protocol.makeConnection(transport)
- return d
- return self._cancelConnectTimeoutTest(connect)
-
-
- def test_cancelConnectUNIXTimeout(self):
- """
- L{ClientCreator.connectUNIX} inserts a very short delayed call between
- the time the connection is established and the time the L{Deferred}
- returned from one of its connect methods actually fires. If the
- L{Deferred} is cancelled in this interval, the established connection is
- closed, the timeout is cancelled, and the L{Deferred} fails with
- L{CancelledError}.
- """
- def connect(reactor, cc):
- d = cc.connectUNIX('/foo/bar')
- address, factory, timeout, bindAddress = reactor.unixClients.pop()
- protocol = factory.buildProtocol(None)
- transport = StringTransport()
- protocol.makeConnection(transport)
- return d
- return self._cancelConnectTimeoutTest(connect)
-
-
- def test_cancelConnectSSLTimeout(self):
- """
- L{ClientCreator.connectSSL} inserts a very short delayed call between
- the time the connection is established and the time the L{Deferred}
- returned from one of its connect methods actually fires. If the
- L{Deferred} is cancelled in this interval, the established connection is
- closed, the timeout is cancelled, and the L{Deferred} fails with
- L{CancelledError}.
- """
- def connect(reactor, cc):
- d = cc.connectSSL('example.com', 1234, object())
- host, port, factory, contextFactory, timeout, bindADdress = reactor.sslClients.pop()
- protocol = factory.buildProtocol(None)
- transport = StringTransport()
- protocol.makeConnection(transport)
- return d
- return self._cancelConnectTimeoutTest(connect)
-
-
- def _cancelConnectFailedTimeoutTest(self, connect):
- """
- Like L{_cancelConnectTest}, but for the case where the L{Deferred} is
- cancelled after the connection attempt has failed but before it is fired
- with the resulting failure.
- """
- reactor = MemoryReactorWithConnectorsAndTime()
- cc = ClientCreator(reactor, Protocol)
- d, factory = connect(reactor, cc)
- connector = reactor.connectors.pop()
- factory.clientConnectionFailed(
- connector, Failure(Exception("Simulated failure")))
-
- # Sanity check - there is an outstanding delayed call to fire the
- # Deferred.
- self.assertEqual(len(reactor.getDelayedCalls()), 1)
-
- # Cancel the Deferred, cancelling the delayed call.
- d.cancel()
-
- self.assertEqual(reactor.getDelayedCalls(), [])
-
- return self.assertFailure(d, CancelledError)
-
-
- def test_cancelConnectTCPFailedTimeout(self):
- """
- Similar to L{test_cancelConnectTCPTimeout}, but for the case where the
- connection attempt fails.
- """
- def connect(reactor, cc):
- d = cc.connectTCP('example.com', 1234)
- host, port, factory, timeout, bindAddress = reactor.tcpClients.pop()
- return d, factory
- return self._cancelConnectFailedTimeoutTest(connect)
-
-
- def test_cancelConnectUNIXFailedTimeout(self):
- """
- Similar to L{test_cancelConnectUNIXTimeout}, but for the case where the
- connection attempt fails.
- """
- def connect(reactor, cc):
- d = cc.connectUNIX('/foo/bar')
- address, factory, timeout, bindAddress = reactor.unixClients.pop()
- return d, factory
- return self._cancelConnectFailedTimeoutTest(connect)
-
-
- def test_cancelConnectSSLFailedTimeout(self):
- """
- Similar to L{test_cancelConnectSSLTimeout}, but for the case where the
- connection attempt fails.
- """
- def connect(reactor, cc):
- d = cc.connectSSL('example.com', 1234, object())
- host, port, factory, contextFactory, timeout, bindADdress = reactor.sslClients.pop()
- return d, factory
- return self._cancelConnectFailedTimeoutTest(connect)
-
-
-class ProtocolTests(TestCase):
- """
- Tests for L{twisted.internet.protocol.Protocol}.
- """
- def test_interfaces(self):
- """
- L{Protocol} instances provide L{IProtocol} and L{ILoggingContext}.
- """
- proto = Protocol()
- self.assertTrue(verifyObject(IProtocol, proto))
- self.assertTrue(verifyObject(ILoggingContext, proto))
-
-
- def test_logPrefix(self):
- """
- L{Protocol.logPrefix} returns the protocol class's name.
- """
- class SomeThing(Protocol):
- pass
- self.assertEqual("SomeThing", SomeThing().logPrefix())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_qtreactor.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_qtreactor.py
deleted file mode 100755
index e87b74fd..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_qtreactor.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-import sys
-
-from twisted.trial import unittest
-from twisted.python.runtime import platform
-from twisted.python.util import sibpath
-from twisted.internet.utils import getProcessOutputAndValue
-
-
-skipWindowsNopywin32 = None
-if platform.isWindows():
- try:
- import win32process
- except ImportError:
- skipWindowsNopywin32 = ("On windows, spawnProcess is not available "
- "in the absence of win32process.")
-
-class QtreactorTestCase(unittest.TestCase):
- """
- Tests for L{twisted.internet.qtreactor}.
- """
- def test_importQtreactor(self):
- """
- Attempting to import L{twisted.internet.qtreactor} should raise an
- C{ImportError} indicating that C{qtreactor} is no longer a part of
- Twisted.
- """
- sys.modules["qtreactor"] = None
- from twisted.plugins.twisted_qtstub import errorMessage
- try:
- import twisted.internet.qtreactor
- except ImportError, e:
- self.assertEqual(str(e), errorMessage)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_serialport.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_serialport.py
deleted file mode 100755
index 85b3f3a6..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_serialport.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.serialport}.
-"""
-
-from twisted.trial import unittest
-from twisted.python.failure import Failure
-from twisted.internet.protocol import Protocol
-from twisted.internet.error import ConnectionDone
-try:
- from twisted.internet import serialport
-except ImportError:
- serialport = None
-
-
-
-class DoNothing(object):
- """
- Object with methods that do nothing.
- """
-
- def __init__(self, *args, **kwargs):
- pass
-
-
- def __getattr__(self, attr):
- return lambda *args, **kwargs: None
-
-
-
-class SerialPortTests(unittest.TestCase):
- """
- Minimal testing for Twisted's serial port support.
-
- See ticket #2462 for the eventual full test suite.
- """
-
- if serialport is None:
- skip = "Serial port support is not available."
-
-
- def test_connectionMadeLost(self):
- """
- C{connectionMade} and C{connectionLost} are called on the protocol by
- the C{SerialPort}.
- """
- # Serial port that doesn't actually connect to anything:
- class DummySerialPort(serialport.SerialPort):
- _serialFactory = DoNothing
-
- def _finishPortSetup(self):
- pass # override default win32 actions
-
- events = []
-
- class SerialProtocol(Protocol):
- def connectionMade(self):
- events.append("connectionMade")
-
- def connectionLost(self, reason):
- events.append(("connectionLost", reason))
-
- # Creation of port should result in connectionMade call:
- port = DummySerialPort(SerialProtocol(), "", reactor=DoNothing())
- self.assertEqual(events, ["connectionMade"])
-
- # Simulate reactor calling connectionLost on the SerialPort:
- f = Failure(ConnectionDone())
- port.connectionLost(f)
- self.assertEqual(events, ["connectionMade", ("connectionLost", f)])
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_sigchld.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_sigchld.py
deleted file mode 100755
index 86a711a5..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_sigchld.py
+++ /dev/null
@@ -1,194 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet._sigchld}, an alternate, superior SIGCHLD
-monitoring API.
-"""
-
-import os, signal, errno
-
-from twisted.python.log import msg
-from twisted.trial.unittest import TestCase
-from twisted.internet.fdesc import setNonBlocking
-from twisted.internet._signals import installHandler, isDefaultHandler
-from twisted.internet._signals import _extInstallHandler, _extIsDefaultHandler
-from twisted.internet._signals import _installHandlerUsingSetWakeup, \
- _installHandlerUsingSignal, _isDefaultHandler
-
-
-class SIGCHLDTestsMixin:
- """
- Mixin for L{TestCase} subclasses which defines several tests for
- I{installHandler} and I{isDefaultHandler}. Subclasses are expected to
- define C{self.installHandler} and C{self.isDefaultHandler} to invoke the
- implementation to be tested.
- """
-
- if getattr(signal, 'SIGCHLD', None) is None:
- skip = "Platform does not have SIGCHLD"
-
- def installHandler(self, fd):
- """
- Override in a subclass to install a SIGCHLD handler which writes a byte
- to the given file descriptor. Return the previously registered file
- descriptor.
- """
- raise NotImplementedError()
-
-
- def isDefaultHandler(self):
- """
- Override in a subclass to determine if the current SIGCHLD handler is
- SIG_DFL or not. Return True if it is SIG_DFL, False otherwise.
- """
- raise NotImplementedError()
-
-
- def pipe(self):
- """
- Create a non-blocking pipe which will be closed after the currently
- running test.
- """
- read, write = os.pipe()
- self.addCleanup(os.close, read)
- self.addCleanup(os.close, write)
- setNonBlocking(read)
- setNonBlocking(write)
- return read, write
-
-
- def setUp(self):
- """
- Save the current SIGCHLD handler as reported by L{signal.signal} and
- the current file descriptor registered with L{installHandler}.
- """
- handler = signal.getsignal(signal.SIGCHLD)
- if handler != signal.SIG_DFL:
- self.signalModuleHandler = handler
- signal.signal(signal.SIGCHLD, signal.SIG_DFL)
- else:
- self.signalModuleHandler = None
-
- self.oldFD = self.installHandler(-1)
-
- if self.signalModuleHandler is not None and self.oldFD != -1:
- msg("SIGCHLD setup issue: %r %r" % (self.signalModuleHandler, self.oldFD))
- raise RuntimeError("You used some signal APIs wrong! Try again.")
-
-
- def tearDown(self):
- """
- Restore whatever signal handler was present when setUp ran.
- """
- # If tests set up any kind of handlers, clear them out.
- self.installHandler(-1)
- signal.signal(signal.SIGCHLD, signal.SIG_DFL)
-
- # Now restore whatever the setup was before the test ran.
- if self.signalModuleHandler is not None:
- signal.signal(signal.SIGCHLD, self.signalModuleHandler)
- elif self.oldFD != -1:
- self.installHandler(self.oldFD)
-
-
- def test_isDefaultHandler(self):
- """
- L{isDefaultHandler} returns true if the SIGCHLD handler is SIG_DFL,
- false otherwise.
- """
- self.assertTrue(self.isDefaultHandler())
- signal.signal(signal.SIGCHLD, signal.SIG_IGN)
- self.assertFalse(self.isDefaultHandler())
- signal.signal(signal.SIGCHLD, signal.SIG_DFL)
- self.assertTrue(self.isDefaultHandler())
- signal.signal(signal.SIGCHLD, lambda *args: None)
- self.assertFalse(self.isDefaultHandler())
-
-
- def test_returnOldFD(self):
- """
- L{installHandler} returns the previously registered file descriptor.
- """
- read, write = self.pipe()
- oldFD = self.installHandler(write)
- self.assertEqual(self.installHandler(oldFD), write)
-
-
- def test_uninstallHandler(self):
- """
- C{installHandler(-1)} removes the SIGCHLD handler completely.
- """
- read, write = self.pipe()
- self.assertTrue(self.isDefaultHandler())
- self.installHandler(write)
- self.assertFalse(self.isDefaultHandler())
- self.installHandler(-1)
- self.assertTrue(self.isDefaultHandler())
-
-
- def test_installHandler(self):
- """
- The file descriptor passed to L{installHandler} has a byte written to
- it when SIGCHLD is delivered to the process.
- """
- read, write = self.pipe()
- self.installHandler(write)
-
- exc = self.assertRaises(OSError, os.read, read, 1)
- self.assertEqual(exc.errno, errno.EAGAIN)
-
- os.kill(os.getpid(), signal.SIGCHLD)
-
- self.assertEqual(len(os.read(read, 5)), 1)
-
-
-
-class DefaultSIGCHLDTests(SIGCHLDTestsMixin, TestCase):
- """
- Tests for whatever implementation is selected for the L{installHandler}
- and L{isDefaultHandler} APIs.
- """
- installHandler = staticmethod(installHandler)
- isDefaultHandler = staticmethod(isDefaultHandler)
-
-
-
-class ExtensionSIGCHLDTests(SIGCHLDTestsMixin, TestCase):
- """
- Tests for the L{twisted.internet._sigchld} implementation of the
- L{installHandler} and L{isDefaultHandler} APIs.
- """
- try:
- import twisted.internet._sigchld
- except ImportError:
- skip = "twisted.internet._sigchld is not available"
-
- installHandler = _extInstallHandler
- isDefaultHandler = _extIsDefaultHandler
-
-
-
-class SetWakeupSIGCHLDTests(SIGCHLDTestsMixin, TestCase):
- """
- Tests for the L{signal.set_wakeup_fd} implementation of the
- L{installHandler} and L{isDefaultHandler} APIs.
- """
- # Check both of these. On Ubuntu 9.10 (to take an example completely at
- # random), Python 2.5 has set_wakeup_fd but not siginterrupt.
- if (getattr(signal, 'set_wakeup_fd', None) is None
- or getattr(signal, 'siginterrupt', None) is None):
- skip = "signal.set_wakeup_fd is not available"
-
- installHandler = staticmethod(_installHandlerUsingSetWakeup)
- isDefaultHandler = staticmethod(_isDefaultHandler)
-
-
-
-class PlainSignalModuleSIGCHLDTests(SIGCHLDTestsMixin, TestCase):
- """
- Tests for the L{signal.signal} implementation of the L{installHandler}
- and L{isDefaultHandler} APIs.
- """
- installHandler = staticmethod(_installHandlerUsingSignal)
- isDefaultHandler = staticmethod(_isDefaultHandler)
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_socket.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_socket.py
deleted file mode 100755
index b31eb914..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_socket.py
+++ /dev/null
@@ -1,128 +0,0 @@
-
-import errno, socket
-
-from twisted.python.log import err
-from twisted.internet.interfaces import IReactorSocket
-from twisted.internet.error import UnsupportedAddressFamily
-from twisted.internet.protocol import ServerFactory
-from twisted.internet.test.reactormixins import (
- ReactorBuilder, needsRunningReactor)
-
-
-class AdoptStreamPortErrorsTestsBuilder(ReactorBuilder):
- """
- Builder for testing L{IReactorSocket.adoptStreamPort} implementations.
-
- Generally only tests for failure cases are found here. Success cases for
- this interface are tested elsewhere. For example, the success case for
- I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should
- behave exactly the same as L{IReactorTCP.listenTCP}.
- """
- requiredInterfaces = [IReactorSocket]
-
- def test_invalidDescriptor(self):
- """
- An implementation of L{IReactorSocket.adoptStreamPort} raises
- L{socket.error} if passed an integer which is not associated with a
- socket.
- """
- reactor = self.buildReactor()
-
- probe = socket.socket()
- fileno = probe.fileno()
- probe.close()
-
- exc = self.assertRaises(
- socket.error,
- reactor.adoptStreamPort, fileno, socket.AF_INET, ServerFactory())
- self.assertEqual(exc.args[0], errno.EBADF)
-
-
- def test_invalidAddressFamily(self):
- """
- An implementation of L{IReactorSocket.adoptStreamPort} raises
- L{UnsupportedAddressFamily} if passed an address family it does not
- support.
- """
- reactor = self.buildReactor()
-
- port = socket.socket()
- port.listen(1)
- self.addCleanup(port.close)
-
- arbitrary = 2 ** 16 + 7
-
- self.assertRaises(
- UnsupportedAddressFamily,
- reactor.adoptStreamPort, port.fileno(), arbitrary, ServerFactory())
-
-
- def test_stopOnlyCloses(self):
- """
- When the L{IListeningPort} returned by L{IReactorSocket.adoptStreamPort}
- is stopped using C{stopListening}, the underlying socket is closed but
- not shutdown. This allows another process which still has a reference
- to it to continue accepting connections over it.
- """
- reactor = self.buildReactor()
-
- portSocket = socket.socket()
- self.addCleanup(portSocket.close)
-
- portSocket.listen(1)
- portSocket.setblocking(False)
-
- # The file descriptor is duplicated by adoptStreamPort
- port = reactor.adoptStreamPort(
- portSocket.fileno(), portSocket.family, ServerFactory())
- d = port.stopListening()
- def stopped(ignored):
- # Should still be possible to accept a connection on portSocket. If
- # it was shutdown, the exception would be EINVAL instead.
- exc = self.assertRaises(socket.error, portSocket.accept)
- self.assertEqual(exc.args[0], errno.EAGAIN)
- d.addCallback(stopped)
- d.addErrback(err, "Failed to accept on original port.")
-
- needsRunningReactor(
- reactor,
- lambda: d.addCallback(lambda ignored: reactor.stop()))
-
- reactor.run()
-
-
-
-class AdoptStreamConnectionErrorsTestsBuilder(ReactorBuilder):
- """
- Builder for testing L{IReactorSocket.adoptStreamConnection}
- implementations.
-
- Generally only tests for failure cases are found here. Success cases for
- this interface are tested elsewhere. For example, the success case for
- I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should
- behave exactly the same as L{IReactorTCP.listenTCP}.
- """
- requiredInterfaces = [IReactorSocket]
-
- def test_invalidAddressFamily(self):
- """
- An implementation of L{IReactorSocket.adoptStreamConnection} raises
- L{UnsupportedAddressFamily} if passed an address family it does not
- support.
- """
- reactor = self.buildReactor()
-
- connection = socket.socket()
- self.addCleanup(connection.close)
-
- arbitrary = 2 ** 16 + 7
-
- self.assertRaises(
- UnsupportedAddressFamily,
- reactor.adoptStreamConnection, connection.fileno(), arbitrary,
- ServerFactory())
-
-
-
-globals().update(AdoptStreamPortErrorsTestsBuilder.makeTestCaseClasses())
-globals().update(AdoptStreamConnectionErrorsTestsBuilder.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_stdio.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_stdio.py
deleted file mode 100755
index 4163e414..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_stdio.py
+++ /dev/null
@@ -1,195 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for L{twisted.internet.stdio}.
-"""
-
-from twisted.python.runtime import platform
-from twisted.internet.test.reactormixins import ReactorBuilder
-from twisted.internet.protocol import Protocol
-if not platform.isWindows():
- from twisted.internet._posixstdio import StandardIO
-
-
-
-class StdioFilesTests(ReactorBuilder):
- """
- L{StandardIO} supports reading and writing to filesystem files.
- """
-
- def setUp(self):
- path = self.mktemp()
- file(path, "w").close()
- self.extraFile = file(path, "r+")
-
-
- def test_addReader(self):
- """
- Adding a filesystem file reader to a reactor will make sure it is
- polled.
- """
- reactor = self.buildReactor()
-
- class DataProtocol(Protocol):
- data = ""
- def dataReceived(self, data):
- self.data += data
- # It'd be better to stop reactor on connectionLost, but that
- # fails on FreeBSD, probably due to
- # http://bugs.python.org/issue9591:
- if self.data == "hello!":
- reactor.stop()
-
- path = self.mktemp()
- f = file(path, "w")
- f.write("hello!")
- f.close()
- f = file(path, "r")
-
- # Read bytes from a file, deliver them to a protocol instance:
- protocol = DataProtocol()
- StandardIO(protocol, stdin=f.fileno(),
- stdout=self.extraFile.fileno(),
- reactor=reactor)
-
- self.runReactor(reactor)
- self.assertEqual(protocol.data, "hello!")
-
-
- def test_addWriter(self):
- """
- Adding a filesystem file writer to a reactor will make sure it is
- polled.
- """
- reactor = self.buildReactor()
-
- class DisconnectProtocol(Protocol):
- def connectionLost(self, reason):
- reactor.stop()
-
- path = self.mktemp()
- f = file(path, "w")
-
- # Write bytes to a transport, hopefully have them written to a file:
- protocol = DisconnectProtocol()
- StandardIO(protocol, stdout=f.fileno(),
- stdin=self.extraFile.fileno(), reactor=reactor)
- protocol.transport.write("hello")
- protocol.transport.write(", world")
- protocol.transport.loseConnection()
-
- self.runReactor(reactor)
- f.close()
- f = file(path, "r")
- self.assertEqual(f.read(), "hello, world")
- f.close()
-
-
- def test_removeReader(self):
- """
- Removing a filesystem file reader from a reactor will make sure it is
- no longer polled.
- """
- reactor = self.buildReactor()
- self.addCleanup(self.unbuildReactor, reactor)
-
- path = self.mktemp()
- file(path, "w").close()
- # Cleanup might fail if file is GCed too soon:
- self.f = f = file(path, "r")
-
- # Have the reader added:
- stdio = StandardIO(Protocol(), stdin=f.fileno(),
- stdout=self.extraFile.fileno(),
- reactor=reactor)
- self.assertIn(stdio._reader, reactor.getReaders())
- stdio._reader.stopReading()
- self.assertNotIn(stdio._reader, reactor.getReaders())
-
-
- def test_removeWriter(self):
- """
- Removing a filesystem file writer from a reactor will make sure it is
- no longer polled.
- """
- reactor = self.buildReactor()
- self.addCleanup(self.unbuildReactor, reactor)
-
- # Cleanup might fail if file is GCed too soon:
- self.f = f = file(self.mktemp(), "w")
-
- # Have the reader added:
- protocol = Protocol()
- stdio = StandardIO(protocol, stdout=f.fileno(),
- stdin=self.extraFile.fileno(),
- reactor=reactor)
- protocol.transport.write("hello")
- self.assertIn(stdio._writer, reactor.getWriters())
- stdio._writer.stopWriting()
- self.assertNotIn(stdio._writer, reactor.getWriters())
-
-
- def test_removeAll(self):
- """
- Calling C{removeAll} on a reactor includes descriptors that are
- filesystem files.
- """
- reactor = self.buildReactor()
- self.addCleanup(self.unbuildReactor, reactor)
-
- path = self.mktemp()
- file(path, "w").close()
- # Cleanup might fail if file is GCed too soon:
- self.f = f = file(path, "r")
-
- # Have the reader added:
- stdio = StandardIO(Protocol(), stdin=f.fileno(),
- stdout=self.extraFile.fileno(), reactor=reactor)
- # And then removed:
- removed = reactor.removeAll()
- self.assertIn(stdio._reader, removed)
- self.assertNotIn(stdio._reader, reactor.getReaders())
-
-
- def test_getReaders(self):
- """
- C{reactor.getReaders} includes descriptors that are filesystem files.
- """
- reactor = self.buildReactor()
- self.addCleanup(self.unbuildReactor, reactor)
-
- path = self.mktemp()
- file(path, "w").close()
- # Cleanup might fail if file is GCed too soon:
- self.f = f = file(path, "r")
-
- # Have the reader added:
- stdio = StandardIO(Protocol(), stdin=f.fileno(),
- stdout=self.extraFile.fileno(), reactor=reactor)
- self.assertIn(stdio._reader, reactor.getReaders())
-
-
- def test_getWriters(self):
- """
- C{reactor.getWriters} includes descriptors that are filesystem files.
- """
- reactor = self.buildReactor()
- self.addCleanup(self.unbuildReactor, reactor)
-
- # Cleanup might fail if file is GCed too soon:
- self.f = f = file(self.mktemp(), "w")
-
- # Have the reader added:
- stdio = StandardIO(Protocol(), stdout=f.fileno(),
- stdin=self.extraFile.fileno(), reactor=reactor)
- self.assertNotIn(stdio._writer, reactor.getWriters())
- stdio._writer.startWriting()
- self.assertIn(stdio._writer, reactor.getWriters())
-
- if platform.isWindows():
- skip = ("StandardIO does not accept stdout as an argument to Windows. "
- "Testing redirection to a file is therefore harder.")
-
-
-globals().update(StdioFilesTests.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tcp.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tcp.py
deleted file mode 100755
index 862cc25b..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tcp.py
+++ /dev/null
@@ -1,2077 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorTCP} and the TCP parts of
-L{IReactorSocket}.
-"""
-
-__metaclass__ = type
-
-import socket, errno
-
-from zope.interface import implements
-
-from twisted.python.runtime import platform
-from twisted.python.failure import Failure
-from twisted.python import log
-
-from twisted.trial.unittest import SkipTest, TestCase
-from twisted.internet.test.reactormixins import ReactorBuilder, EndpointCreator
-from twisted.internet.test.reactormixins import ConnectableProtocol
-from twisted.internet.test.reactormixins import runProtocolsWithReactor
-from twisted.internet.error import (
- ConnectionLost, UserError, ConnectionRefusedError, ConnectionDone,
- ConnectionAborted)
-from twisted.internet.interfaces import (
- ILoggingContext, IConnector, IReactorFDSet, IReactorSocket, IReactorTCP)
-from twisted.internet.address import IPv4Address, IPv6Address
-from twisted.internet.defer import (
- Deferred, DeferredList, maybeDeferred, gatherResults)
-from twisted.internet.endpoints import (
- TCP4ServerEndpoint, TCP4ClientEndpoint)
-from twisted.internet.protocol import ServerFactory, ClientFactory, Protocol
-from twisted.internet.interfaces import (
- IPushProducer, IPullProducer, IHalfCloseableProtocol)
-from twisted.internet.tcp import Connection, Server, _resolveIPv6
-
-from twisted.internet.test.connectionmixins import (
- LogObserverMixin, ConnectionTestsMixin, TCPClientTestsMixin, findFreePort)
-from twisted.internet.test.test_core import ObjectModelIntegrationMixin
-from twisted.test.test_tcp import MyClientFactory, MyServerFactory
-from twisted.test.test_tcp import ClosingFactory, ClientStartStopFactory
-
-try:
- from OpenSSL import SSL
-except ImportError:
- useSSL = False
-else:
- from twisted.internet.ssl import ClientContextFactory
- useSSL = True
-
-try:
- socket.socket(socket.AF_INET6, socket.SOCK_STREAM).close()
-except socket.error, e:
- ipv6Skip = str(e)
-else:
- ipv6Skip = None
-
-
-
-if platform.isWindows():
- from twisted.internet.test import _win32ifaces
- getLinkLocalIPv6Addresses = _win32ifaces.win32GetLinkLocalIPv6Addresses
-else:
- try:
- from twisted.internet.test import _posixifaces
- except ImportError:
- getLinkLocalIPv6Addresses = lambda: []
- else:
- getLinkLocalIPv6Addresses = _posixifaces.posixGetLinkLocalIPv6Addresses
-
-
-
-def getLinkLocalIPv6Address():
- """
- Find and return a configured link local IPv6 address including a scope
- identifier using the % separation syntax. If the system has no link local
- IPv6 addresses, raise L{SkipTest} instead.
-
- @raise SkipTest: if no link local address can be found or if the
- C{netifaces} module is not available.
-
- @return: a C{str} giving the address
- """
- addresses = getLinkLocalIPv6Addresses()
- if addresses:
- return addresses[0]
- raise SkipTest("Link local IPv6 address unavailable")
-
-
-
-def connect(client, (host, port)):
- if '%' in host or ':' in host:
- address = socket.getaddrinfo(host, port)[0][4]
- else:
- address = (host, port)
- client.connect(address)
-
-
-
-class FakeSocket(object):
- """
- A fake for L{socket.socket} objects.
-
- @ivar data: A C{str} giving the data which will be returned from
- L{FakeSocket.recv}.
-
- @ivar sendBuffer: A C{list} of the objects passed to L{FakeSocket.send}.
- """
- def __init__(self, data):
- self.data = data
- self.sendBuffer = []
-
- def setblocking(self, blocking):
- self.blocking = blocking
-
- def recv(self, size):
- return self.data
-
- def send(self, bytes):
- """
- I{Send} all of C{bytes} by accumulating it into C{self.sendBuffer}.
-
- @return: The length of C{bytes}, indicating all the data has been
- accepted.
- """
- self.sendBuffer.append(bytes)
- return len(bytes)
-
-
- def shutdown(self, how):
- """
- Shutdown is not implemented. The method is provided since real sockets
- have it and some code expects it. No behavior of L{FakeSocket} is
- affected by a call to it.
- """
-
-
- def close(self):
- """
- Close is not implemented. The method is provided since real sockets
- have it and some code expects it. No behavior of L{FakeSocket} is
- affected by a call to it.
- """
-
-
- def setsockopt(self, *args):
- """
- Setsockopt is not implemented. The method is provided since
- real sockets have it and some code expects it. No behavior of
- L{FakeSocket} is affected by a call to it.
- """
-
-
- def fileno(self):
- """
- Return a fake file descriptor. If actually used, this will have no
- connection to this L{FakeSocket} and will probably cause surprising
- results.
- """
- return 1
-
-
-
-class TestFakeSocket(TestCase):
- """
- Test that the FakeSocket can be used by the doRead method of L{Connection}
- """
-
- def test_blocking(self):
- skt = FakeSocket("someData")
- skt.setblocking(0)
- self.assertEqual(skt.blocking, 0)
-
-
- def test_recv(self):
- skt = FakeSocket("someData")
- self.assertEqual(skt.recv(10), "someData")
-
-
- def test_send(self):
- """
- L{FakeSocket.send} accepts the entire string passed to it, adds it to
- its send buffer, and returns its length.
- """
- skt = FakeSocket("")
- count = skt.send("foo")
- self.assertEqual(count, 3)
- self.assertEqual(skt.sendBuffer, ["foo"])
-
-
-
-class FakeProtocol(Protocol):
- """
- An L{IProtocol} that returns a value from its dataReceived method.
- """
- def dataReceived(self, data):
- """
- Return something other than C{None} to trigger a deprecation warning for
- that behavior.
- """
- return ()
-
-
-
-class _FakeFDSetReactor(object):
- """
- A no-op implementation of L{IReactorFDSet}, which ignores all adds and
- removes.
- """
- implements(IReactorFDSet)
-
- addReader = addWriter = removeReader = removeWriter = (
- lambda self, desc: None)
-
-
-
-class TCPServerTests(TestCase):
- """
- Whitebox tests for L{twisted.internet.tcp.Server}.
- """
- def setUp(self):
- self.reactor = _FakeFDSetReactor()
- class FakePort(object):
- _realPortNumber = 3
- self.skt = FakeSocket("")
- self.protocol = Protocol()
- self.server = Server(
- self.skt, self.protocol, ("", 0), FakePort(), None, self.reactor)
-
-
- def test_writeAfterDisconnect(self):
- """
- L{Server.write} discards bytes passed to it if called after it has lost
- its connection.
- """
- self.server.connectionLost(
- Failure(Exception("Simulated lost connection")))
- self.server.write("hello world")
- self.assertEqual(self.skt.sendBuffer, [])
-
-
- def test_writeAfteDisconnectAfterTLS(self):
- """
- L{Server.write} discards bytes passed to it if called after it has lost
- its connection when the connection had started TLS.
- """
- self.server.TLS = True
- self.test_writeAfterDisconnect()
-
-
- def test_writeSequenceAfterDisconnect(self):
- """
- L{Server.writeSequence} discards bytes passed to it if called after it
- has lost its connection.
- """
- self.server.connectionLost(
- Failure(Exception("Simulated lost connection")))
- self.server.writeSequence(["hello world"])
- self.assertEqual(self.skt.sendBuffer, [])
-
-
- def test_writeSequenceAfteDisconnectAfterTLS(self):
- """
- L{Server.writeSequence} discards bytes passed to it if called after it
- has lost its connection when the connection had started TLS.
- """
- self.server.TLS = True
- self.test_writeSequenceAfterDisconnect()
-
-
-
-class TCPConnectionTests(TestCase):
- """
- Whitebox tests for L{twisted.internet.tcp.Connection}.
- """
- def test_doReadWarningIsRaised(self):
- """
- When an L{IProtocol} implementation that returns a value from its
- C{dataReceived} method, a deprecated warning is emitted.
- """
- skt = FakeSocket("someData")
- protocol = FakeProtocol()
- conn = Connection(skt, protocol)
- conn.doRead()
- warnings = self.flushWarnings([FakeProtocol.dataReceived])
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(
- warnings[0]["message"],
- "Returning a value other than None from "
- "twisted.internet.test.test_tcp.FakeProtocol.dataReceived "
- "is deprecated since Twisted 11.0.0.")
- self.assertEqual(len(warnings), 1)
-
-
- def test_noTLSBeforeStartTLS(self):
- """
- The C{TLS} attribute of a L{Connection} instance is C{False} before
- L{Connection.startTLS} is called.
- """
- skt = FakeSocket("")
- protocol = FakeProtocol()
- conn = Connection(skt, protocol)
- self.assertFalse(conn.TLS)
-
-
- def test_tlsAfterStartTLS(self):
- """
- The C{TLS} attribute of a L{Connection} instance is C{True} after
- L{Connection.startTLS} is called.
- """
- skt = FakeSocket("")
- protocol = FakeProtocol()
- conn = Connection(skt, protocol, reactor=_FakeFDSetReactor())
- conn._tlsClientDefault = True
- conn.startTLS(ClientContextFactory(), True)
- self.assertTrue(conn.TLS)
- if not useSSL:
- test_tlsAfterStartTLS.skip = "No SSL support available"
-
-
-
-class TCPCreator(EndpointCreator):
- """
- Create IPv4 TCP endpoints for L{runProtocolsWithReactor}-based tests.
- """
-
- interface = "127.0.0.1"
-
- def server(self, reactor):
- """
- Create a server-side TCP endpoint.
- """
- return TCP4ServerEndpoint(reactor, 0, interface=self.interface)
-
-
- def client(self, reactor, serverAddress):
- """
- Create a client end point that will connect to the given address.
-
- @type serverAddress: L{IPv4Address}
- """
- return TCP4ClientEndpoint(reactor, self.interface, serverAddress.port)
-
-
-
-class TCP6Creator(TCPCreator):
- """
- Create IPv6 TCP endpoints for
- C{ReactorBuilder.runProtocolsWithReactor}-based tests.
-
- The endpoint types in question here are still the TCP4 variety, since
- these simply pass through IPv6 address literals to the reactor, and we are
- only testing address literals, not name resolution (as name resolution has
- not yet been implemented). See http://twistedmatrix.com/trac/ticket/4470
- for more specific information about new endpoint classes. The naming is
- slightly misleading, but presumably if you're passing an IPv6 literal, you
- know what you're asking for.
- """
- def __init__(self):
- self.interface = getLinkLocalIPv6Address()
-
-
-
-class TCPClientTestsBase(ReactorBuilder, ConnectionTestsMixin,
- TCPClientTestsMixin):
- """
- Base class for builders defining tests related to L{IReactorTCP.connectTCP}.
- """
- requiredInterfaces = (IReactorTCP,)
-
- port = 1234
-
- @property
- def interface(self):
- """
- Return the interface attribute from the endpoints object.
- """
- return self.endpoints.interface
-
-
-
-class TCP4ClientTestsBuilder(TCPClientTestsBase):
- """
- Builder configured with IPv4 parameters for tests related to
- L{IReactorTCP.connectTCP}.
- """
- fakeDomainName = 'some-fake.domain.example.com'
- family = socket.AF_INET
- addressClass = IPv4Address
-
- endpoints = TCPCreator()
-
-
-
-class TCP6ClientTestsBuilder(TCPClientTestsBase):
- """
- Builder configured with IPv6 parameters for tests related to
- L{IReactorTCP.connectTCP}.
- """
- if ipv6Skip:
- skip = ipv6Skip
-
- family = socket.AF_INET6
- addressClass = IPv6Address
-
- def setUp(self):
- # Only create this object here, so that it won't be created if tests
- # are being skipped:
- self.endpoints = TCP6Creator()
- # This is used by test_addresses to test the distinction between the
- # resolved name and the name on the socket itself. All the same
- # invariants should hold, but giving back an IPv6 address from a
- # resolver is not something the reactor can handle, so instead, we make
- # it so that the connect call for the IPv6 address test simply uses an
- # address literal.
- self.fakeDomainName = self.endpoints.interface
-
-
-
-class TCPConnectorTestsBuilder(ReactorBuilder):
- """
- Tests for the L{IConnector} provider returned by L{IReactorTCP.connectTCP}.
- """
- requiredInterfaces = (IReactorTCP,)
-
- def test_connectorIdentity(self):
- """
- L{IReactorTCP.connectTCP} returns an object which provides
- L{IConnector}. The destination of the connector is the address which
- was passed to C{connectTCP}. The same connector object is passed to
- the factory's C{startedConnecting} method as to the factory's
- C{clientConnectionLost} method.
- """
- serverFactory = ClosingFactory()
- reactor = self.buildReactor()
- tcpPort = reactor.listenTCP(0, serverFactory, interface=self.interface)
- serverFactory.port = tcpPort
- portNumber = tcpPort.getHost().port
-
- seenConnectors = []
- seenFailures = []
-
- clientFactory = ClientStartStopFactory()
- clientFactory.clientConnectionLost = (
- lambda connector, reason: (seenConnectors.append(connector),
- seenFailures.append(reason)))
- clientFactory.startedConnecting = seenConnectors.append
-
- connector = reactor.connectTCP(self.interface, portNumber,
- clientFactory)
- self.assertTrue(IConnector.providedBy(connector))
- dest = connector.getDestination()
- self.assertEqual(dest.type, "TCP")
- self.assertEqual(dest.host, self.interface)
- self.assertEqual(dest.port, portNumber)
-
- clientFactory.whenStopped.addBoth(lambda _: reactor.stop())
-
- self.runReactor(reactor)
-
- seenFailures[0].trap(ConnectionDone)
- self.assertEqual(seenConnectors, [connector, connector])
-
-
- def test_userFail(self):
- """
- Calling L{IConnector.stopConnecting} in C{Factory.startedConnecting}
- results in C{Factory.clientConnectionFailed} being called with
- L{error.UserError} as the reason.
- """
- serverFactory = MyServerFactory()
- reactor = self.buildReactor()
- tcpPort = reactor.listenTCP(0, serverFactory, interface=self.interface)
- portNumber = tcpPort.getHost().port
-
- fatalErrors = []
-
- def startedConnecting(connector):
- try:
- connector.stopConnecting()
- except Exception:
- fatalErrors.append(Failure())
- reactor.stop()
-
- clientFactory = ClientStartStopFactory()
- clientFactory.startedConnecting = startedConnecting
-
- clientFactory.whenStopped.addBoth(lambda _: reactor.stop())
-
- reactor.callWhenRunning(lambda: reactor.connectTCP(self.interface,
- portNumber,
- clientFactory))
-
- self.runReactor(reactor)
-
- if fatalErrors:
- self.fail(fatalErrors[0].getTraceback())
- clientFactory.reason.trap(UserError)
- self.assertEqual(clientFactory.failed, 1)
-
-
- def test_reconnect(self):
- """
- Calling L{IConnector.connect} in C{Factory.clientConnectionLost} causes
- a new connection attempt to be made.
- """
- serverFactory = ClosingFactory()
- reactor = self.buildReactor()
- tcpPort = reactor.listenTCP(0, serverFactory, interface=self.interface)
- serverFactory.port = tcpPort
- portNumber = tcpPort.getHost().port
-
- clientFactory = MyClientFactory()
-
- def clientConnectionLost(connector, reason):
- connector.connect()
- clientFactory.clientConnectionLost = clientConnectionLost
- reactor.connectTCP(self.interface, portNumber, clientFactory)
-
- protocolMadeAndClosed = []
- def reconnectFailed(ignored):
- p = clientFactory.protocol
- protocolMadeAndClosed.append((p.made, p.closed))
- reactor.stop()
-
- clientFactory.failDeferred.addCallback(reconnectFailed)
-
- self.runReactor(reactor)
-
- clientFactory.reason.trap(ConnectionRefusedError)
- self.assertEqual(protocolMadeAndClosed, [(1, 1)])
-
-
-
-class TCP4ConnectorTestsBuilder(TCPConnectorTestsBuilder):
- interface = '127.0.0.1'
- family = socket.AF_INET
- addressClass = IPv4Address
-
-
-
-class TCP6ConnectorTestsBuilder(TCPConnectorTestsBuilder):
- family = socket.AF_INET6
- addressClass = IPv6Address
-
- if ipv6Skip:
- skip = ipv6Skip
-
- def setUp(self):
- self.interface = getLinkLocalIPv6Address()
-
-
-
-def createTestSocket(test, addressFamily, socketType):
- """
- Create a socket for the duration of the given test.
-
- @param test: the test to add cleanup to.
-
- @param addressFamily: an C{AF_*} constant
-
- @param socketType: a C{SOCK_*} constant.
-
- @return: a socket object.
- """
- skt = socket.socket(addressFamily, socketType)
- test.addCleanup(skt.close)
- return skt
-
-
-
-class StreamTransportTestsMixin(LogObserverMixin):
- """
- Mixin defining tests which apply to any port/connection based transport.
- """
- def test_startedListeningLogMessage(self):
- """
- When a port starts, a message including a description of the associated
- factory is logged.
- """
- loggedMessages = self.observe()
- reactor = self.buildReactor()
- class SomeFactory(ServerFactory):
- implements(ILoggingContext)
- def logPrefix(self):
- return "Crazy Factory"
- factory = SomeFactory()
- p = self.getListeningPort(reactor, factory)
- expectedMessage = self.getExpectedStartListeningLogMessage(
- p, "Crazy Factory")
- self.assertEqual((expectedMessage,), loggedMessages[0]['message'])
-
-
- def test_connectionLostLogMsg(self):
- """
- When a connection is lost, an informative message should be logged
- (see L{getExpectedConnectionLostLogMsg}): an address identifying
- the port and the fact that it was closed.
- """
-
- loggedMessages = []
- def logConnectionLostMsg(eventDict):
- loggedMessages.append(log.textFromEventDict(eventDict))
-
- reactor = self.buildReactor()
- p = self.getListeningPort(reactor, ServerFactory())
- expectedMessage = self.getExpectedConnectionLostLogMsg(p)
- log.addObserver(logConnectionLostMsg)
-
- def stopReactor(ignored):
- log.removeObserver(logConnectionLostMsg)
- reactor.stop()
-
- def doStopListening():
- log.addObserver(logConnectionLostMsg)
- maybeDeferred(p.stopListening).addCallback(stopReactor)
-
- reactor.callWhenRunning(doStopListening)
- reactor.run()
-
- self.assertIn(expectedMessage, loggedMessages)
-
-
- def test_allNewStyle(self):
- """
- The L{IListeningPort} object is an instance of a class with no
- classic classes in its hierarchy.
- """
- reactor = self.buildReactor()
- port = self.getListeningPort(reactor, ServerFactory())
- self.assertFullyNewStyle(port)
-
-
-class ListenTCPMixin(object):
- """
- Mixin which uses L{IReactorTCP.listenTCP} to hand out listening TCP ports.
- """
- def getListeningPort(self, reactor, factory, port=0, interface=''):
- """
- Get a TCP port from a reactor.
- """
- return reactor.listenTCP(port, factory, interface=interface)
-
-
-
-class SocketTCPMixin(object):
- """
- Mixin which uses L{IReactorSocket.adoptStreamPort} to hand out listening TCP
- ports.
- """
- def getListeningPort(self, reactor, factory, port=0, interface=''):
- """
- Get a TCP port from a reactor, wrapping an already-initialized file
- descriptor.
- """
- if IReactorSocket.providedBy(reactor):
- if ':' in interface:
- domain = socket.AF_INET6
- address = socket.getaddrinfo(interface, port)[0][4]
- else:
- domain = socket.AF_INET
- address = (interface, port)
- portSock = socket.socket(domain)
- portSock.bind(address)
- portSock.listen(3)
- portSock.setblocking(False)
- try:
- return reactor.adoptStreamPort(
- portSock.fileno(), portSock.family, factory)
- finally:
- # The socket should still be open; fileno will raise if it is
- # not.
- portSock.fileno()
- # Now clean it up, because the rest of the test does not need
- # it.
- portSock.close()
- else:
- raise SkipTest("Reactor does not provide IReactorSocket")
-
-
-
-class TCPPortTestsMixin(object):
- """
- Tests for L{IReactorTCP.listenTCP}
- """
- requiredInterfaces = (IReactorTCP,)
-
- def getExpectedStartListeningLogMessage(self, port, factory):
- """
- Get the message expected to be logged when a TCP port starts listening.
- """
- return "%s starting on %d" % (
- factory, port.getHost().port)
-
-
- def getExpectedConnectionLostLogMsg(self, port):
- """
- Get the expected connection lost message for a TCP port.
- """
- return "(TCP Port %s Closed)" % (port.getHost().port,)
-
-
- def test_portGetHostOnIPv4(self):
- """
- When no interface is passed to L{IReactorTCP.listenTCP}, the returned
- listening port listens on an IPv4 address.
- """
- reactor = self.buildReactor()
- port = self.getListeningPort(reactor, ServerFactory())
- address = port.getHost()
- self.assertIsInstance(address, IPv4Address)
-
-
- def test_portGetHostOnIPv6(self):
- """
- When listening on an IPv6 address, L{IListeningPort.getHost} returns
- an L{IPv6Address} with C{host} and C{port} attributes reflecting the
- address the port is bound to.
- """
- reactor = self.buildReactor()
- host, portNumber = findFreePort(
- family=socket.AF_INET6, interface='::1')[:2]
- port = self.getListeningPort(
- reactor, ServerFactory(), portNumber, host)
- address = port.getHost()
- self.assertIsInstance(address, IPv6Address)
- self.assertEqual('::1', address.host)
- self.assertEqual(portNumber, address.port)
- if ipv6Skip:
- test_portGetHostOnIPv6.skip = ipv6Skip
-
-
- def test_portGetHostOnIPv6ScopeID(self):
- """
- When a link-local IPv6 address including a scope identifier is passed as
- the C{interface} argument to L{IReactorTCP.listenTCP}, the resulting
- L{IListeningPort} reports its address as an L{IPv6Address} with a host
- value that includes the scope identifier.
- """
- linkLocal = getLinkLocalIPv6Address()
- reactor = self.buildReactor()
- port = self.getListeningPort(reactor, ServerFactory(), 0, linkLocal)
- address = port.getHost()
- self.assertIsInstance(address, IPv6Address)
- self.assertEqual(linkLocal, address.host)
- if ipv6Skip:
- test_portGetHostOnIPv6ScopeID.skip = ipv6Skip
-
-
- def _buildProtocolAddressTest(self, client, interface):
- """
- Connect C{client} to a server listening on C{interface} started with
- L{IReactorTCP.listenTCP} and return the address passed to the factory's
- C{buildProtocol} method.
-
- @param client: A C{SOCK_STREAM} L{socket.socket} created with an address
- family such that it will be able to connect to a server listening on
- C{interface}.
-
- @param interface: A C{str} giving an address for a server to listen on.
- This should almost certainly be the loopback address for some
- address family supported by L{IReactorTCP.listenTCP}.
-
- @return: Whatever object, probably an L{IAddress} provider, is passed to
- a server factory's C{buildProtocol} method when C{client}
- establishes a connection.
- """
- class ObserveAddress(ServerFactory):
- def buildProtocol(self, address):
- reactor.stop()
- self.observedAddress = address
- return Protocol()
-
- factory = ObserveAddress()
- reactor = self.buildReactor()
- port = self.getListeningPort(reactor, factory, 0, interface)
- client.setblocking(False)
- try:
- connect(client, (port.getHost().host, port.getHost().port))
- except socket.error, (errnum, message):
- self.assertIn(errnum, (errno.EINPROGRESS, errno.EWOULDBLOCK))
-
- self.runReactor(reactor)
-
- return factory.observedAddress
-
-
- def test_buildProtocolIPv4Address(self):
- """
- When a connection is accepted over IPv4, an L{IPv4Address} is passed
- to the factory's C{buildProtocol} method giving the peer's address.
- """
- interface = '127.0.0.1'
- client = createTestSocket(self, socket.AF_INET, socket.SOCK_STREAM)
- observedAddress = self._buildProtocolAddressTest(client, interface)
- self.assertEqual(
- IPv4Address('TCP', *client.getsockname()), observedAddress)
-
-
- def test_buildProtocolIPv6Address(self):
- """
- When a connection is accepted to an IPv6 address, an L{IPv6Address} is
- passed to the factory's C{buildProtocol} method giving the peer's
- address.
- """
- interface = '::1'
- client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
- observedAddress = self._buildProtocolAddressTest(client, interface)
- self.assertEqual(
- IPv6Address('TCP', *client.getsockname()[:2]), observedAddress)
- if ipv6Skip:
- test_buildProtocolIPv6Address.skip = ipv6Skip
-
-
- def test_buildProtocolIPv6AddressScopeID(self):
- """
- When a connection is accepted to a link-local IPv6 address, an
- L{IPv6Address} is passed to the factory's C{buildProtocol} method
- giving the peer's address, including a scope identifier.
- """
- interface = getLinkLocalIPv6Address()
- client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
- observedAddress = self._buildProtocolAddressTest(client, interface)
- self.assertEqual(
- IPv6Address('TCP', *client.getsockname()[:2]), observedAddress)
- if ipv6Skip:
- test_buildProtocolIPv6AddressScopeID.skip = ipv6Skip
-
-
- def _serverGetConnectionAddressTest(self, client, interface, which):
- """
- Connect C{client} to a server listening on C{interface} started with
- L{IReactorTCP.listenTCP} and return the address returned by one of the
- server transport's address lookup methods, C{getHost} or C{getPeer}.
-
- @param client: A C{SOCK_STREAM} L{socket.socket} created with an address
- family such that it will be able to connect to a server listening on
- C{interface}.
-
- @param interface: A C{str} giving an address for a server to listen on.
- This should almost certainly be the loopback address for some
- address family supported by L{IReactorTCP.listenTCP}.
-
- @param which: A C{str} equal to either C{"getHost"} or C{"getPeer"}
- determining which address will be returned.
-
- @return: Whatever object, probably an L{IAddress} provider, is returned
- from the method indicated by C{which}.
- """
- class ObserveAddress(Protocol):
- def makeConnection(self, transport):
- reactor.stop()
- self.factory.address = getattr(transport, which)()
-
- reactor = self.buildReactor()
- factory = ServerFactory()
- factory.protocol = ObserveAddress
- port = self.getListeningPort(reactor, factory, 0, interface)
- client.setblocking(False)
- try:
- connect(client, (port.getHost().host, port.getHost().port))
- except socket.error, (errnum, message):
- self.assertIn(errnum, (errno.EINPROGRESS, errno.EWOULDBLOCK))
- self.runReactor(reactor)
- return factory.address
-
-
- def test_serverGetHostOnIPv4(self):
- """
- When a connection is accepted over IPv4, the server
- L{ITransport.getHost} method returns an L{IPv4Address} giving the
- address on which the server accepted the connection.
- """
- interface = '127.0.0.1'
- client = createTestSocket(self, socket.AF_INET, socket.SOCK_STREAM)
- hostAddress = self._serverGetConnectionAddressTest(
- client, interface, 'getHost')
- self.assertEqual(
- IPv4Address('TCP', *client.getpeername()), hostAddress)
-
-
- def test_serverGetHostOnIPv6(self):
- """
- When a connection is accepted over IPv6, the server
- L{ITransport.getHost} method returns an L{IPv6Address} giving the
- address on which the server accepted the connection.
- """
- interface = '::1'
- client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
- hostAddress = self._serverGetConnectionAddressTest(
- client, interface, 'getHost')
- self.assertEqual(
- IPv6Address('TCP', *client.getpeername()[:2]), hostAddress)
- if ipv6Skip:
- test_serverGetHostOnIPv6.skip = ipv6Skip
-
-
- def test_serverGetHostOnIPv6ScopeID(self):
- """
- When a connection is accepted over IPv6, the server
- L{ITransport.getHost} method returns an L{IPv6Address} giving the
- address on which the server accepted the connection, including the scope
- identifier.
- """
- interface = getLinkLocalIPv6Address()
- client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
- hostAddress = self._serverGetConnectionAddressTest(
- client, interface, 'getHost')
- self.assertEqual(
- IPv6Address('TCP', *client.getpeername()[:2]), hostAddress)
- if ipv6Skip:
- test_serverGetHostOnIPv6ScopeID.skip = ipv6Skip
-
-
- def test_serverGetPeerOnIPv4(self):
- """
- When a connection is accepted over IPv4, the server
- L{ITransport.getPeer} method returns an L{IPv4Address} giving the
- address of the remote end of the connection.
- """
- interface = '127.0.0.1'
- client = createTestSocket(self, socket.AF_INET, socket.SOCK_STREAM)
- peerAddress = self._serverGetConnectionAddressTest(
- client, interface, 'getPeer')
- self.assertEqual(
- IPv4Address('TCP', *client.getsockname()), peerAddress)
-
-
- def test_serverGetPeerOnIPv6(self):
- """
- When a connection is accepted over IPv6, the server
- L{ITransport.getPeer} method returns an L{IPv6Address} giving the
- address on the remote end of the connection.
- """
- interface = '::1'
- client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
- peerAddress = self._serverGetConnectionAddressTest(
- client, interface, 'getPeer')
- self.assertEqual(
- IPv6Address('TCP', *client.getsockname()[:2]), peerAddress)
- if ipv6Skip:
- test_serverGetPeerOnIPv6.skip = ipv6Skip
-
-
- def test_serverGetPeerOnIPv6ScopeID(self):
- """
- When a connection is accepted over IPv6, the server
- L{ITransport.getPeer} method returns an L{IPv6Address} giving the
- address on the remote end of the connection, including the scope
- identifier.
- """
- interface = getLinkLocalIPv6Address()
- client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
- peerAddress = self._serverGetConnectionAddressTest(
- client, interface, 'getPeer')
- self.assertEqual(
- IPv6Address('TCP', *client.getsockname()[:2]), peerAddress)
- if ipv6Skip:
- test_serverGetPeerOnIPv6ScopeID.skip = ipv6Skip
-
-
-
-class TCPPortTestsBuilder(ReactorBuilder, ListenTCPMixin, TCPPortTestsMixin,
- ObjectModelIntegrationMixin,
- StreamTransportTestsMixin):
- pass
-
-
-
-class TCPFDPortTestsBuilder(ReactorBuilder, SocketTCPMixin, TCPPortTestsMixin,
- ObjectModelIntegrationMixin,
- StreamTransportTestsMixin):
- pass
-
-
-
-class StopStartReadingProtocol(Protocol):
- """
- Protocol that pauses and resumes the transport a few times
- """
-
- def connectionMade(self):
- self.data = ''
- self.pauseResumeProducing(3)
-
-
- def pauseResumeProducing(self, counter):
- """
- Toggle transport read state, then count down.
- """
- self.transport.pauseProducing()
- self.transport.resumeProducing()
- if counter:
- self.factory.reactor.callLater(0,
- self.pauseResumeProducing, counter - 1)
- else:
- self.factory.reactor.callLater(0,
- self.factory.ready.callback, self)
-
-
- def dataReceived(self, data):
- log.msg('got data', len(data))
- self.data += data
- if len(self.data) == 4*4096:
- self.factory.stop.callback(self.data)
-
-
-
-class TCPConnectionTestsBuilder(ReactorBuilder):
- """
- Builder defining tests relating to L{twisted.internet.tcp.Connection}.
- """
- requiredInterfaces = (IReactorTCP,)
-
- def test_stopStartReading(self):
- """
- This test verifies transport socket read state after multiple
- pause/resumeProducing calls.
- """
- sf = ServerFactory()
- reactor = sf.reactor = self.buildReactor()
-
- skippedReactors = ["Glib2Reactor", "Gtk2Reactor"]
- reactorClassName = reactor.__class__.__name__
- if reactorClassName in skippedReactors and platform.isWindows():
- raise SkipTest(
- "This test is broken on gtk/glib under Windows.")
-
- sf.protocol = StopStartReadingProtocol
- sf.ready = Deferred()
- sf.stop = Deferred()
- p = reactor.listenTCP(0, sf)
- port = p.getHost().port
- def proceed(protos, port):
- """
- Send several IOCPReactor's buffers' worth of data.
- """
- self.assertTrue(protos[0])
- self.assertTrue(protos[1])
- protos = protos[0][1], protos[1][1]
- protos[0].transport.write('x' * (2 * 4096) + 'y' * (2 * 4096))
- return (sf.stop.addCallback(cleanup, protos, port)
- .addCallback(lambda ign: reactor.stop()))
-
- def cleanup(data, protos, port):
- """
- Make sure IOCPReactor didn't start several WSARecv operations
- that clobbered each other's results.
- """
- self.assertEqual(data, 'x'*(2*4096) + 'y'*(2*4096),
- 'did not get the right data')
- return DeferredList([
- maybeDeferred(protos[0].transport.loseConnection),
- maybeDeferred(protos[1].transport.loseConnection),
- maybeDeferred(port.stopListening)])
-
- cc = TCP4ClientEndpoint(reactor, '127.0.0.1', port)
- cf = ClientFactory()
- cf.protocol = Protocol
- d = DeferredList([cc.connect(cf), sf.ready]).addCallback(proceed, p)
- d.addErrback(log.err)
- self.runReactor(reactor)
-
-
- def test_connectionLostAfterPausedTransport(self):
- """
- Alice connects to Bob. Alice writes some bytes and then shuts down the
- connection. Bob receives the bytes from the connection and then pauses
- the transport object. Shortly afterwards Bob resumes the transport
- object. At that point, Bob is notified that the connection has been
- closed.
-
- This is no problem for most reactors. The underlying event notification
- API will probably just remind them that the connection has been closed.
- It is a little tricky for win32eventreactor (MsgWaitForMultipleObjects).
- MsgWaitForMultipleObjects will only deliver the close notification once.
- The reactor needs to remember that notification until Bob resumes the
- transport.
- """
- class Pauser(ConnectableProtocol):
- def __init__(self):
- self.events = []
-
- def dataReceived(self, bytes):
- self.events.append("paused")
- self.transport.pauseProducing()
- self.reactor.callLater(0, self.resume)
-
- def resume(self):
- self.events.append("resumed")
- self.transport.resumeProducing()
-
- def connectionLost(self, reason):
- # This is the event you have been waiting for.
- self.events.append("lost")
- ConnectableProtocol.connectionLost(self, reason)
-
- class Client(ConnectableProtocol):
- def connectionMade(self):
- self.transport.write("some bytes for you")
- self.transport.loseConnection()
-
- pauser = Pauser()
- runProtocolsWithReactor(self, pauser, Client(), TCPCreator())
- self.assertEqual(pauser.events, ["paused", "resumed", "lost"])
-
-
- def test_doubleHalfClose(self):
- """
- If one side half-closes its connection, and then the other side of the
- connection calls C{loseWriteConnection}, and then C{loseConnection} in
- {writeConnectionLost}, the connection is closed correctly.
-
- This rather obscure case used to fail (see ticket #3037).
- """
- class ListenerProtocol(ConnectableProtocol):
- implements(IHalfCloseableProtocol)
-
- def readConnectionLost(self):
- self.transport.loseWriteConnection()
-
- def writeConnectionLost(self):
- self.transport.loseConnection()
-
- class Client(ConnectableProtocol):
- def connectionMade(self):
- self.transport.loseConnection()
-
- # If test fails, reactor won't stop and we'll hit timeout:
- runProtocolsWithReactor(
- self, ListenerProtocol(), Client(), TCPCreator())
-
-
-
-class WriteSequenceTestsMixin(object):
- """
- Test for L{twisted.internet.abstract.FileDescriptor.writeSequence}.
- """
- requiredInterfaces = (IReactorTCP,)
-
- def setWriteBufferSize(self, transport, value):
- """
- Set the write buffer size for the given transport, mananing possible
- differences (ie, IOCP). Bug #4322 should remove the need of that hack.
- """
- if getattr(transport, "writeBufferSize", None) is not None:
- transport.writeBufferSize = value
- else:
- transport.bufferSize = value
-
-
- def test_writeSequeceWithoutWrite(self):
- """
- C{writeSequence} sends the data even if C{write} hasn't been called.
- """
-
- def connected(protocols):
- client, server, port = protocols
-
- def dataReceived(data):
- log.msg("data received: %r" % data)
- self.assertEqual(data, "Some sequence splitted")
- client.transport.loseConnection()
-
- server.dataReceived = dataReceived
-
- client.transport.writeSequence(["Some ", "sequence ", "splitted"])
-
- reactor = self.buildReactor()
- d = self.getConnectedClientAndServer(reactor, "127.0.0.1",
- socket.AF_INET)
- d.addCallback(connected)
- d.addErrback(log.err)
- self.runReactor(reactor)
-
-
- def test_writeSequenceWithUnicodeRaisesException(self):
- """
- C{writeSequence} with an element in the sequence of type unicode raises
- C{TypeError}.
- """
-
- def connected(protocols):
- client, server, port = protocols
-
- exc = self.assertRaises(
- TypeError,
- server.transport.writeSequence, [u"Unicode is not kosher"])
-
- self.assertEqual(str(exc), "Data must not be unicode")
-
- server.transport.loseConnection()
-
- reactor = self.buildReactor()
- d = self.getConnectedClientAndServer(reactor, "127.0.0.1",
- socket.AF_INET)
- d.addCallback(connected)
- d.addErrback(log.err)
- self.runReactor(reactor)
-
-
- def test_streamingProducer(self):
- """
- C{writeSequence} pauses its streaming producer if too much data is
- buffered, and then resumes it.
- """
-
- class SaveActionProducer(object):
- implements(IPushProducer)
- client = None
- server = None
-
- def __init__(self):
- self.actions = []
-
- def pauseProducing(self):
- self.actions.append("pause")
-
- def resumeProducing(self):
- self.actions.append("resume")
- # Unregister the producer so the connection can close
- self.client.transport.unregisterProducer()
- # This is why the code below waits for the server connection
- # first - so we have it to close here. We close the server
- # side because win32evenreactor cannot reliably observe us
- # closing the client side (#5285).
- self.server.transport.loseConnection()
-
- def stopProducing(self):
- self.actions.append("stop")
-
- producer = SaveActionProducer()
-
- def connected(protocols):
- client, server = protocols[:2]
- producer.client = client
- producer.server = server
- # Register a streaming producer and verify that it gets paused
- # after it writes more than the local send buffer can hold.
- client.transport.registerProducer(producer, True)
- self.assertEqual(producer.actions, [])
- self.setWriteBufferSize(client.transport, 500)
- client.transport.writeSequence(["x" * 50] * 20)
- self.assertEqual(producer.actions, ["pause"])
-
- reactor = self.buildReactor()
- d = self.getConnectedClientAndServer(reactor, "127.0.0.1",
- socket.AF_INET)
- d.addCallback(connected)
- d.addErrback(log.err)
- self.runReactor(reactor)
- # After the send buffer gets a chance to empty out a bit, the producer
- # should be resumed.
- self.assertEqual(producer.actions, ["pause", "resume"])
-
-
- def test_nonStreamingProducer(self):
- """
- C{writeSequence} pauses its producer if too much data is buffered only
- if this is a streaming producer.
- """
- test = self
-
- class SaveActionProducer(object):
- implements(IPullProducer)
- client = None
-
- def __init__(self):
- self.actions = []
-
- def resumeProducing(self):
- self.actions.append("resume")
- if self.actions.count("resume") == 2:
- self.client.transport.stopConsuming()
- else:
- test.setWriteBufferSize(self.client.transport, 500)
- self.client.transport.writeSequence(["x" * 50] * 20)
-
- def stopProducing(self):
- self.actions.append("stop")
-
-
- producer = SaveActionProducer()
-
- def connected(protocols):
- client = protocols[0]
- producer.client = client
- # Register a non-streaming producer and verify that it is resumed
- # immediately.
- client.transport.registerProducer(producer, False)
- self.assertEqual(producer.actions, ["resume"])
-
- reactor = self.buildReactor()
- d = self.getConnectedClientAndServer(reactor, "127.0.0.1",
- socket.AF_INET)
- d.addCallback(connected)
- d.addErrback(log.err)
- self.runReactor(reactor)
- # After the local send buffer empties out, the producer should be
- # resumed again.
- self.assertEqual(producer.actions, ["resume", "resume"])
-
-
-
-class TCPTransportServerAddressTestMixin(object):
- """
- Test mixing for TCP server address building and log prefix.
- """
-
- def getConnectedClientAndServer(self, reactor, interface, addressFamily):
- """
- Helper method returnine a L{Deferred} firing with a tuple of a client
- protocol, a server protocol, and a running TCP port.
- """
- raise NotImplementedError()
-
-
- def _testServerAddress(self, interface, addressFamily, adressClass):
- """
- Helper method to test TCP server addresses on either IPv4 or IPv6.
- """
-
- def connected(protocols):
- client, server, port = protocols
-
- self.assertEqual(
- "<AccumulatingProtocol #%s on %s>" %
- (server.transport.sessionno, port.getHost().port),
- str(server.transport))
-
- self.assertEqual(
- "AccumulatingProtocol,%s,%s" %
- (server.transport.sessionno, interface),
- server.transport.logstr)
-
- [peerAddress] = server.factory.peerAddresses
- self.assertIsInstance(peerAddress, adressClass)
- self.assertEqual('TCP', peerAddress.type)
- self.assertEqual(interface, peerAddress.host)
-
- server.transport.loseConnection()
-
- reactor = self.buildReactor()
- d = self.getConnectedClientAndServer(reactor, interface, addressFamily)
- d.addCallback(connected)
- d.addErrback(log.err)
- self.runReactor(reactor)
-
-
- def test_serverAddressTCP4(self):
- """
- L{Server} instances have a string representation indicating on which
- port they're running, and the connected address is stored on the
- C{peerAddresses} attribute of the factory.
- """
- return self._testServerAddress("127.0.0.1", socket.AF_INET,
- IPv4Address)
-
-
- def test_serverAddressTCP6(self):
- """
- IPv6 L{Server} instances have a string representation indicating on
- which port they're running, and the connected address is stored on the
- C{peerAddresses} attribute of the factory.
- """
- return self._testServerAddress(getLinkLocalIPv6Address(),
- socket.AF_INET6, IPv6Address)
-
- if ipv6Skip:
- test_serverAddressTCP6.skip = ipv6Skip
-
-
-
-class TCPTransportTestsBuilder(TCPTransportServerAddressTestMixin,
- WriteSequenceTestsMixin, ReactorBuilder):
- """
- Test standard L{ITCPTransport}s built with C{listenTCP} and C{connectTCP}.
- """
-
- def getConnectedClientAndServer(self, reactor, interface, addressFamily):
- """
- Return a L{Deferred} firing with a L{MyClientFactory} and
- L{MyServerFactory} connected pair, and the listening C{Port}.
- """
- server = MyServerFactory()
- server.protocolConnectionMade = Deferred()
- server.protocolConnectionLost = Deferred()
-
- client = MyClientFactory()
- client.protocolConnectionMade = Deferred()
- client.protocolConnectionLost = Deferred()
-
- port = reactor.listenTCP(0, server, interface=interface)
-
- lostDeferred = gatherResults([client.protocolConnectionLost,
- server.protocolConnectionLost])
- def stop(result):
- reactor.stop()
- return result
-
- lostDeferred.addBoth(stop)
-
- startDeferred = gatherResults([client.protocolConnectionMade,
- server.protocolConnectionMade])
-
- deferred = Deferred()
-
- def start(protocols):
- client, server = protocols
- log.msg("client connected %s" % client)
- log.msg("server connected %s" % server)
- deferred.callback((client, server, port))
-
- startDeferred.addCallback(start)
-
- reactor.connectTCP(interface, port.getHost().port, client)
-
- return deferred
-
-
-
-class AdoptStreamConnectionTestsBuilder(TCPTransportServerAddressTestMixin,
- WriteSequenceTestsMixin,
- ReactorBuilder):
- """
- Test server transports built using C{adoptStreamConnection}.
- """
-
- requiredInterfaces = (IReactorFDSet, IReactorSocket)
-
- def getConnectedClientAndServer(self, reactor, interface, addressFamily):
- """
- Return a L{Deferred} firing with a L{MyClientFactory} and
- L{MyServerFactory} connected pair, and the listening C{Port}. The
- particularity is that the server protocol has been obtained after doing
- a C{adoptStreamConnection} against the original server connection.
- """
- firstServer = MyServerFactory()
- firstServer.protocolConnectionMade = Deferred()
-
- server = MyServerFactory()
- server.protocolConnectionMade = Deferred()
- server.protocolConnectionLost = Deferred()
-
- client = MyClientFactory()
- client.protocolConnectionMade = Deferred()
- client.protocolConnectionLost = Deferred()
-
- port = reactor.listenTCP(0, firstServer, interface=interface)
-
- def firtServerConnected(proto):
- reactor.removeReader(proto.transport)
- reactor.removeWriter(proto.transport)
- reactor.adoptStreamConnection(
- proto.transport.fileno(), addressFamily, server)
-
- firstServer.protocolConnectionMade.addCallback(firtServerConnected)
-
- lostDeferred = gatherResults([client.protocolConnectionLost,
- server.protocolConnectionLost])
- def stop(result):
- if reactor.running:
- reactor.stop()
- return result
-
- lostDeferred.addBoth(stop)
-
- deferred = Deferred()
- deferred.addErrback(stop)
-
- startDeferred = gatherResults([client.protocolConnectionMade,
- server.protocolConnectionMade])
- def start(protocols):
- client, server = protocols
- log.msg("client connected %s" % client)
- log.msg("server connected %s" % server)
- deferred.callback((client, server, port))
-
- startDeferred.addCallback(start)
-
- reactor.connectTCP(interface, port.getHost().port, client)
- return deferred
-
-
-
-globals().update(TCP4ClientTestsBuilder.makeTestCaseClasses())
-globals().update(TCP6ClientTestsBuilder.makeTestCaseClasses())
-globals().update(TCPPortTestsBuilder.makeTestCaseClasses())
-globals().update(TCPFDPortTestsBuilder.makeTestCaseClasses())
-globals().update(TCPConnectionTestsBuilder.makeTestCaseClasses())
-globals().update(TCP4ConnectorTestsBuilder.makeTestCaseClasses())
-globals().update(TCP6ConnectorTestsBuilder.makeTestCaseClasses())
-globals().update(TCPTransportTestsBuilder.makeTestCaseClasses())
-globals().update(AdoptStreamConnectionTestsBuilder.makeTestCaseClasses())
-
-
-
-class ServerAbortsTwice(ConnectableProtocol):
- """
- Call abortConnection() twice.
- """
-
- def dataReceived(self, data):
- self.transport.abortConnection()
- self.transport.abortConnection()
-
-
-
-class ServerAbortsThenLoses(ConnectableProtocol):
- """
- Call abortConnection() followed by loseConnection().
- """
-
- def dataReceived(self, data):
- self.transport.abortConnection()
- self.transport.loseConnection()
-
-
-
-class AbortServerWritingProtocol(ConnectableProtocol):
- """
- Protocol that writes data upon connection.
- """
-
- def connectionMade(self):
- """
- Tell the client that the connection is set up and it's time to abort.
- """
- self.transport.write("ready")
-
-
-
-class ReadAbortServerProtocol(AbortServerWritingProtocol):
- """
- Server that should never receive any data, except 'X's which are written
- by the other side of the connection before abortConnection, and so might
- possibly arrive.
- """
-
- def dataReceived(self, data):
- if data.replace('X', ''):
- raise Exception("Unexpectedly received data.")
-
-
-
-class NoReadServer(ConnectableProtocol):
- """
- Stop reading immediately on connection.
-
- This simulates a lost connection that will cause the other side to time
- out, and therefore call abortConnection().
- """
-
- def connectionMade(self):
- self.transport.stopReading()
-
-
-
-class EventualNoReadServer(ConnectableProtocol):
- """
- Like NoReadServer, except we Wait until some bytes have been delivered
- before stopping reading. This means TLS handshake has finished, where
- applicable.
- """
-
- gotData = False
- stoppedReading = False
-
-
- def dataReceived(self, data):
- if not self.gotData:
- self.gotData = True
- self.transport.registerProducer(self, False)
- self.transport.write("hello")
-
-
- def resumeProducing(self):
- if self.stoppedReading:
- return
- self.stoppedReading = True
- # We've written out the data:
- self.transport.stopReading()
-
-
- def pauseProducing(self):
- pass
-
-
- def stopProducing(self):
- pass
-
-
-
-class BaseAbortingClient(ConnectableProtocol):
- """
- Base class for abort-testing clients.
- """
- inReactorMethod = False
-
- def connectionLost(self, reason):
- if self.inReactorMethod:
- raise RuntimeError("BUG: connectionLost was called re-entrantly!")
- ConnectableProtocol.connectionLost(self, reason)
-
-
-
-class WritingButNotAbortingClient(BaseAbortingClient):
- """
- Write data, but don't abort.
- """
-
- def connectionMade(self):
- self.transport.write("hello")
-
-
-
-class AbortingClient(BaseAbortingClient):
- """
- Call abortConnection() after writing some data.
- """
-
- def dataReceived(self, data):
- """
- Some data was received, so the connection is set up.
- """
- self.inReactorMethod = True
- self.writeAndAbort()
- self.inReactorMethod = False
-
-
- def writeAndAbort(self):
- # X is written before abortConnection, and so there is a chance it
- # might arrive. Y is written after, and so no Ys should ever be
- # delivered:
- self.transport.write("X" * 10000)
- self.transport.abortConnection()
- self.transport.write("Y" * 10000)
-
-
-
-class AbortingTwiceClient(AbortingClient):
- """
- Call abortConnection() twice, after writing some data.
- """
-
- def writeAndAbort(self):
- AbortingClient.writeAndAbort(self)
- self.transport.abortConnection()
-
-
-
-class AbortingThenLosingClient(AbortingClient):
- """
- Call abortConnection() and then loseConnection().
- """
-
- def writeAndAbort(self):
- AbortingClient.writeAndAbort(self)
- self.transport.loseConnection()
-
-
-
-class ProducerAbortingClient(ConnectableProtocol):
- """
- Call abortConnection from doWrite, via resumeProducing.
- """
-
- inReactorMethod = True
- producerStopped = False
-
- def write(self):
- self.transport.write("lalala" * 127000)
- self.inRegisterProducer = True
- self.transport.registerProducer(self, False)
- self.inRegisterProducer = False
-
-
- def connectionMade(self):
- self.write()
-
-
- def resumeProducing(self):
- self.inReactorMethod = True
- if not self.inRegisterProducer:
- self.transport.abortConnection()
- self.inReactorMethod = False
-
-
- def stopProducing(self):
- self.producerStopped = True
-
-
- def connectionLost(self, reason):
- if not self.producerStopped:
- raise RuntimeError("BUG: stopProducing() was never called.")
- if self.inReactorMethod:
- raise RuntimeError("BUG: connectionLost called re-entrantly!")
- ConnectableProtocol.connectionLost(self, reason)
-
-
-
-class StreamingProducerClient(ConnectableProtocol):
- """
- Call abortConnection() when the other side has stopped reading.
-
- In particular, we want to call abortConnection() only once our local
- socket hits a state where it is no longer writeable. This helps emulate
- the most common use case for abortConnection(), closing a connection after
- a timeout, with write buffers being full.
-
- Since it's very difficult to know when this actually happens, we just
- write a lot of data, and assume at that point no more writes will happen.
- """
- paused = False
- extraWrites = 0
- inReactorMethod = False
-
- def connectionMade(self):
- self.write()
-
-
- def write(self):
- """
- Write large amount to transport, then wait for a while for buffers to
- fill up.
- """
- self.transport.registerProducer(self, True)
- for i in range(100):
- self.transport.write("1234567890" * 32000)
-
-
- def resumeProducing(self):
- self.paused = False
-
-
- def stopProducing(self):
- pass
-
-
- def pauseProducing(self):
- """
- Called when local buffer fills up.
-
- The goal is to hit the point where the local file descriptor is not
- writeable (or the moral equivalent). The fact that pauseProducing has
- been called is not sufficient, since that can happen when Twisted's
- buffers fill up but OS hasn't gotten any writes yet. We want to be as
- close as possible to every buffer (including OS buffers) being full.
-
- So, we wait a bit more after this for Twisted to write out a few
- chunks, then abortConnection.
- """
- if self.paused:
- return
- self.paused = True
- # The amount we wait is arbitrary, we just want to make sure some
- # writes have happened and outgoing OS buffers filled up -- see
- # http://twistedmatrix.com/trac/ticket/5303 for details:
- self.reactor.callLater(0.01, self.doAbort)
-
-
- def doAbort(self):
- if not self.paused:
- log.err(RuntimeError("BUG: We should be paused a this point."))
- self.inReactorMethod = True
- self.transport.abortConnection()
- self.inReactorMethod = False
-
-
- def connectionLost(self, reason):
- # Tell server to start reading again so it knows to go away:
- self.otherProtocol.transport.startReading()
- ConnectableProtocol.connectionLost(self, reason)
-
-
-
-class StreamingProducerClientLater(StreamingProducerClient):
- """
- Call abortConnection() from dataReceived, after bytes have been
- exchanged.
- """
-
- def connectionMade(self):
- self.transport.write("hello")
- self.gotData = False
-
-
- def dataReceived(self, data):
- if not self.gotData:
- self.gotData = True
- self.write()
-
-
-class ProducerAbortingClientLater(ProducerAbortingClient):
- """
- Call abortConnection from doWrite, via resumeProducing.
-
- Try to do so after some bytes have already been exchanged, so we
- don't interrupt SSL handshake.
- """
-
- def connectionMade(self):
- # Override base class connectionMade().
- pass
-
-
- def dataReceived(self, data):
- self.write()
-
-
-
-class DataReceivedRaisingClient(AbortingClient):
- """
- Call abortConnection(), and then throw exception, from dataReceived.
- """
-
- def dataReceived(self, data):
- self.transport.abortConnection()
- raise ZeroDivisionError("ONO")
-
-
-
-class ResumeThrowsClient(ProducerAbortingClient):
- """
- Call abortConnection() and throw exception from resumeProducing().
- """
-
- def resumeProducing(self):
- if not self.inRegisterProducer:
- self.transport.abortConnection()
- raise ZeroDivisionError("ono!")
-
-
- def connectionLost(self, reason):
- # Base class assertion about stopProducing being called isn't valid;
- # if the we blew up in resumeProducing, consumers are justified in
- # giving up on the producer and not calling stopProducing.
- ConnectableProtocol.connectionLost(self, reason)
-
-
-
-class AbortConnectionMixin(object):
- """
- Unit tests for L{ITransport.abortConnection}.
- """
- # Override in subclasses, should be a EndpointCreator instance:
- endpoints = None
-
- def runAbortTest(self, clientClass, serverClass,
- clientConnectionLostReason=None):
- """
- A test runner utility function, which hooks up a matched pair of client
- and server protocols.
-
- We then run the reactor until both sides have disconnected, and then
- verify that the right exception resulted.
- """
- clientExpectedExceptions = (ConnectionAborted, ConnectionLost)
- serverExpectedExceptions = (ConnectionLost, ConnectionDone)
- # In TLS tests we may get SSL.Error instead of ConnectionLost,
- # since we're trashing the TLS protocol layer.
- if useSSL:
- clientExpectedExceptions = clientExpectedExceptions + (SSL.Error,)
- serverExpectedExceptions = serverExpectedExceptions + (SSL.Error,)
-
- client = clientClass()
- server = serverClass()
- client.otherProtocol = server
- server.otherProtocol = client
- reactor = runProtocolsWithReactor(self, server, client, self.endpoints)
-
- # Make sure everything was shutdown correctly:
- self.assertEqual(reactor.removeAll(), [])
- # The reactor always has a timeout added in runReactor():
- delayedCalls = reactor.getDelayedCalls()
- self.assertEqual(len(delayedCalls), 1, map(str, delayedCalls))
-
- if clientConnectionLostReason is not None:
- self.assertIsInstance(
- client.disconnectReason.value,
- (clientConnectionLostReason,) + clientExpectedExceptions)
- else:
- self.assertIsInstance(client.disconnectReason.value,
- clientExpectedExceptions)
- self.assertIsInstance(server.disconnectReason.value, serverExpectedExceptions)
-
-
- def test_dataReceivedAbort(self):
- """
- abortConnection() is called in dataReceived. The protocol should be
- disconnected, but connectionLost should not be called re-entrantly.
- """
- return self.runAbortTest(AbortingClient, ReadAbortServerProtocol)
-
-
- def test_clientAbortsConnectionTwice(self):
- """
- abortConnection() is called twice by client.
-
- No exception should be thrown, and the connection will be closed.
- """
- return self.runAbortTest(AbortingTwiceClient, ReadAbortServerProtocol)
-
-
- def test_clientAbortsConnectionThenLosesConnection(self):
- """
- Client calls abortConnection(), followed by loseConnection().
-
- No exception should be thrown, and the connection will be closed.
- """
- return self.runAbortTest(AbortingThenLosingClient,
- ReadAbortServerProtocol)
-
-
- def test_serverAbortsConnectionTwice(self):
- """
- abortConnection() is called twice by server.
-
- No exception should be thrown, and the connection will be closed.
- """
- return self.runAbortTest(WritingButNotAbortingClient, ServerAbortsTwice,
- clientConnectionLostReason=ConnectionLost)
-
-
- def test_serverAbortsConnectionThenLosesConnection(self):
- """
- Server calls abortConnection(), followed by loseConnection().
-
- No exception should be thrown, and the connection will be closed.
- """
- return self.runAbortTest(WritingButNotAbortingClient,
- ServerAbortsThenLoses,
- clientConnectionLostReason=ConnectionLost)
-
-
- def test_resumeProducingAbort(self):
- """
- abortConnection() is called in resumeProducing, before any bytes have
- been exchanged. The protocol should be disconnected, but
- connectionLost should not be called re-entrantly.
- """
- self.runAbortTest(ProducerAbortingClient,
- ConnectableProtocol)
-
-
- def test_resumeProducingAbortLater(self):
- """
- abortConnection() is called in resumeProducing, after some
- bytes have been exchanged. The protocol should be disconnected.
- """
- return self.runAbortTest(ProducerAbortingClientLater,
- AbortServerWritingProtocol)
-
-
- def test_fullWriteBuffer(self):
- """
- abortConnection() triggered by the write buffer being full.
-
- In particular, the server side stops reading. This is supposed
- to simulate a realistic timeout scenario where the client
- notices the server is no longer accepting data.
-
- The protocol should be disconnected, but connectionLost should not be
- called re-entrantly.
- """
- self.runAbortTest(StreamingProducerClient,
- NoReadServer)
-
-
- def test_fullWriteBufferAfterByteExchange(self):
- """
- abortConnection() is triggered by a write buffer being full.
-
- However, this buffer is filled after some bytes have been exchanged,
- allowing a TLS handshake if we're testing TLS. The connection will
- then be lost.
- """
- return self.runAbortTest(StreamingProducerClientLater,
- EventualNoReadServer)
-
-
- def test_dataReceivedThrows(self):
- """
- dataReceived calls abortConnection(), and then raises an exception.
-
- The connection will be lost, with the thrown exception
- (C{ZeroDivisionError}) as the reason on the client. The idea here is
- that bugs should not be masked by abortConnection, in particular
- unexpected exceptions.
- """
- self.runAbortTest(DataReceivedRaisingClient,
- AbortServerWritingProtocol,
- clientConnectionLostReason=ZeroDivisionError)
- errors = self.flushLoggedErrors(ZeroDivisionError)
- self.assertEqual(len(errors), 1)
-
-
- def test_resumeProducingThrows(self):
- """
- resumeProducing calls abortConnection(), and then raises an exception.
-
- The connection will be lost, with the thrown exception
- (C{ZeroDivisionError}) as the reason on the client. The idea here is
- that bugs should not be masked by abortConnection, in particular
- unexpected exceptions.
- """
- self.runAbortTest(ResumeThrowsClient,
- ConnectableProtocol,
- clientConnectionLostReason=ZeroDivisionError)
- errors = self.flushLoggedErrors(ZeroDivisionError)
- self.assertEqual(len(errors), 1)
-
-
-
-class AbortConnectionTestCase(ReactorBuilder, AbortConnectionMixin):
- """
- TCP-specific L{AbortConnectionMixin} tests.
- """
- requiredInterfaces = (IReactorTCP,)
-
- endpoints = TCPCreator()
-
-globals().update(AbortConnectionTestCase.makeTestCaseClasses())
-
-
-
-class SimpleUtilityTestCase(TestCase):
- """
- Simple, direct tests for helpers within L{twisted.internet.tcp}.
- """
- if ipv6Skip:
- skip = ipv6Skip
-
- def test_resolveNumericHost(self):
- """
- L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
- invoked with a non-numeric host. (In other words, it is passing
- L{socket.AI_NUMERICHOST} to L{socket.getaddrinfo} and will not
- accidentally block if it receives bad input.)
- """
- err = self.assertRaises(socket.gaierror, _resolveIPv6, "localhost", 1)
- self.assertEqual(err.args[0], socket.EAI_NONAME)
-
-
- def test_resolveNumericService(self):
- """
- L{_resolveIPv6} raises a L{socket.gaierror} (L{socket.EAI_NONAME}) when
- invoked with a non-numeric port. (In other words, it is passing
- L{socket.AI_NUMERICSERV} to L{socket.getaddrinfo} and will not
- accidentally block if it receives bad input.)
- """
- err = self.assertRaises(socket.gaierror, _resolveIPv6, "::1", "http")
- self.assertEqual(err.args[0], socket.EAI_NONAME)
-
- if platform.isWindows():
- test_resolveNumericService.skip = ("The AI_NUMERICSERV flag is not "
- "supported by Microsoft providers.")
- # http://msdn.microsoft.com/en-us/library/windows/desktop/ms738520.aspx
-
-
- def test_resolveIPv6(self):
- """
- L{_resolveIPv6} discovers the flow info and scope ID of an IPv6
- address.
- """
- result = _resolveIPv6("::1", 2)
- self.assertEqual(len(result), 4)
- # We can't say anything more useful about these than that they're
- # integers, because the whole point of getaddrinfo is that you can never
- # know a-priori know _anything_ about the network interfaces of the
- # computer that you're on and you have to ask it.
- self.assertIsInstance(result[2], int) # flow info
- self.assertIsInstance(result[3], int) # scope id
- # but, luckily, IP presentation format and what it means to be a port
- # number are a little better specified.
- self.assertEqual(result[:2], ("::1", 2))
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_threads.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_threads.py
deleted file mode 100755
index 00683a31..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_threads.py
+++ /dev/null
@@ -1,218 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorThreads}.
-"""
-
-__metaclass__ = type
-
-from weakref import ref
-import gc, threading
-
-from twisted.python.threadable import isInIOThread
-from twisted.internet.test.reactormixins import ReactorBuilder
-from twisted.python.threadpool import ThreadPool
-from twisted.internet.interfaces import IReactorThreads
-
-
-class ThreadTestsBuilder(ReactorBuilder):
- """
- Builder for defining tests relating to L{IReactorThreads}.
- """
- requiredInterfaces = (IReactorThreads,)
-
- def test_getThreadPool(self):
- """
- C{reactor.getThreadPool()} returns an instance of L{ThreadPool} which
- starts when C{reactor.run()} is called and stops before it returns.
- """
- state = []
- reactor = self.buildReactor()
-
- pool = reactor.getThreadPool()
- self.assertIsInstance(pool, ThreadPool)
- self.assertFalse(
- pool.started, "Pool should not start before reactor.run")
-
- def f():
- # Record the state for later assertions
- state.append(pool.started)
- state.append(pool.joined)
- reactor.stop()
-
- reactor.callWhenRunning(f)
- self.runReactor(reactor, 2)
-
- self.assertTrue(
- state[0], "Pool should start after reactor.run")
- self.assertFalse(
- state[1], "Pool should not be joined before reactor.stop")
- self.assertTrue(
- pool.joined,
- "Pool should be stopped after reactor.run returns")
-
-
- def test_suggestThreadPoolSize(self):
- """
- C{reactor.suggestThreadPoolSize()} sets the maximum size of the reactor
- threadpool.
- """
- reactor = self.buildReactor()
- reactor.suggestThreadPoolSize(17)
- pool = reactor.getThreadPool()
- self.assertEqual(pool.max, 17)
-
-
- def test_delayedCallFromThread(self):
- """
- A function scheduled with L{IReactorThreads.callFromThread} invoked
- from a delayed call is run immediately in the next reactor iteration.
-
- When invoked from the reactor thread, previous implementations of
- L{IReactorThreads.callFromThread} would skip the pipe/socket based wake
- up step, assuming the reactor would wake up on its own. However, this
- resulted in the reactor not noticing a insert into the thread queue at
- the right time (in this case, after the thread queue has been processed
- for that reactor iteration).
- """
- reactor = self.buildReactor()
-
- def threadCall():
- reactor.stop()
-
- # Set up the use of callFromThread being tested.
- reactor.callLater(0, reactor.callFromThread, threadCall)
-
- before = reactor.seconds()
- self.runReactor(reactor, 60)
- after = reactor.seconds()
-
- # We specified a timeout of 60 seconds. The timeout code in runReactor
- # probably won't actually work, though. If the reactor comes out of
- # the event notification API just a little bit early, say after 59.9999
- # seconds instead of after 60 seconds, then the queued thread call will
- # get processed but the timeout delayed call runReactor sets up won't!
- # Then the reactor will stop and runReactor will return without the
- # timeout firing. As it turns out, select() and poll() are quite
- # likely to return *slightly* earlier than we ask them to, so the
- # timeout will rarely happen, even if callFromThread is broken. So,
- # instead we'll measure the elapsed time and make sure it's something
- # less than about half of the timeout we specified. This is heuristic.
- # It assumes that select() won't ever return after 30 seconds when we
- # asked it to timeout after 60 seconds. And of course like all
- # time-based tests, it's slightly non-deterministic. If the OS doesn't
- # schedule this process for 30 seconds, then the test might fail even
- # if callFromThread is working.
- self.assertTrue(after - before < 30)
-
-
- def test_callFromThread(self):
- """
- A function scheduled with L{IReactorThreads.callFromThread} invoked
- from another thread is run in the reactor thread.
- """
- reactor = self.buildReactor()
- result = []
-
- def threadCall():
- result.append(threading.currentThread())
- reactor.stop()
- reactor.callLater(0, reactor.callInThread,
- reactor.callFromThread, threadCall)
- self.runReactor(reactor, 5)
-
- self.assertEquals(result, [threading.currentThread()])
-
-
- def test_stopThreadPool(self):
- """
- When the reactor stops, L{ReactorBase._stopThreadPool} drops the
- reactor's direct reference to its internal threadpool and removes
- the associated startup and shutdown triggers.
-
- This is the case of the thread pool being created before the reactor
- is run.
- """
- reactor = self.buildReactor()
- threadpool = ref(reactor.getThreadPool())
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- gc.collect()
- self.assertIdentical(threadpool(), None)
-
-
- def test_stopThreadPoolWhenStartedAfterReactorRan(self):
- """
- We must handle the case of shutting down the thread pool when it was
- started after the reactor was run in a special way.
-
- Some implementation background: The thread pool is started with
- callWhenRunning, which only returns a system trigger ID when it is
- invoked before the reactor is started.
-
- This is the case of the thread pool being created after the reactor
- is started.
- """
- reactor = self.buildReactor()
- threadPoolRefs = []
- def acquireThreadPool():
- threadPoolRefs.append(ref(reactor.getThreadPool()))
- reactor.stop()
- reactor.callWhenRunning(acquireThreadPool)
- self.runReactor(reactor)
- gc.collect()
- self.assertIdentical(threadPoolRefs[0](), None)
-
-
- def test_cleanUpThreadPoolEvenBeforeReactorIsRun(self):
- """
- When the reactor has its shutdown event fired before it is run, the
- thread pool is completely destroyed.
-
- For what it's worth, the reason we support this behavior at all is
- because Trial does this.
-
- This is the case of the thread pool being created without the reactor
- being started at al.
- """
- reactor = self.buildReactor()
- threadPoolRef = ref(reactor.getThreadPool())
- reactor.fireSystemEvent("shutdown")
- gc.collect()
- self.assertIdentical(threadPoolRef(), None)
-
-
- def test_isInIOThread(self):
- """
- The reactor registers itself as the I/O thread when it runs so that
- L{twisted.python.threadable.isInIOThread} returns C{True} if it is
- called in the thread the reactor is running in.
- """
- results = []
- reactor = self.buildReactor()
- def check():
- results.append(isInIOThread())
- reactor.stop()
- reactor.callWhenRunning(check)
- self.runReactor(reactor)
- self.assertEqual([True], results)
-
-
- def test_isNotInIOThread(self):
- """
- The reactor registers itself as the I/O thread when it runs so that
- L{twisted.python.threadable.isInIOThread} returns C{False} if it is
- called in a different thread than the reactor is running in.
- """
- results = []
- reactor = self.buildReactor()
- def check():
- results.append(isInIOThread())
- reactor.callFromThread(reactor.stop)
- reactor.callInThread(check)
- self.runReactor(reactor)
- self.assertEqual([False], results)
-
-
-globals().update(ThreadTestsBuilder.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_time.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_time.py
deleted file mode 100755
index b6f9e1db..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_time.py
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorTime}.
-"""
-
-__metaclass__ = type
-
-from twisted.python.runtime import platform
-from twisted.internet.test.reactormixins import ReactorBuilder
-from twisted.internet.interfaces import IReactorTime
-
-
-class TimeTestsBuilder(ReactorBuilder):
- """
- Builder for defining tests relating to L{IReactorTime}.
- """
- requiredInterfaces = (IReactorTime,)
-
- def test_delayedCallStopsReactor(self):
- """
- The reactor can be stopped by a delayed call.
- """
- reactor = self.buildReactor()
- reactor.callLater(0, reactor.stop)
- reactor.run()
-
-
-
-class GlibTimeTestsBuilder(ReactorBuilder):
- """
- Builder for defining tests relating to L{IReactorTime} for reactors based
- off glib.
- """
- requiredInterfaces = (IReactorTime,)
-
- if platform.isWindows():
- _reactors = ["twisted.internet.gtk2reactor.PortableGtkReactor"]
- else:
- _reactors = ["twisted.internet.glib2reactor.Glib2Reactor",
- "twisted.internet.gtk2reactor.Gtk2Reactor"]
-
- def test_timeout_add(self):
- """
- A C{reactor.callLater} call scheduled from a C{gobject.timeout_add}
- call is run on time.
- """
- import gobject
- reactor = self.buildReactor()
-
- result = []
- def gschedule():
- reactor.callLater(0, callback)
- return 0
- def callback():
- result.append(True)
- reactor.stop()
-
- reactor.callWhenRunning(gobject.timeout_add, 10, gschedule)
- self.runReactor(reactor, 5)
- self.assertEqual(result, [True])
-
-
-globals().update(TimeTestsBuilder.makeTestCaseClasses())
-globals().update(GlibTimeTestsBuilder.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tls.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tls.py
deleted file mode 100755
index 223d5f68..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_tls.py
+++ /dev/null
@@ -1,432 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{ITLSTransport}.
-"""
-
-__metaclass__ = type
-
-import sys, operator
-
-from zope.interface import implements
-
-from twisted.internet.test.reactormixins import ReactorBuilder, EndpointCreator
-from twisted.internet.protocol import ServerFactory, ClientFactory, Protocol
-from twisted.internet.interfaces import (
- IReactorSSL, ITLSTransport, IStreamClientEndpoint)
-from twisted.internet.defer import Deferred, DeferredList
-from twisted.internet.endpoints import (
- SSL4ServerEndpoint, SSL4ClientEndpoint, TCP4ClientEndpoint)
-from twisted.internet.error import ConnectionClosed
-from twisted.internet.task import Cooperator
-from twisted.trial.unittest import TestCase, SkipTest
-from twisted.python.runtime import platform
-
-from twisted.internet.test.test_core import ObjectModelIntegrationMixin
-from twisted.internet.test.test_tcp import (
- StreamTransportTestsMixin, AbortConnectionMixin)
-from twisted.internet.test.connectionmixins import ConnectionTestsMixin
-from twisted.internet.test.connectionmixins import BrokenContextFactory
-
-try:
- from OpenSSL.crypto import FILETYPE_PEM
-except ImportError:
- FILETYPE_PEM = None
-else:
- from twisted.internet.ssl import PrivateCertificate, KeyPair
- from twisted.internet.ssl import ClientContextFactory
-
-
-class TLSMixin:
- requiredInterfaces = [IReactorSSL]
-
- if platform.isWindows():
- msg = (
- "For some reason, these reactors don't deal with SSL "
- "disconnection correctly on Windows. See #3371.")
- skippedReactors = {
- "twisted.internet.glib2reactor.Glib2Reactor": msg,
- "twisted.internet.gtk2reactor.Gtk2Reactor": msg}
-
-
-class ContextGeneratingMixin(object):
- _certificateText = (
- "-----BEGIN CERTIFICATE-----\n"
- "MIIDBjCCAm+gAwIBAgIBATANBgkqhkiG9w0BAQQFADB7MQswCQYDVQQGEwJTRzER\n"
- "MA8GA1UEChMITTJDcnlwdG8xFDASBgNVBAsTC00yQ3J5cHRvIENBMSQwIgYDVQQD\n"
- "ExtNMkNyeXB0byBDZXJ0aWZpY2F0ZSBNYXN0ZXIxHTAbBgkqhkiG9w0BCQEWDm5n\n"
- "cHNAcG9zdDEuY29tMB4XDTAwMDkxMDA5NTEzMFoXDTAyMDkxMDA5NTEzMFowUzEL\n"
- "MAkGA1UEBhMCU0cxETAPBgNVBAoTCE0yQ3J5cHRvMRIwEAYDVQQDEwlsb2NhbGhv\n"
- "c3QxHTAbBgkqhkiG9w0BCQEWDm5ncHNAcG9zdDEuY29tMFwwDQYJKoZIhvcNAQEB\n"
- "BQADSwAwSAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh\n"
- "5kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEAAaOCAQQwggEAMAkGA1UdEwQC\n"
- "MAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRl\n"
- "MB0GA1UdDgQWBBTPhIKSvnsmYsBVNWjj0m3M2z0qVTCBpQYDVR0jBIGdMIGagBT7\n"
- "hyNp65w6kxXlxb8pUU/+7Sg4AaF/pH0wezELMAkGA1UEBhMCU0cxETAPBgNVBAoT\n"
- "CE0yQ3J5cHRvMRQwEgYDVQQLEwtNMkNyeXB0byBDQTEkMCIGA1UEAxMbTTJDcnlw\n"
- "dG8gQ2VydGlmaWNhdGUgTWFzdGVyMR0wGwYJKoZIhvcNAQkBFg5uZ3BzQHBvc3Qx\n"
- "LmNvbYIBADANBgkqhkiG9w0BAQQFAAOBgQA7/CqT6PoHycTdhEStWNZde7M/2Yc6\n"
- "BoJuVwnW8YxGO8Sn6UJ4FeffZNcYZddSDKosw8LtPOeWoK3JINjAk5jiPQ2cww++\n"
- "7QGG/g5NDjxFZNDJP1dGiLAxPW6JXwov4v0FmdzfLOZ01jDcgQQZqEpYlgpuI5JE\n"
- "WUQ9Ho4EzbYCOQ==\n"
- "-----END CERTIFICATE-----\n")
-
- _privateKeyText = (
- "-----BEGIN RSA PRIVATE KEY-----\n"
- "MIIBPAIBAAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh\n"
- "5kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEAAQJBAIqm/bz4NA1H++Vx5Ewx\n"
- "OcKp3w19QSaZAwlGRtsUxrP7436QjnREM3Bm8ygU11BjkPVmtrKm6AayQfCHqJoT\n"
- "ZIECIQDW0BoMoL0HOYM/mrTLhaykYAVqgIeJsPjvkEhTFXWBuQIhAM3deFAvWNu4\n"
- "nklUQ37XsCT2c9tmNt1LAT+slG2JOTTRAiAuXDtC/m3NYVwyHfFm+zKHRzHkClk2\n"
- "HjubeEgjpj32AQIhAJqMGTaZVOwevTXvvHwNEH+vRWsAYU/gbx+OQB+7VOcBAiEA\n"
- "oolb6NMg/R3enNPvS1O4UU1H8wpaF77L4yiSWlE0p4w=\n"
- "-----END RSA PRIVATE KEY-----\n")
-
-
- def getServerContext(self):
- """
- Return a new SSL context suitable for use in a test server.
- """
- cert = PrivateCertificate.load(
- self._certificateText,
- KeyPair.load(self._privateKeyText, FILETYPE_PEM),
- FILETYPE_PEM)
- return cert.options()
-
-
- def getClientContext(self):
- return ClientContextFactory()
-
-
-
-class StartTLSClientEndpoint(object):
- """
- An endpoint which wraps another one and adds a TLS layer immediately when
- connections are set up.
-
- @ivar wrapped: A L{IStreamClientEndpoint} provider which will be used to
- really set up connections.
-
- @ivar contextFactory: A L{ContextFactory} to use to do TLS.
- """
- implements(IStreamClientEndpoint)
-
- def __init__(self, wrapped, contextFactory):
- self.wrapped = wrapped
- self.contextFactory = contextFactory
-
-
- def connect(self, factory):
- """
- Establish a connection using a protocol build by C{factory} and
- immediately start TLS on it. Return a L{Deferred} which fires with the
- protocol instance.
- """
- # This would be cleaner when we have ITransport.switchProtocol, which
- # will be added with ticket #3204:
- class WrapperFactory(ServerFactory):
- def buildProtocol(wrapperSelf, addr):
- protocol = factory.buildProtocol(addr)
- def connectionMade(orig=protocol.connectionMade):
- protocol.transport.startTLS(self.contextFactory)
- orig()
- protocol.connectionMade = connectionMade
- return protocol
-
- return self.wrapped.connect(WrapperFactory())
-
-
-
-class StartTLSClientCreator(EndpointCreator, ContextGeneratingMixin):
- """
- Create L{ITLSTransport.startTLS} endpoint for the client, and normal SSL
- for server just because it's easier.
- """
- def server(self, reactor):
- """
- Construct an SSL server endpoint. This should be be constructing a TCP
- server endpoint which immediately calls C{startTLS} instead, but that
- is hard.
- """
- return SSL4ServerEndpoint(reactor, 0, self.getServerContext())
-
-
- def client(self, reactor, serverAddress):
- """
- Construct a TCP client endpoint wrapped to immediately start TLS.
- """
- return StartTLSClientEndpoint(
- TCP4ClientEndpoint(
- reactor, '127.0.0.1', serverAddress.port),
- ClientContextFactory())
-
-
-
-class BadContextTestsMixin(object):
- """
- Mixin for L{ReactorBuilder} subclasses which defines a helper for testing
- the handling of broken context factories.
- """
- def _testBadContext(self, useIt):
- """
- Assert that the exception raised by a broken context factory's
- C{getContext} method is raised by some reactor method. If it is not, an
- exception will be raised to fail the test.
-
- @param useIt: A two-argument callable which will be called with a
- reactor and a broken context factory and which is expected to raise
- the same exception as the broken context factory's C{getContext}
- method.
- """
- reactor = self.buildReactor()
- exc = self.assertRaises(
- ValueError, useIt, reactor, BrokenContextFactory())
- self.assertEqual(BrokenContextFactory.message, str(exc))
-
-
-
-class StartTLSClientTestsMixin(TLSMixin, ReactorBuilder, ConnectionTestsMixin):
- """
- Tests for TLS connections established using L{ITLSTransport.startTLS} (as
- opposed to L{IReactorSSL.connectSSL} or L{IReactorSSL.listenSSL}).
- """
- endpoints = StartTLSClientCreator()
-
-
-
-class SSLCreator(EndpointCreator, ContextGeneratingMixin):
- """
- Create SSL endpoints.
- """
- def server(self, reactor):
- """
- Create an SSL server endpoint on a TCP/IP-stack allocated port.
- """
- return SSL4ServerEndpoint(reactor, 0, self.getServerContext())
-
-
- def client(self, reactor, serverAddress):
- """
- Create an SSL client endpoint which will connect localhost on
- the port given by C{serverAddress}.
-
- @type serverAddress: L{IPv4Address}
- """
- return SSL4ClientEndpoint(
- reactor, '127.0.0.1', serverAddress.port,
- ClientContextFactory())
-
-
-class SSLClientTestsMixin(TLSMixin, ReactorBuilder, ContextGeneratingMixin,
- ConnectionTestsMixin, BadContextTestsMixin):
- """
- Mixin defining tests relating to L{ITLSTransport}.
- """
- endpoints = SSLCreator()
-
- def test_badContext(self):
- """
- If the context factory passed to L{IReactorSSL.connectSSL} raises an
- exception from its C{getContext} method, that exception is raised by
- L{IReactorSSL.connectSSL}.
- """
- def useIt(reactor, contextFactory):
- return reactor.connectSSL(
- "127.0.0.1", 1234, ClientFactory(), contextFactory)
- self._testBadContext(useIt)
-
-
- def test_disconnectAfterWriteAfterStartTLS(self):
- """
- L{ITCPTransport.loseConnection} ends a connection which was set up with
- L{ITLSTransport.startTLS} and which has recently been written to. This
- is intended to verify that a socket send error masked by the TLS
- implementation doesn't prevent the connection from being reported as
- closed.
- """
- class ShortProtocol(Protocol):
- def connectionMade(self):
- if not ITLSTransport.providedBy(self.transport):
- # Functionality isn't available to be tested.
- finished = self.factory.finished
- self.factory.finished = None
- finished.errback(SkipTest("No ITLSTransport support"))
- return
-
- # Switch the transport to TLS.
- self.transport.startTLS(self.factory.context)
- # Force TLS to really get negotiated. If nobody talks, nothing
- # will happen.
- self.transport.write("x")
-
- def dataReceived(self, data):
- # Stuff some bytes into the socket. This mostly has the effect
- # of causing the next write to fail with ENOTCONN or EPIPE.
- # With the pyOpenSSL implementation of ITLSTransport, the error
- # is swallowed outside of the control of Twisted.
- self.transport.write("y")
- # Now close the connection, which requires a TLS close alert to
- # be sent.
- self.transport.loseConnection()
-
- def connectionLost(self, reason):
- # This is the success case. The client and the server want to
- # get here.
- finished = self.factory.finished
- if finished is not None:
- self.factory.finished = None
- finished.callback(reason)
-
- reactor = self.buildReactor()
-
- serverFactory = ServerFactory()
- serverFactory.finished = Deferred()
- serverFactory.protocol = ShortProtocol
- serverFactory.context = self.getServerContext()
-
- clientFactory = ClientFactory()
- clientFactory.finished = Deferred()
- clientFactory.protocol = ShortProtocol
- clientFactory.context = self.getClientContext()
- clientFactory.context.method = serverFactory.context.method
-
- lostConnectionResults = []
- finished = DeferredList(
- [serverFactory.finished, clientFactory.finished],
- consumeErrors=True)
- def cbFinished(results):
- lostConnectionResults.extend([results[0][1], results[1][1]])
- finished.addCallback(cbFinished)
-
- port = reactor.listenTCP(0, serverFactory, interface='127.0.0.1')
- self.addCleanup(port.stopListening)
-
- connector = reactor.connectTCP(
- port.getHost().host, port.getHost().port, clientFactory)
- self.addCleanup(connector.disconnect)
-
- finished.addCallback(lambda ign: reactor.stop())
- self.runReactor(reactor)
- lostConnectionResults[0].trap(ConnectionClosed)
- lostConnectionResults[1].trap(ConnectionClosed)
-
-
-
-class TLSPortTestsBuilder(TLSMixin, ContextGeneratingMixin,
- ObjectModelIntegrationMixin, BadContextTestsMixin,
- StreamTransportTestsMixin, ReactorBuilder):
- """
- Tests for L{IReactorSSL.listenSSL}
- """
- def getListeningPort(self, reactor, factory):
- """
- Get a TLS port from a reactor.
- """
- return reactor.listenSSL(0, factory, self.getServerContext())
-
-
- def getExpectedStartListeningLogMessage(self, port, factory):
- """
- Get the message expected to be logged when a TLS port starts listening.
- """
- return "%s (TLS) starting on %d" % (factory, port.getHost().port)
-
-
- def getExpectedConnectionLostLogMsg(self, port):
- """
- Get the expected connection lost message for a TLS port.
- """
- return "(TLS Port %s Closed)" % (port.getHost().port,)
-
-
- def test_badContext(self):
- """
- If the context factory passed to L{IReactorSSL.listenSSL} raises an
- exception from its C{getContext} method, that exception is raised by
- L{IReactorSSL.listenSSL}.
- """
- def useIt(reactor, contextFactory):
- return reactor.listenSSL(0, ServerFactory(), contextFactory)
- self._testBadContext(useIt)
-
-
-
-globals().update(SSLClientTestsMixin.makeTestCaseClasses())
-globals().update(StartTLSClientTestsMixin.makeTestCaseClasses())
-globals().update(TLSPortTestsBuilder().makeTestCaseClasses())
-
-
-
-class AbortSSLConnectionTest(ReactorBuilder, AbortConnectionMixin, ContextGeneratingMixin):
- """
- C{abortConnection} tests using SSL.
- """
- requiredInterfaces = (IReactorSSL,)
- endpoints = SSLCreator()
-
- def buildReactor(self):
- reactor = ReactorBuilder.buildReactor(self)
- try:
- from twisted.protocols import tls
- except ImportError:
- return reactor
-
- # Patch twisted.protocols.tls to use this reactor, until we get
- # around to fixing #5206, or the TLS code uses an explicit reactor:
- cooperator = Cooperator(
- scheduler=lambda x: reactor.callLater(0.00001, x))
- self.patch(tls, "cooperate", cooperator.cooperate)
- return reactor
-
-
- def setUp(self):
- if FILETYPE_PEM is None:
- raise SkipTest("OpenSSL not available.")
-
-globals().update(AbortSSLConnectionTest.makeTestCaseClasses())
-
-class OldTLSDeprecationTest(TestCase):
- """
- Tests for the deprecation of L{twisted.internet._oldtls}, the implementation
- module for L{IReactorSSL} used when only an old version of pyOpenSSL is
- available.
- """
- def test_warning(self):
- """
- The use of L{twisted.internet._oldtls} is deprecated, and emits a
- L{DeprecationWarning}.
- """
- # Since _oldtls depends on OpenSSL, just skip this test if it isn't
- # installed on the system. Faking it would be error prone.
- try:
- import OpenSSL
- except ImportError:
- raise SkipTest("OpenSSL not available.")
-
- # Change the apparent version of OpenSSL to one support for which is
- # deprecated. And have it change back again after the test.
- self.patch(OpenSSL, '__version__', '0.5')
-
- # If the module was already imported, the import statement below won't
- # execute its top-level code. Take it out of sys.modules so the import
- # system re-evaluates it. Arrange to put the original back afterwards.
- # Also handle the case where it hasn't yet been imported.
- try:
- oldtls = sys.modules['twisted.internet._oldtls']
- except KeyError:
- self.addCleanup(sys.modules.pop, 'twisted.internet._oldtls')
- else:
- del sys.modules['twisted.internet._oldtls']
- self.addCleanup(
- operator.setitem, sys.modules, 'twisted.internet._oldtls',
- oldtls)
-
- # The actual test.
- import twisted.internet._oldtls
- warnings = self.flushWarnings()
- self.assertEqual(warnings[0]['category'], DeprecationWarning)
- self.assertEqual(
- warnings[0]['message'],
- "Support for pyOpenSSL 0.5 is deprecated. "
- "Upgrade to pyOpenSSL 0.10 or newer.")
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp.py
deleted file mode 100755
index 8760a942..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp.py
+++ /dev/null
@@ -1,197 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorUDP}.
-"""
-
-__metaclass__ = type
-
-from socket import SOCK_DGRAM
-
-from zope.interface import implements
-from zope.interface.verify import verifyObject
-
-from twisted.python import context
-from twisted.python.log import ILogContext, err
-from twisted.internet.test.reactormixins import ReactorBuilder
-from twisted.internet.defer import Deferred, maybeDeferred
-from twisted.internet.interfaces import (
- ILoggingContext, IListeningPort, IReactorUDP)
-from twisted.internet.address import IPv4Address
-from twisted.internet.protocol import DatagramProtocol
-
-from twisted.internet.test.test_tcp import findFreePort
-from twisted.internet.test.connectionmixins import LogObserverMixin
-
-
-class UDPPortMixin(object):
- def getListeningPort(self, reactor, protocol):
- """
- Get a UDP port from a reactor.
- """
- return reactor.listenUDP(0, protocol)
-
-
- def getExpectedStartListeningLogMessage(self, port, protocol):
- """
- Get the message expected to be logged when a UDP port starts listening.
- """
- return "%s starting on %d" % (protocol, port.getHost().port)
-
-
- def getExpectedConnectionLostLogMessage(self, port):
- """
- Get the expected connection lost message for a UDP port.
- """
- return "(UDP Port %s Closed)" % (port.getHost().port,)
-
-
-
-class DatagramTransportTestsMixin(LogObserverMixin):
- """
- Mixin defining tests which apply to any port/datagram based transport.
- """
- def test_startedListeningLogMessage(self):
- """
- When a port starts, a message including a description of the associated
- protocol is logged.
- """
- loggedMessages = self.observe()
- reactor = self.buildReactor()
- class SomeProtocol(DatagramProtocol):
- implements(ILoggingContext)
- def logPrefix(self):
- return "Crazy Protocol"
- protocol = SomeProtocol()
- p = self.getListeningPort(reactor, protocol)
- expectedMessage = self.getExpectedStartListeningLogMessage(
- p, "Crazy Protocol")
- self.assertEqual((expectedMessage,), loggedMessages[0]['message'])
-
-
- def test_connectionLostLogMessage(self):
- """
- When a connection is lost, an informative message should be logged (see
- L{getExpectedConnectionLostLogMessage}): an address identifying the port
- and the fact that it was closed.
- """
- loggedMessages = self.observe()
- reactor = self.buildReactor()
- p = self.getListeningPort(reactor, DatagramProtocol())
- expectedMessage = self.getExpectedConnectionLostLogMessage(p)
-
- def stopReactor(ignored):
- reactor.stop()
-
- def doStopListening():
- del loggedMessages[:]
- maybeDeferred(p.stopListening).addCallback(stopReactor)
-
- reactor.callWhenRunning(doStopListening)
- self.runReactor(reactor)
-
- self.assertEqual((expectedMessage,), loggedMessages[0]['message'])
-
-
- def test_stopProtocolScheduling(self):
- """
- L{DatagramProtocol.stopProtocol} is called asynchronously (ie, not
- re-entrantly) when C{stopListening} is used to stop the the datagram
- transport.
- """
- class DisconnectingProtocol(DatagramProtocol):
-
- started = False
- stopped = False
- inStartProtocol = False
- stoppedInStart = False
-
- def startProtocol(self):
- self.started = True
- self.inStartProtocol = True
- self.transport.stopListening()
- self.inStartProtocol = False
-
- def stopProtocol(self):
- self.stopped = True
- self.stoppedInStart = self.inStartProtocol
- reactor.stop()
-
- reactor = self.buildReactor()
- protocol = DisconnectingProtocol()
- self.getListeningPort(reactor, protocol)
- self.runReactor(reactor)
-
- self.assertTrue(protocol.started)
- self.assertTrue(protocol.stopped)
- self.assertFalse(protocol.stoppedInStart)
-
-
-
-class UDPServerTestsBuilder(ReactorBuilder, UDPPortMixin,
- DatagramTransportTestsMixin):
- """
- Builder defining tests relating to L{IReactorUDP.listenUDP}.
- """
- requiredInterfaces = (IReactorUDP,)
-
- def test_interface(self):
- """
- L{IReactorUDP.listenUDP} returns an object providing L{IListeningPort}.
- """
- reactor = self.buildReactor()
- port = reactor.listenUDP(0, DatagramProtocol())
- self.assertTrue(verifyObject(IListeningPort, port))
-
-
- def test_getHost(self):
- """
- L{IListeningPort.getHost} returns an L{IPv4Address} giving a
- dotted-quad of the IPv4 address the port is listening on as well as
- the port number.
- """
- host, portNumber = findFreePort(type=SOCK_DGRAM)
- reactor = self.buildReactor()
- port = reactor.listenUDP(
- portNumber, DatagramProtocol(), interface=host)
- self.assertEqual(
- port.getHost(), IPv4Address('UDP', host, portNumber))
-
-
- def test_logPrefix(self):
- """
- Datagram transports implement L{ILoggingContext.logPrefix} to return a
- message reflecting the protocol they are running.
- """
- class CustomLogPrefixDatagramProtocol(DatagramProtocol):
- def __init__(self, prefix):
- self._prefix = prefix
- self.system = Deferred()
-
- def logPrefix(self):
- return self._prefix
-
- def datagramReceived(self, bytes, addr):
- if self.system is not None:
- system = self.system
- self.system = None
- system.callback(context.get(ILogContext)["system"])
-
- reactor = self.buildReactor()
- protocol = CustomLogPrefixDatagramProtocol("Custom Datagrams")
- d = protocol.system
- port = reactor.listenUDP(0, protocol)
- address = port.getHost()
-
- def gotSystem(system):
- self.assertEqual("Custom Datagrams (UDP)", system)
- d.addCallback(gotSystem)
- d.addErrback(err)
- d.addCallback(lambda ignored: reactor.stop())
-
- port.write("some bytes", ('127.0.0.1', address.port))
- self.runReactor(reactor)
-
-
-globals().update(UDPServerTestsBuilder.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp_internals.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp_internals.py
deleted file mode 100755
index 75dc1e2a..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_udp_internals.py
+++ /dev/null
@@ -1,165 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for the internal implementation details of L{twisted.internet.udp}.
-"""
-
-import socket
-
-from twisted.trial import unittest
-from twisted.internet.protocol import DatagramProtocol
-from twisted.internet import udp
-from twisted.python.runtime import platformType
-
-if platformType == 'win32':
- from errno import WSAEWOULDBLOCK as EWOULDBLOCK
- from errno import WSAECONNREFUSED as ECONNREFUSED
-else:
- from errno import EWOULDBLOCK
- from errno import ECONNREFUSED
-
-
-
-class StringUDPSocket(object):
- """
- A fake UDP socket object, which returns a fixed sequence of strings and/or
- socket errors. Useful for testing.
-
- @ivar retvals: A C{list} containing either strings or C{socket.error}s.
-
- @ivar connectedAddr: The address the socket is connected to.
- """
-
- def __init__(self, retvals):
- self.retvals = retvals
- self.connectedAddr = None
-
-
- def connect(self, addr):
- self.connectedAddr = addr
-
-
- def recvfrom(self, size):
- """
- Return (or raise) the next value from C{self.retvals}.
- """
- ret = self.retvals.pop(0)
- if isinstance(ret, socket.error):
- raise ret
- return ret, None
-
-
-
-class KeepReads(DatagramProtocol):
- """
- Accumulate reads in a list.
- """
-
- def __init__(self):
- self.reads = []
-
-
- def datagramReceived(self, data, addr):
- self.reads.append(data)
-
-
-
-class ErrorsTestCase(unittest.TestCase):
- """
- Error handling tests for C{udp.Port}.
- """
-
- def test_socketReadNormal(self):
- """
- Socket reads with some good data followed by a socket error which can
- be ignored causes reading to stop, and no log messages to be logged.
- """
- # Add a fake error to the list of ignorables:
- udp._sockErrReadIgnore.append(-7000)
- self.addCleanup(udp._sockErrReadIgnore.remove, -7000)
-
- protocol = KeepReads()
- port = udp.Port(None, protocol)
-
- # Normal result, no errors
- port.socket = StringUDPSocket(
- ["result", "123", socket.error(-7000), "456",
- socket.error(-7000)])
- port.doRead()
- # Read stops on error:
- self.assertEqual(protocol.reads, ["result", "123"])
- port.doRead()
- self.assertEqual(protocol.reads, ["result", "123", "456"])
-
-
- def test_readImmediateError(self):
- """
- If the socket is unconnected, socket reads with an immediate
- connection refusal are ignored, and reading stops. The protocol's
- C{connectionRefused} method is not called.
- """
- # Add a fake error to the list of those that count as connection
- # refused:
- udp._sockErrReadRefuse.append(-6000)
- self.addCleanup(udp._sockErrReadRefuse.remove, -6000)
-
- protocol = KeepReads()
- # Fail if connectionRefused is called:
- protocol.connectionRefused = lambda: 1/0
-
- port = udp.Port(None, protocol)
-
- # Try an immediate "connection refused"
- port.socket = StringUDPSocket(["a", socket.error(-6000), "b",
- socket.error(EWOULDBLOCK)])
- port.doRead()
- # Read stops on error:
- self.assertEqual(protocol.reads, ["a"])
- # Read again:
- port.doRead()
- self.assertEqual(protocol.reads, ["a", "b"])
-
-
- def test_connectedReadImmediateError(self):
- """
- If the socket connected, socket reads with an immediate
- connection refusal are ignored, and reading stops. The protocol's
- C{connectionRefused} method is called.
- """
- # Add a fake error to the list of those that count as connection
- # refused:
- udp._sockErrReadRefuse.append(-6000)
- self.addCleanup(udp._sockErrReadRefuse.remove, -6000)
-
- protocol = KeepReads()
- refused = []
- protocol.connectionRefused = lambda: refused.append(True)
-
- port = udp.Port(None, protocol)
- port.socket = StringUDPSocket(["a", socket.error(-6000), "b",
- socket.error(EWOULDBLOCK)])
- port.connect("127.0.0.1", 9999)
-
- # Read stops on error:
- port.doRead()
- self.assertEqual(protocol.reads, ["a"])
- self.assertEqual(refused, [True])
-
- # Read again:
- port.doRead()
- self.assertEqual(protocol.reads, ["a", "b"])
- self.assertEqual(refused, [True])
-
-
- def test_readUnknownError(self):
- """
- Socket reads with an unknown socket error are raised.
- """
- protocol = KeepReads()
- port = udp.Port(None, protocol)
-
- # Some good data, followed by an unknown error
- port.socket = StringUDPSocket(["good", socket.error(-1337)])
- self.assertRaises(socket.error, port.doRead)
- self.assertEqual(protocol.reads, ["good"])
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_unix.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_unix.py
deleted file mode 100755
index b9370da5..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_unix.py
+++ /dev/null
@@ -1,558 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorUNIX}.
-"""
-
-from stat import S_IMODE
-from os import stat, close
-from tempfile import mktemp
-from socket import AF_INET, SOCK_STREAM, socket
-from pprint import pformat
-
-try:
- from socket import AF_UNIX
-except ImportError:
- AF_UNIX = None
-
-from zope.interface import implements
-from zope.interface.verify import verifyObject
-
-from twisted.python.log import addObserver, removeObserver, err
-from twisted.python.failure import Failure
-from twisted.python.hashlib import md5
-from twisted.python.runtime import platform
-from twisted.internet.interfaces import (
- IConnector, IFileDescriptorReceiver, IReactorUNIX)
-from twisted.internet.error import ConnectionClosed, FileDescriptorOverrun
-from twisted.internet.address import UNIXAddress
-from twisted.internet.endpoints import UNIXServerEndpoint, UNIXClientEndpoint
-from twisted.internet.defer import Deferred, fail
-from twisted.internet.task import LoopingCall
-from twisted.internet import interfaces
-from twisted.internet.protocol import (
- ServerFactory, ClientFactory, DatagramProtocol)
-from twisted.internet.test.reactormixins import ReactorBuilder, EndpointCreator
-from twisted.internet.test.test_core import ObjectModelIntegrationMixin
-from twisted.internet.test.test_tcp import StreamTransportTestsMixin
-from twisted.internet.test.reactormixins import (
- ConnectableProtocol, runProtocolsWithReactor)
-from twisted.internet.test.connectionmixins import ConnectionTestsMixin
-
-try:
- from twisted.python import sendmsg
-except ImportError:
- sendmsgSkip = (
- "sendmsg extension unavailable, extended UNIX features disabled")
-else:
- sendmsgSkip = None
-
-
-class UNIXFamilyMixin:
- """
- Test-helper defining mixin for things related to AF_UNIX sockets.
- """
- def _modeTest(self, methodName, path, factory):
- """
- Assert that the mode of the created unix socket is set to the mode
- specified to the reactor method.
- """
- mode = 0600
- reactor = self.buildReactor()
- unixPort = getattr(reactor, methodName)(path, factory, mode=mode)
- unixPort.stopListening()
- self.assertEqual(S_IMODE(stat(path).st_mode), mode)
-
-
-def _abstractPath(case):
- """
- Return a new, unique abstract namespace path to be listened on.
- """
- # Use the test cases's mktemp to get something unique, but also squash it
- # down to make sure it fits in the unix socket path limit (something around
- # 110 bytes).
- return md5(case.mktemp()).hexdigest()
-
-
-
-class UNIXCreator(EndpointCreator):
- """
- Create UNIX socket end points.
- """
- requiredInterfaces = (interfaces.IReactorUNIX,)
-
- def server(self, reactor):
- """
- Construct a UNIX server endpoint.
- """
- # self.mktemp() often returns a path which is too long to be used.
- path = mktemp(suffix='.sock', dir='.')
- return UNIXServerEndpoint(reactor, path)
-
-
- def client(self, reactor, serverAddress):
- """
- Construct a UNIX client endpoint.
- """
- return UNIXClientEndpoint(reactor, serverAddress.name)
-
-
-
-class SendFileDescriptor(ConnectableProtocol):
- """
- L{SendFileDescriptorAndBytes} sends a file descriptor and optionally some
- normal bytes and then closes its connection.
-
- @ivar reason: The reason the connection was lost, after C{connectionLost}
- is called.
- """
- reason = None
-
- def __init__(self, fd, data):
- """
- @param fd: A C{int} giving a file descriptor to send over the
- connection.
-
- @param data: A C{str} giving data to send over the connection, or
- C{None} if no data is to be sent.
- """
- self.fd = fd
- self.data = data
-
-
- def connectionMade(self):
- """
- Send C{self.fd} and, if it is not C{None}, C{self.data}. Then close the
- connection.
- """
- self.transport.sendFileDescriptor(self.fd)
- if self.data:
- self.transport.write(self.data)
- self.transport.loseConnection()
-
-
- def connectionLost(self, reason):
- ConnectableProtocol.connectionLost(self, reason)
- self.reason = reason
-
-
-
-class ReceiveFileDescriptor(ConnectableProtocol):
- """
- L{ReceiveFileDescriptor} provides an API for waiting for file descriptors to
- be received.
-
- @ivar reason: The reason the connection was lost, after C{connectionLost}
- is called.
-
- @ivar waiting: A L{Deferred} which fires with a file descriptor once one is
- received, or with a failure if the connection is lost with no descriptor
- arriving.
- """
- implements(IFileDescriptorReceiver)
-
- reason = None
- waiting = None
-
- def waitForDescriptor(self):
- """
- Return a L{Deferred} which will fire with the next file descriptor
- received, or with a failure if the connection is or has already been
- lost.
- """
- if self.reason is None:
- self.waiting = Deferred()
- return self.waiting
- else:
- return fail(self.reason)
-
-
- def fileDescriptorReceived(self, descriptor):
- """
- Fire the waiting Deferred, initialized by C{waitForDescriptor}, with the
- file descriptor just received.
- """
- self.waiting.callback(descriptor)
- self.waiting = None
-
-
- def dataReceived(self, data):
- """
- Fail the waiting Deferred, if it has not already been fired by
- C{fileDescriptorReceived}. The bytes sent along with a file descriptor
- are guaranteed to be delivered to the protocol's C{dataReceived} method
- only after the file descriptor has been delivered to the protocol's
- C{fileDescriptorReceived}.
- """
- if self.waiting is not None:
- self.waiting.errback(Failure(Exception(
- "Received bytes (%r) before descriptor." % (data,))))
- self.waiting = None
-
-
- def connectionLost(self, reason):
- """
- Fail the waiting Deferred, initialized by C{waitForDescriptor}, if there
- is one.
- """
- ConnectableProtocol.connectionLost(self, reason)
- if self.waiting is not None:
- self.waiting.errback(reason)
- self.waiting = None
- self.reason = reason
-
-
-
-class UNIXTestsBuilder(UNIXFamilyMixin, ReactorBuilder, ConnectionTestsMixin):
- """
- Builder defining tests relating to L{IReactorUNIX}.
- """
- requiredInterfaces = (IReactorUNIX,)
-
- endpoints = UNIXCreator()
-
- def test_interface(self):
- """
- L{IReactorUNIX.connectUNIX} returns an object providing L{IConnector}.
- """
- reactor = self.buildReactor()
- connector = reactor.connectUNIX(self.mktemp(), ClientFactory())
- self.assertTrue(verifyObject(IConnector, connector))
-
-
- def test_mode(self):
- """
- The UNIX socket created by L{IReactorUNIX.listenUNIX} is created with
- the mode specified.
- """
- self._modeTest('listenUNIX', self.mktemp(), ServerFactory())
-
-
- def test_listenOnLinuxAbstractNamespace(self):
- """
- On Linux, a UNIX socket path may begin with C{'\0'} to indicate a socket
- in the abstract namespace. L{IReactorUNIX.listenUNIX} accepts such a
- path.
- """
- # Don't listen on a path longer than the maximum allowed.
- path = _abstractPath(self)
- reactor = self.buildReactor()
- port = reactor.listenUNIX('\0' + path, ServerFactory())
- self.assertEqual(port.getHost(), UNIXAddress('\0' + path))
- if not platform.isLinux():
- test_listenOnLinuxAbstractNamespace.skip = (
- 'Abstract namespace UNIX sockets only supported on Linux.')
-
-
- def test_connectToLinuxAbstractNamespace(self):
- """
- L{IReactorUNIX.connectUNIX} also accepts a Linux abstract namespace
- path.
- """
- path = _abstractPath(self)
- reactor = self.buildReactor()
- connector = reactor.connectUNIX('\0' + path, ClientFactory())
- self.assertEqual(
- connector.getDestination(), UNIXAddress('\0' + path))
- if not platform.isLinux():
- test_connectToLinuxAbstractNamespace.skip = (
- 'Abstract namespace UNIX sockets only supported on Linux.')
-
-
- def test_addresses(self):
- """
- A client's transport's C{getHost} and C{getPeer} return L{UNIXAddress}
- instances which have the filesystem path of the host and peer ends of
- the connection.
- """
- class SaveAddress(ConnectableProtocol):
- def makeConnection(self, transport):
- self.addresses = dict(
- host=transport.getHost(), peer=transport.getPeer())
- transport.loseConnection()
-
- server = SaveAddress()
- client = SaveAddress()
-
- runProtocolsWithReactor(self, server, client, self.endpoints)
-
- self.assertEqual(server.addresses['host'], client.addresses['peer'])
- self.assertEqual(server.addresses['peer'], client.addresses['host'])
-
-
- def test_sendFileDescriptor(self):
- """
- L{IUNIXTransport.sendFileDescriptor} accepts an integer file descriptor
- and sends a copy of it to the process reading from the connection.
- """
- from socket import fromfd
-
- s = socket()
- s.bind(('', 0))
- server = SendFileDescriptor(s.fileno(), "junk")
-
- client = ReceiveFileDescriptor()
- d = client.waitForDescriptor()
- def checkDescriptor(descriptor):
- received = fromfd(descriptor, AF_INET, SOCK_STREAM)
- # Thanks for the free dup, fromfd()
- close(descriptor)
-
- # If the sockets have the same local address, they're probably the
- # same.
- self.assertEqual(s.getsockname(), received.getsockname())
-
- # But it would be cheating for them to be identified by the same
- # file descriptor. The point was to get a copy, as we might get if
- # there were two processes involved here.
- self.assertNotEqual(s.fileno(), received.fileno())
- d.addCallback(checkDescriptor)
- d.addErrback(err, "Sending file descriptor encountered a problem")
- d.addBoth(lambda ignored: server.transport.loseConnection())
-
- runProtocolsWithReactor(self, server, client, self.endpoints)
- if sendmsgSkip is not None:
- test_sendFileDescriptor.skip = sendmsgSkip
-
-
- def test_sendFileDescriptorTriggersPauseProducing(self):
- """
- If a L{IUNIXTransport.sendFileDescriptor} call fills up the send buffer,
- any registered producer is paused.
- """
- class DoesNotRead(ConnectableProtocol):
- def connectionMade(self):
- self.transport.pauseProducing()
-
- class SendsManyFileDescriptors(ConnectableProtocol):
- paused = False
-
- def connectionMade(self):
- self.socket = socket()
- self.transport.registerProducer(self, True)
- def sender():
- self.transport.sendFileDescriptor(self.socket.fileno())
- self.transport.write("x")
- self.task = LoopingCall(sender)
- self.task.clock = self.transport.reactor
- self.task.start(0).addErrback(err, "Send loop failure")
-
- def stopProducing(self):
- self._disconnect()
-
- def resumeProducing(self):
- self._disconnect()
-
- def pauseProducing(self):
- self.paused = True
- self.transport.unregisterProducer()
- self._disconnect()
-
- def _disconnect(self):
- self.task.stop()
- self.transport.abortConnection()
- self.other.transport.abortConnection()
-
- server = SendsManyFileDescriptors()
- client = DoesNotRead()
- server.other = client
- runProtocolsWithReactor(self, server, client, self.endpoints)
-
- self.assertTrue(
- server.paused, "sendFileDescriptor producer was not paused")
- if sendmsgSkip is not None:
- test_sendFileDescriptorTriggersPauseProducing.skip = sendmsgSkip
-
-
- def test_fileDescriptorOverrun(self):
- """
- If L{IUNIXTransport.sendFileDescriptor} is used to queue a greater
- number of file descriptors than the number of bytes sent using
- L{ITransport.write}, the connection is closed and the protocol connected
- to the transport has its C{connectionLost} method called with a failure
- wrapping L{FileDescriptorOverrun}.
- """
- cargo = socket()
- server = SendFileDescriptor(cargo.fileno(), None)
-
- client = ReceiveFileDescriptor()
- d = self.assertFailure(
- client.waitForDescriptor(), ConnectionClosed)
- d.addErrback(
- err, "Sending file descriptor encountered unexpected problem")
- d.addBoth(lambda ignored: server.transport.loseConnection())
-
- runProtocolsWithReactor(self, server, client, self.endpoints)
-
- self.assertIsInstance(server.reason.value, FileDescriptorOverrun)
- if sendmsgSkip is not None:
- test_fileDescriptorOverrun.skip = sendmsgSkip
-
-
- def test_avoidLeakingFileDescriptors(self):
- """
- If associated with a protocol which does not provide
- L{IFileDescriptorReceiver}, file descriptors received by the
- L{IUNIXTransport} implementation are closed and a warning is emitted.
- """
- # To verify this, establish a connection. Send one end of the
- # connection over the IUNIXTransport implementation. After the copy
- # should no longer exist, close the original. If the opposite end of
- # the connection decides the connection is closed, the copy does not
- # exist.
- from socket import socketpair
- probeClient, probeServer = socketpair()
-
- events = []
- addObserver(events.append)
- self.addCleanup(removeObserver, events.append)
-
- class RecordEndpointAddresses(SendFileDescriptor):
- def connectionMade(self):
- self.hostAddress = self.transport.getHost()
- self.peerAddress = self.transport.getPeer()
- SendFileDescriptor.connectionMade(self)
-
- server = RecordEndpointAddresses(probeClient.fileno(), "junk")
- client = ConnectableProtocol()
-
- runProtocolsWithReactor(self, server, client, self.endpoints)
-
- # Get rid of the original reference to the socket.
- probeClient.close()
-
- # A non-blocking recv will return "" if the connection is closed, as
- # desired. If the connection has not been closed, because the duplicate
- # file descriptor is still open, it will fail with EAGAIN instead.
- probeServer.setblocking(False)
- self.assertEqual("", probeServer.recv(1024))
-
- # This is a surprising circumstance, so it should be logged.
- format = (
- "%(protocolName)s (on %(hostAddress)r) does not "
- "provide IFileDescriptorReceiver; closing file "
- "descriptor received (from %(peerAddress)r).")
- clsName = "ConnectableProtocol"
-
- # Reverse host and peer, since the log event is from the client
- # perspective.
- expectedEvent = dict(hostAddress=server.peerAddress,
- peerAddress=server.hostAddress,
- protocolName=clsName,
- format=format)
-
- for logEvent in events:
- for k, v in expectedEvent.iteritems():
- if v != logEvent.get(k):
- break
- else:
- # No mismatches were found, stop looking at events
- break
- else:
- # No fully matching events were found, fail the test.
- self.fail(
- "Expected event (%s) not found in logged events (%s)" % (
- expectedEvent, pformat(events,)))
- if sendmsgSkip is not None:
- test_avoidLeakingFileDescriptors.skip = sendmsgSkip
-
-
- def test_descriptorDeliveredBeforeBytes(self):
- """
- L{IUNIXTransport.sendFileDescriptor} sends file descriptors before
- L{ITransport.write} sends normal bytes.
- """
- class RecordEvents(ConnectableProtocol):
- implements(IFileDescriptorReceiver)
-
- def connectionMade(self):
- ConnectableProtocol.connectionMade(self)
- self.events = []
-
- def fileDescriptorReceived(innerSelf, descriptor):
- self.addCleanup(close, descriptor)
- innerSelf.events.append(type(descriptor))
-
- def dataReceived(self, data):
- self.events.extend(data)
-
- cargo = socket()
- server = SendFileDescriptor(cargo.fileno(), "junk")
- client = RecordEvents()
-
- runProtocolsWithReactor(self, server, client, self.endpoints)
-
- self.assertEqual([int, "j", "u", "n", "k"], client.events)
- if sendmsgSkip is not None:
- test_descriptorDeliveredBeforeBytes.skip = sendmsgSkip
-
-
-
-class UNIXDatagramTestsBuilder(UNIXFamilyMixin, ReactorBuilder):
- """
- Builder defining tests relating to L{IReactorUNIXDatagram}.
- """
- requiredInterfaces = (interfaces.IReactorUNIXDatagram,)
-
- # There's no corresponding test_connectMode because the mode parameter to
- # connectUNIXDatagram has been completely ignored since that API was first
- # introduced.
- def test_listenMode(self):
- """
- The UNIX socket created by L{IReactorUNIXDatagram.listenUNIXDatagram}
- is created with the mode specified.
- """
- self._modeTest('listenUNIXDatagram', self.mktemp(), DatagramProtocol())
-
-
- def test_listenOnLinuxAbstractNamespace(self):
- """
- On Linux, a UNIX socket path may begin with C{'\0'} to indicate a socket
- in the abstract namespace. L{IReactorUNIX.listenUNIXDatagram} accepts
- such a path.
- """
- path = _abstractPath(self)
- reactor = self.buildReactor()
- port = reactor.listenUNIXDatagram('\0' + path, DatagramProtocol())
- self.assertEqual(port.getHost(), UNIXAddress('\0' + path))
- if not platform.isLinux():
- test_listenOnLinuxAbstractNamespace.skip = (
- 'Abstract namespace UNIX sockets only supported on Linux.')
-
-
-
-class UNIXPortTestsBuilder(ReactorBuilder, ObjectModelIntegrationMixin,
- StreamTransportTestsMixin):
- """
- Tests for L{IReactorUNIX.listenUnix}
- """
- requiredInterfaces = (interfaces.IReactorUNIX,)
-
- def getListeningPort(self, reactor, factory):
- """
- Get a UNIX port from a reactor
- """
- # self.mktemp() often returns a path which is too long to be used.
- path = mktemp(suffix='.sock', dir='.')
- return reactor.listenUNIX(path, factory)
-
-
- def getExpectedStartListeningLogMessage(self, port, factory):
- """
- Get the message expected to be logged when a UNIX port starts listening.
- """
- return "%s starting on %r" % (factory, port.getHost().name)
-
-
- def getExpectedConnectionLostLogMsg(self, port):
- """
- Get the expected connection lost message for a UNIX port
- """
- return "(UNIX Port %s Closed)" % (repr(port.port),)
-
-
-
-globals().update(UNIXTestsBuilder.makeTestCaseClasses())
-globals().update(UNIXDatagramTestsBuilder.makeTestCaseClasses())
-globals().update(UNIXPortTestsBuilder.makeTestCaseClasses())
diff --git a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_win32events.py b/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_win32events.py
deleted file mode 100755
index b8ba59b6..00000000
--- a/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/test/test_win32events.py
+++ /dev/null
@@ -1,183 +0,0 @@
-# Copyright (c) Twisted Matrix Laboratories.
-# See LICENSE for details.
-
-"""
-Tests for implementations of L{IReactorWin32Events}.
-"""
-
-from thread import get_ident
-
-try:
- import win32event
-except ImportError:
- win32event = None
-
-from zope.interface.verify import verifyObject
-
-from twisted.python.threadable import isInIOThread
-from twisted.internet.interfaces import IReactorWin32Events
-from twisted.internet.defer import Deferred
-from twisted.internet.test.reactormixins import ReactorBuilder
-
-
-class Listener(object):
- """
- L{Listener} is an object that can be added to a L{IReactorWin32Events}
- reactor to receive callback notification when a Windows event is set. It
- records what thread its callback is invoked in and fires a Deferred.
-
- @ivar success: A flag which is set to C{True} when the event callback is
- called.
-
- @ivar logThreadID: The id of the thread in which the C{logPrefix} method is
- called.
-
- @ivar eventThreadID: The id of the thread in which the event callback is
- called.
-
- @ivar connLostThreadID: The id of the thread in which the C{connectionLost}
- method is called.
-
- @ivar _finished: The L{Deferred} which will be fired when the event callback
- is called.
- """
- success = False
- logThreadID = eventThreadID = connLostThreadID = None
-
- def __init__(self, finished):
- self._finished = finished
-
-
- def logPrefix(self):
- self.logThreadID = get_ident()
- return 'Listener'
-
-
- def occurred(self):
- self.success = True
- self.eventThreadID = get_ident()
- self._finished.callback(None)
-
-
- def brokenOccurred(self):
- raise RuntimeError("Some problem")
-
-
- def returnValueOccurred(self):
- return EnvironmentError("Entirely different problem")
-
-
- def connectionLost(self, reason):
- self.connLostThreadID = get_ident()
- self._finished.errback(reason)
-
-
-
-class Win32EventsTestsBuilder(ReactorBuilder):
- """
- Builder defining tests relating to L{IReactorWin32Events}.
- """
- requiredInterfaces = [IReactorWin32Events]
-
- def test_interface(self):
- """
- An instance of the reactor has all of the methods defined on
- L{IReactorWin32Events}.
- """
- reactor = self.buildReactor()
- verifyObject(IReactorWin32Events, reactor)
-
-
- def test_addEvent(self):
- """
- When an event which has been added to the reactor is set, the action
- associated with the event is invoked in the reactor thread.
- """
- reactorThreadID = get_ident()
- reactor = self.buildReactor()
- event = win32event.CreateEvent(None, False, False, None)
- finished = Deferred()
- finished.addCallback(lambda ignored: reactor.stop())
- listener = Listener(finished)
- reactor.addEvent(event, listener, 'occurred')
- reactor.callWhenRunning(win32event.SetEvent, event)
- self.runReactor(reactor)
- self.assertTrue(listener.success)
- self.assertEqual(reactorThreadID, listener.logThreadID)
- self.assertEqual(reactorThreadID, listener.eventThreadID)
-
-
- def test_ioThreadDoesNotChange(self):
- """
- Using L{IReactorWin32Events.addEvent} does not change which thread is
- reported as the I/O thread.
- """
- results = []
- def check(ignored):
- results.append(isInIOThread())
- reactor.stop()
- reactor = self.buildReactor()
- event = win32event.CreateEvent(None, False, False, None)
- finished = Deferred()
- listener = Listener(finished)
- finished.addCallback(check)
- reactor.addEvent(event, listener, 'occurred')
- reactor.callWhenRunning(win32event.SetEvent, event)
- self.runReactor(reactor)
- self.assertTrue(listener.success)
- self.assertEqual([True], results)
-
-
- def test_disconnectedOnError(self):
- """
- If the event handler raises an exception, the event is removed from the
- reactor and the handler's C{connectionLost} method is called in the I/O
- thread and the exception is logged.
- """
- reactorThreadID = get_ident()
- reactor = self.buildReactor()
- event = win32event.CreateEvent(None, False, False, None)
- finished = self.assertFailure(Deferred(), RuntimeError)
- finished.addCallback(lambda ignored: reactor.stop())
- listener = Listener(finished)
- reactor.addEvent(event, listener, 'brokenOccurred')
- reactor.callWhenRunning(win32event.SetEvent, event)
- self.runReactor(reactor)
- self.assertEqual(reactorThreadID, listener.connLostThreadID)
- self.assertEqual(1, len(self.flushLoggedErrors(RuntimeError)))
-
-
- def test_disconnectOnReturnValue(self):
- """
- If the event handler returns a value, the event is removed from the
- reactor and the handler's C{connectionLost} method is called in the I/O
- thread.
- """
- reactorThreadID = get_ident()
- reactor = self.buildReactor()
- event = win32event.CreateEvent(None, False, False, None)
- finished = self.assertFailure(Deferred(), EnvironmentError)
- finished.addCallback(lambda ignored: reactor.stop())
- listener = Listener(finished)
- reactor.addEvent(event, listener, 'returnValueOccurred')
- reactor.callWhenRunning(win32event.SetEvent, event)
- self.runReactor(reactor)
- self.assertEqual(reactorThreadID, listener.connLostThreadID)
-
-
- def test_notDisconnectedOnShutdown(self):
- """
- Event handlers added with L{IReactorWin32Events.addEvent} do not have
- C{connectionLost} called on them if they are still active when the
- reactor shuts down.
- """
- reactor = self.buildReactor()
- event = win32event.CreateEvent(None, False, False, None)
- finished = Deferred()
- listener = Listener(finished)
- reactor.addEvent(event, listener, 'occurred')
- reactor.callWhenRunning(reactor.stop)
- self.runReactor(reactor)
- self.assertIdentical(None, listener.connLostThreadID)
-
-globals().update(Win32EventsTestsBuilder.makeTestCaseClasses())