当前位置: 首页>>代码示例>>Python>>正文


Python address.UNIXAddress方法代码示例

本文整理汇总了Python中twisted.internet.address.UNIXAddress方法的典型用法代码示例。如果您正苦于以下问题:Python address.UNIXAddress方法的具体用法?Python address.UNIXAddress怎么用?Python address.UNIXAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.address的用法示例。


在下文中一共展示了address.UNIXAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createClientEndpoint

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_endpoints.py

示例2: test_addresses

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_unix.py

示例3: test_validUNIXHeaderResolves_getPeerHost

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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',
        ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_wrapper.py

示例4: test_peerBind

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_unix.py

示例5: createServerEndpoint

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_endpoints.py

示例6: connectToListener

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:test_unix.py

示例7: createServerEndpoint

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:test_endpoints.py

示例8: _addressToTuple

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
def _addressToTuple(addr):
    if isinstance(addr, address.IPv4Address):
        return ('INET', addr.host, addr.port)
    elif isinstance(addr, address.UNIXAddress):
        return ('UNIX', addr.name)
    else:
        return tuple(addr) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:server.py

示例9: setCopyableState

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
def setCopyableState(self, state):
        """
        Initialize this L{twisted.web.distrib.Request} based on the copied
        state so that it closely resembles a L{twisted.web.server.Request}.
        """
        for k in 'host', 'client':
            tup = state[k]
            addrdesc = {'INET': 'TCP', 'UNIX': 'UNIX'}[tup[0]]
            addr = {'TCP': lambda: address.IPv4Address(addrdesc,
                                                       tup[1], tup[2]),
                    'UNIX': lambda: address.UNIXAddress(tup[1])}[addrdesc]()
            state[k] = addr
        state['requestHeaders'] = Headers(dict(state['requestHeaders']))
        pb.RemoteCopy.setCopyableState(self, state)
        # Emulate the local request interface --
        self.content = cStringIO.StringIO(self.content_data)
        self.finish           = self.remote.remoteMethod('finish')
        self.setHeader        = self.remote.remoteMethod('setHeader')
        self.addCookie        = self.remote.remoteMethod('addCookie')
        self.setETag          = self.remote.remoteMethod('setETag')
        self.setResponseCode  = self.remote.remoteMethod('setResponseCode')
        self.setLastModified  = self.remote.remoteMethod('setLastModified')

        # To avoid failing if a resource tries to write a very long string
        # all at once, this one will be handled slightly differently.
        self._write = self.remote.remoteMethod('write') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:28,代码来源:distrib.py

示例10: getHost

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
def getHost(self):
        return address.UNIXAddress(self.socket.getsockname()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:unix.py

示例11: getPeer

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
def getPeer(self):
        return address.UNIXAddress(self.hostname or None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:unix.py

示例12: __init__

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
def __init__(self, filename, connector, reactor=None, checkPID = 0):
        _SendmsgMixin.__init__(self)
        # Normalise the filename using UNIXAddress
        filename = address.UNIXAddress(filename).name
        self.connector = connector
        self.realAddress = self.addr = filename
        if checkPID and not lockfile.isLocked(filename + b".lock"):
            self._finishInit(None, None, error.BadFileError(filename), reactor)
        self._finishInit(self.doConnect, self.createInternetSocket(),
                         None, reactor) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:unix.py

示例13: getDestination

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
def getDestination(self):
        return address.UNIXAddress(self.address) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:unix.py

示例14: test_addressComparison

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_address.py

示例15: buildAddress

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import UNIXAddress [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:test_address.py


注:本文中的twisted.internet.address.UNIXAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。