Python twisted.internet.address.UNIXAddress() Examples
The following are 30
code examples of twisted.internet.address.UNIXAddress().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.address
, or try the search function
.
Example #1
Source File: test_wrapper.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_validUNIXHeaderResolves_getPeerHost(self): """ Test if UNIX headers result in the correct host and peer data. """ factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol)) proto = factory.buildProtocol( address.UNIXAddress(b'/home/test/sockets/server.sock'), ) transport = StringTransportWithDisconnection() proto.makeConnection(transport) proto.dataReceived(self.UNIXHEADER) self.assertEqual(proto.getPeer().name, b'/home/tests/mysockets/sock') self.assertEqual( proto.wrappedProtocol.transport.getPeer().name, b'/home/tests/mysockets/sock', ) self.assertEqual(proto.getHost().name, b'/home/tests/mysockets/sock') self.assertEqual( proto.wrappedProtocol.transport.getHost().name, b'/home/tests/mysockets/sock', )
Example #2
Source File: test_unix.py From learn_python3_spider with MIT License | 6 votes |
def connectToListener(self, reactor, address, factory): """ Connect to a listening UNIX socket. @param reactor: The reactor under test. @type reactor: L{IReactorUNIX} @param address: The listening's address. @type address: L{UNIXAddress} @param factory: The client factory. @type factory: L{ClientFactory} @return: The connector """ return reactor.connectUNIX(address.name, factory)
Example #3
Source File: test_unix.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def test_peerBind(self): """ The address passed to the server factory's C{buildProtocol} method and the address returned by the connected protocol's transport's C{getPeer} method match the address the client socket is bound to. """ filename = self.mktemp() peername = self.mktemp() serverFactory = MyServerFactory() connMade = serverFactory.protocolConnectionMade = defer.Deferred() unixPort = reactor.listenUNIX(filename, serverFactory) self.addCleanup(unixPort.stopListening) unixSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.addCleanup(unixSocket.close) unixSocket.bind(peername) unixSocket.connect(filename) def cbConnMade(proto): expected = address.UNIXAddress(peername) self.assertEqual(serverFactory.peerAddresses, [expected]) self.assertEqual(proto.transport.getPeer(), expected) connMade.addCallback(cbConnMade) return connMade
Example #4
Source File: test_unix.py From learn_python3_spider with MIT License | 6 votes |
def connectToListener(self, reactor, address, factory): """ Connect to a listening UNIX socket. @param reactor: The reactor under test. @type reactor: L{IReactorUNIX} @param address: The listening's address. @type address: L{UNIXAddress} @param factory: The client factory. @type factory: L{ClientFactory} @return: The connector """ return reactor.connectUNIX(address.name, factory)
Example #5
Source File: test_unix.py From learn_python3_spider with MIT License | 6 votes |
def test_peerBind(self): """ The address passed to the server factory's C{buildProtocol} method and the address returned by the connected protocol's transport's C{getPeer} method match the address the client socket is bound to. """ filename = self.mktemp() peername = self.mktemp() serverFactory = MyServerFactory() connMade = serverFactory.protocolConnectionMade = defer.Deferred() unixPort = reactor.listenUNIX(filename, serverFactory) self.addCleanup(unixPort.stopListening) unixSocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.addCleanup(unixSocket.close) unixSocket.bind(peername) unixSocket.connect(filename) def cbConnMade(proto): expected = address.UNIXAddress(peername) self.assertEqual(serverFactory.peerAddresses, [expected]) self.assertEqual(proto.transport.getPeer(), expected) connMade.addCallback(cbConnMade) return connMade
Example #6
Source File: test_unix.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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'])
Example #7
Source File: test_wrapper.py From learn_python3_spider with MIT License | 6 votes |
def test_validUNIXHeaderResolves_getPeerHost(self): """ Test if UNIX headers result in the correct host and peer data. """ factory = HAProxyWrappingFactory(Factory.forProtocol(StaticProtocol)) proto = factory.buildProtocol( address.UNIXAddress(b'/home/test/sockets/server.sock'), ) transport = StringTransportWithDisconnection() proto.makeConnection(transport) proto.dataReceived(self.UNIXHEADER) self.assertEqual(proto.getPeer().name, b'/home/tests/mysockets/sock') self.assertEqual( proto.wrappedProtocol.transport.getPeer().name, b'/home/tests/mysockets/sock', ) self.assertEqual(proto.getHost().name, b'/home/tests/mysockets/sock') self.assertEqual( proto.wrappedProtocol.transport.getHost().name, b'/home/tests/mysockets/sock', )
Example #8
Source File: test_endpoints.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #9
Source File: test_endpoints.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: test_endpoints.py From learn_python3_spider with MIT License | 6 votes |
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', 0o666), listenArgs.get('wantPID', 0)), address)
Example #11
Source File: test_unix.py From python-for-android with Apache License 2.0 | 5 votes |
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.assertEquals(port.getHost(), UNIXAddress('\0' + path))
Example #12
Source File: test_unix.py From learn_python3_spider with MIT License | 5 votes |
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))
Example #13
Source File: unix.py From python-for-android with Apache License 2.0 | 5 votes |
def getHost(self): return address.UNIXAddress(None)
Example #14
Source File: unix.py From python-for-android with Apache License 2.0 | 5 votes |
def getDestination(self): return address.UNIXAddress(self.address)
Example #15
Source File: unix.py From python-for-android with Apache License 2.0 | 5 votes |
def getPeer(self): return address.UNIXAddress(self.remoteaddr)
Example #16
Source File: test_unix.py From learn_python3_spider with MIT License | 5 votes |
def test_ServerAddressUNIX(self): """ Helper method to test UNIX server addresses. """ def connected(protocols): client, server, port = protocols try: portPath = _coerceToFilesystemEncoding('', port.getHost().name) self.assertEqual( "<AccumulatingProtocol #%s on %s>" % (server.transport.sessionno, portPath), str(server.transport)) self.assertEqual( "AccumulatingProtocol,%s,%s" % (server.transport.sessionno, portPath), server.transport.logstr) peerAddress = server.factory.peerAddresses[0] self.assertIsInstance(peerAddress, UNIXAddress) finally: # Be certain to drop the connection so the test completes. server.transport.loseConnection() reactor = self.buildReactor() d = self.getConnectedClientAndServer(reactor, interface=None, addressFamily=None) d.addCallback(connected) self.runReactor(reactor)
Example #17
Source File: test_address.py From python-for-android with Apache License 2.0 | 5 votes |
def buildAddress(self): return UNIXAddress(self._socketAddress)
Example #18
Source File: test_unix.py From python-for-android with Apache License 2.0 | 5 votes |
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.assertEquals(port.getHost(), UNIXAddress('\0' + path))
Example #19
Source File: unix.py From learn_python3_spider with MIT License | 5 votes |
def getPeer(self): return address.UNIXAddress(self.remoteaddr)
Example #20
Source File: test_unix.py From learn_python3_spider with MIT License | 5 votes |
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))
Example #21
Source File: test_unix.py From learn_python3_spider with MIT License | 5 votes |
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))
Example #22
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
def test_comparisonOfLinkedFiles(self): """ A UNIXAddress referring to a L{None} address does not compare equal to a UNIXAddress referring to a symlink. """ linkName = self.mktemp() with open(self._socketAddress, 'w') as self.fd: os.symlink(os.path.abspath(self._socketAddress), linkName) self.assertNotEqual(UNIXAddress(self._socketAddress), UNIXAddress(None)) self.assertNotEqual(UNIXAddress(None), UNIXAddress(self._socketAddress))
Example #23
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
def buildDifferentAddress(self): """ Like L{buildAddress}, but with a random temporary directory. """ return UNIXAddress(self._socketAddress)
Example #24
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
def buildAddress(self): """ Create an arbitrary new L{UNIXAddress} instance. A new instance is created for each call, but always for the same address. This builds it with a fixed address of L{None}. """ return UNIXAddress(None)
Example #25
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
def test_comparisonOfLinkedFiles(self): """ UNIXAddress objects compare as equal if they link to the same file. """ linkName = self.mktemp() with open(self._socketAddress, 'w') as self.fd: os.symlink(os.path.abspath(self._socketAddress), linkName) self.assertEqual(UNIXAddress(self._socketAddress), UNIXAddress(linkName)) self.assertEqual(UNIXAddress(linkName), UNIXAddress(self._socketAddress))
Example #26
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
def test_repr(self): """ The repr of L{UNIXAddress} returns with the filename that the L{UNIXAddress} is for. """ self.assertEqual(repr(self.buildAddress()), "UNIXAddress('%s')" % ( nativeString(self._socketAddress)))
Example #27
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
def buildDifferentAddress(self): """ Like L{buildAddress}, but with a different fixed address. """ return UNIXAddress(self._otherAddress)
Example #28
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
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)
Example #29
Source File: test_address.py From learn_python3_spider with MIT License | 5 votes |
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())
Example #30
Source File: unix.py From learn_python3_spider with MIT License | 5 votes |
def getPeer(self): return address.UNIXAddress(self.addr)