Here are the examples of the python api twisted.internet.address.UNIXAddress taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
31 Examples
3
Example 1
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))
3
Example 2
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.assertEquals(
connector.getDestination(), UNIXAddress('\0' + path))
3
Example 3
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))
3
Example 4
def getHost(self):
"""Returns a UNIXAddress.
This indicates the server's address.
"""
if sys.version_info > (2, 5) or _inFilesystemNamespace(self.port):
path = self.socket.getsockname()
else:
# Abstract namespace sockets aren't well supported on Python 2.4.
# getsockname() always returns ''.
path = self.port
return address.UNIXAddress(path)
3
Example 5
def listenUNIX(self, address, factory,
backlog=50, mode=0666, wantPID=0):
"""
Fake L{reactor.listenUNIX}, that logs the call and returns an
L{IListeningPort}.
"""
self.unixServers.append((address, factory, backlog, mode, wantPID))
return _FakePort(UNIXAddress(address))
3
Example 6
def connectUNIX(self, address, factory, timeout=30, checkPID=0):
"""
Fake L{reactor.connectUNIX}, that logs the call and returns an
L{IConnector}.
"""
self.unixClients.append((address, factory, timeout, checkPID))
return _FakeConnector(UNIXAddress(address))
3
Example 7
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)
3
Example 8
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))
3
Example 9
Project: SubliminalCollaborator Source File: test_address.py
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)))
3
Example 10
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)
3
Example 11
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))
3
Example 12
Project: SubliminalCollaborator Source File: test_unix.py
Function: test_listenonlinuxabstractnamespace
Function: test_listenonlinuxabstractnamespace
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))
3
Example 13
Project: SubliminalCollaborator Source File: test_unix.py
Function: test_connecttolinuxabstractnamespace
Function: test_connecttolinuxabstractnamespace
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))
3
Example 14
Project: SubliminalCollaborator Source File: test_unix.py
Function: test_listenonlinuxabstractnamespace
Function: test_listenonlinuxabstractnamespace
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))
3
Example 15
def connectUNIX(self, address, factory, timeout=30, checkPID=0):
"""
Fake L{reactor.connectUNIX}, that logs the call and returns an
L{IConnector}.
"""
self.unixClients.append((address, factory, timeout, checkPID))
conn = _FakeConnector(UNIXAddress(address))
factory.startedConnecting(conn)
return conn
0
Example 16
def buildAddress(self):
return UNIXAddress(self._socketAddress)
0
Example 17
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)
0
Example 18
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)
0
Example 19
def getHost(self):
return address.UNIXAddress(self.socket.getsockname())
0
Example 20
def getPeer(self):
return address.UNIXAddress(self.hostname)
0
Example 21
Project: mythbox Source File: unix.py
def _buildAddr(self, name):
return address.UNIXAddress(name)
0
Example 22
def getPeer(self):
return address.UNIXAddress(self.addr)
0
Example 23
def getHost(self):
return address.UNIXAddress(None)
0
Example 24
def getDestination(self):
return address.UNIXAddress(self.address)
0
Example 25
def getPeer(self):
return address.UNIXAddress(self.remoteaddr)
0
Example 26
Project: mythbox Source File: test_unix.py
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
0
Example 27
Project: mythbox Source File: test_unix.py
def test_dumber(self):
"""
L{IReactorUNIX.connectUNIX} can be used to connect a client to a server
started with L{IReactorUNIX.listenUNIX}.
"""
filename = self.mktemp()
serverFactory = MyServerFactory()
serverConnMade = defer.Deferred()
serverFactory.protocolConnectionMade = serverConnMade
unixPort = reactor.listenUNIX(filename, serverFactory)
self.addCleanup(unixPort.stopListening)
clientFactory = MyClientFactory()
clientConnMade = defer.Deferred()
clientFactory.protocolConnectionMade = clientConnMade
c = reactor.connectUNIX(filename, clientFactory)
d = defer.gatherResults([serverConnMade, clientConnMade])
def allConnected((serverProtocol, clientProtocol)):
# Incidental assertion which may or may not be redundant with some
# other test. This probably deserves its own test method.
self.assertEqual(clientFactory.peerAddresses,
[address.UNIXAddress(filename)])
clientProtocol.transport.loseConnection()
serverProtocol.transport.loseConnection()
0
Example 28
def test_pidFile(self):
"""
A lockfile is created and locked when L{IReactorUNIX.listenUNIX} is
called and released when the Deferred returned by the L{IListeningPort}
provider's C{stopListening} method is called back.
"""
filename = self.mktemp()
serverFactory = MyServerFactory()
serverConnMade = defer.Deferred()
serverFactory.protocolConnectionMade = serverConnMade
unixPort = reactor.listenUNIX(filename, serverFactory, wantPID=True)
self.assertTrue(lockfile.isLocked(filename + ".lock"))
# XXX This part would test something about the checkPID parameter, but
# it doesn't actually. It should be rewritten to test the several
# different possible behaviors. -exarkun
clientFactory = MyClientFactory()
clientConnMade = defer.Deferred()
clientFactory.protocolConnectionMade = clientConnMade
c = reactor.connectUNIX(filename, clientFactory, checkPID=1)
d = defer.gatherResults([serverConnMade, clientConnMade])
def _portStuff((serverProtocol, clientProto)):
# Incidental assertion which may or may not be redundant with some
# other test. This probably deserves its own test method.
self.assertEqual(clientFactory.peerAddresses,
[address.UNIXAddress(filename)])
clientProto.transport.loseConnection()
serverProtocol.transport.loseConnection()
return unixPort.stopListening()
0
Example 29
def buildDifferentAddress(self):
"""
Like L{buildAddress}, but with a different fixed address.
"""
return UNIXAddress(self._otherAddress)
0
Example 30
def buildDifferentAddress(self):
"""
Like L{buildAddress}, but with a fixed address of C{None}.
"""
return UNIXAddress(None)
0
Example 31
def getPeer(self):
return address.UNIXAddress(self.hostname or None)