twisted.internet.address.UNIXAddress

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.

86 Examples 7

Example 1

Project: mythbox
Source File: test_unix.py
View license
    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 2

Project: mythbox
Source File: test_unix.py
View license
    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))

Example 3

Project: mythbox
Source File: test_unix.py
View license
    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 4

Project: mythbox
Source File: unix.py
View license
    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)

Example 5

Project: mythbox
Source File: test_unix.py
View license
    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 6

Project: mythbox
Source File: test_unix.py
View license
    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))

Example 7

Project: mythbox
Source File: test_unix.py
View license
    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 8

Project: mythbox
Source File: unix.py
View license
    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)

Example 9

Project: mythbox
Source File: proto_helpers.py
View license
    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))

Example 10

Project: mythbox
Source File: proto_helpers.py
View license
    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))

Example 11

Project: mythbox
Source File: proto_helpers.py
View license
    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))

Example 12

Project: mythbox
Source File: proto_helpers.py
View license
    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))

Example 13

View license
    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 14

View license
    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))

Example 15

View license
    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)))

Example 16

View license
    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)

Example 17

View license
    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 18

View license
    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))

Example 19

View license
    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 20

View license
    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))

Example 21

View license
    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)))

Example 22

View license
    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)

Example 23

View license
    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 24

View license
    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))

Example 25

Project: SubliminalCollaborator
Source File: test_unix.py
View license
    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 26

Project: SubliminalCollaborator
Source File: test_unix.py
View license
    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 27

Project: SubliminalCollaborator
Source File: test_unix.py
View license
    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 28

Project: SubliminalCollaborator
Source File: test_unix.py
View license
    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 29

Project: SubliminalCollaborator
Source File: test_unix.py
View license
    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 30

Project: SubliminalCollaborator
Source File: unix.py
View license
    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)

Example 31

Project: SubliminalCollaborator
Source File: test_unix.py
View license
    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 32

Project: SubliminalCollaborator
Source File: unix.py
View license
    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)

Example 33

View license
    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))

Example 34

View license
    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

Example 35

View license
    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))

Example 36

View license
    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

Example 37

Project: mythbox
Source File: test_address.py
View license
    def buildAddress(self):
        return UNIXAddress(self._socketAddress)

Example 38

Project: mythbox
Source File: test_endpoints.py
View license
    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 39

Project: mythbox
Source File: test_endpoints.py
View license
    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 40

Project: mythbox
Source File: test_address.py
View license
    def buildAddress(self):
        return UNIXAddress(self._socketAddress)

Example 41

Project: mythbox
Source File: test_endpoints.py
View license
    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 42

Project: mythbox
Source File: test_endpoints.py
View license
    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 43

Project: mythbox
Source File: unix.py
View license
    def getHost(self):
        return address.UNIXAddress(self.socket.getsockname())

Example 44

Project: mythbox
Source File: unix.py
View license
    def getPeer(self):
        return address.UNIXAddress(self.hostname)

Example 45

Project: mythbox
Source File: unix.py
View license
    def _buildAddr(self, name):
        return address.UNIXAddress(name)

Example 46

Project: mythbox
Source File: unix.py
View license
    def getPeer(self):
        return address.UNIXAddress(self.addr)

Example 47

Project: mythbox
Source File: unix.py
View license
    def getHost(self):
        return address.UNIXAddress(None)

Example 48

Project: mythbox
Source File: unix.py
View license
    def getDestination(self):
        return address.UNIXAddress(self.address)

Example 49

Project: mythbox
Source File: unix.py
View license
    def getPeer(self):
        return address.UNIXAddress(self.remoteaddr)

Example 50

Project: mythbox
Source File: unix.py
View license
    def getHost(self):
        return address.UNIXAddress(self.socket.getsockname())