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


Python address.IPv4Address方法代码示例

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


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

示例1: test_lengthLimitExceeded

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def test_lengthLimitExceeded(self):
        """
        An error is logged and the connection dropped when an oversized message
        is received.
        """
        too_long = KafkaProtocol.MAX_LENGTH + 1
        peer = IPv4Address('TCP', '1.2.3.4', 1234)
        kp = KafkaProtocol()
        kp.factory = factory_spy = mock.Mock(wraps=TheFactory())
        kp.transport = StringTransportWithDisconnection(peerAddress=peer)
        kp.transport.protocol = kp

        with capture_logging(logging.getLogger('afkak.protocol')) as records:
            kp.lengthLimitExceeded(too_long)

        self.assertEqual(1, len(factory_spy._connectionLost.mock_calls))

        [record] = records
        record.getMessage()  # Formats okay.
        self.assertEqual((
            'Broker at %s sent a %d byte message, exceeding the size limit of %d. '
            'Terminating connection.'
        ), record.msg)
        self.assertEqual((peer, too_long, kp.MAX_LENGTH), record.args) 
开发者ID:ciena,项目名称:afkak,代码行数:26,代码来源:test_protocol.py

示例2: test_decode

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def test_decode(self):
        """
        L{digest.DigestCredentialFactory.decode} calls the C{decode} method on
        L{twisted.cred.digest.DigestCredentialFactory} with the HTTP method and
        host of the request.
        """
        host = b'169.254.0.1'
        method = b'GET'
        done = [False]
        response = object()
        def check(_response, _method, _host):
            self.assertEqual(response, _response)
            self.assertEqual(method, _method)
            self.assertEqual(host, _host)
            done[0] = True

        self.patch(self.credentialFactory.digest, 'decode', check)
        req = self.makeRequest(method, IPv4Address('TCP', host, 81))
        self.credentialFactory.decode(response, req)
        self.assertTrue(done[0]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_httpauth.py

示例3: test_nonASCII

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def test_nonASCII(self):
        """
        Bytes in fields of the request which are not part of ASCII are escaped
        in the result.
        """
        reactor = Clock()
        reactor.advance(1234567890)

        timestamp = http.datetimeToLogString(reactor.seconds())
        request = DummyRequestForLogTest(http.HTTPFactory(reactor=reactor))
        request.client = IPv4Address("TCP", b"evil x-forwarded-for \x80", 12345)
        request.method = b"POS\x81"
        request.protocol = b"HTTP/1.\x82"
        request.requestHeaders.addRawHeader(b"referer", b"evil \x83")
        request.requestHeaders.addRawHeader(b"user-agent", b"evil \x84")

        line = http.combinedLogFormatter(timestamp, request)
        self.assertEqual(
            u'"evil x-forwarded-for \\x80" - - [13/Feb/2009:23:31:30 +0000] '
            u'"POS\\x81 /dummy HTTP/1.0" 123 - "evil \\x83" "evil \\x84"',
            line) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_web.py

示例4: createServerEndpoint

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

示例5: test_ignoreUnknownAddressTypes

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def test_ignoreUnknownAddressTypes(self):
        """
        If an address type other than L{IPv4Address} and L{IPv6Address} is
        returned by on address resolution, the endpoint ignores that address.
        """
        self.mreactor = MemoryReactor()
        self.endpoint = endpoints.HostnameEndpoint(
            deterministicResolvingReactor(self.mreactor, ['1.2.3.4', object(),
                                                          '1:2::3:4']),
            b"www.example.com", 80
        )
        clientFactory = None

        self.endpoint.connect(clientFactory)

        self.mreactor.advance(0.3)
        (host, port, factory, timeout, bindAddress) = self.mreactor.tcpClients[1]
        self.assertEqual(len(self.mreactor.tcpClients), 2)
        self.assertEqual(host, '1:2::3:4')
        self.assertEqual(port, 80) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_endpoints.py

示例6: test_feedParsing

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def test_feedParsing(self):
        """
        Test that parsing happens when fed a complete line.
        """
        parser = _v1parser.V1Parser()
        info, remaining = parser.feed(b'PROXY TCP4 127.0.0.1 127.0.0.1 ')
        self.assertFalse(info)
        self.assertFalse(remaining)
        info, remaining = parser.feed(b'8080 8888')
        self.assertFalse(info)
        self.assertFalse(remaining)
        info, remaining = parser.feed(b'\r\n')
        self.assertFalse(remaining)
        self.assertIsInstance(info.source, address.IPv4Address)
        self.assertEqual(info.source.host, b'127.0.0.1')
        self.assertEqual(info.source.port, 8080)
        self.assertEqual(info.destination.host, b'127.0.0.1')
        self.assertEqual(info.destination.port, 8888) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_v1parser.py

示例7: _timeoutTest

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def _timeoutTest(self, onDone, clientFactory):
        """
        Connect the clientFactory, and check the timeout on the request.
        """
        clock = task.Clock()
        client = clientFactory.buildProtocol(
            address.IPv4Address('TCP', 'example.net', 25))
        client.callLater = clock.callLater
        t = StringTransport()
        client.makeConnection(t)
        t.protocol = client
        def check(ign):
            self.assertEqual(clock.seconds(), 0.5)
        d = self.assertFailure(onDone, smtp.SMTPTimeoutError
            ).addCallback(check)
        # The first call should not trigger the timeout
        clock.advance(0.1)
        # But this one should
        clock.advance(0.4)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_smtp.py

示例8: test_onlyLogFailedAddresses

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def test_onlyLogFailedAddresses(self):
        """
        L{smtp.SenderMixin.sentMail} adds only the addresses with failing
        SMTP response codes to the log passed to the factory's errback.
        """
        onDone = self.assertFailure(defer.Deferred(), smtp.SMTPDeliveryError)
        onDone.addCallback(lambda e: self.assertEqual(
                e.log, "bob@example.com: 199 Error in sending.\n"))

        clientFactory = smtp.SMTPSenderFactory(
            'source@address', 'recipient@address',
            StringIO("Message body"), onDone,
            retries=0, timeout=0.5)

        client = clientFactory.buildProtocol(
            address.IPv4Address('TCP', 'example.net', 25))

        addresses = [("alice@example.com", 200, "No errors here!"),
                     ("bob@example.com", 199, "Error in sending.")]
        client.sentMail(199, "Test response", 1, addresses, client.log)

        return onDone 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_smtp.py

示例9: setUp

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def setUp(self):
        self.hostname = b"ssh.example.com"
        self.port = 42022
        self.user = b"user"
        self.password = b"password"
        self.reactor = MemoryReactorClock()
        self.realm = TrivialRealm()
        self.portal = Portal(self.realm)
        self.passwdDB = InMemoryUsernamePasswordDatabaseDontUse()
        self.passwdDB.addUser(self.user, self.password)
        self.portal.registerChecker(self.passwdDB)
        self.factory = CommandFactory()
        self.factory.reactor = self.reactor
        self.factory.portal = self.portal
        self.factory.doStart()
        self.addCleanup(self.factory.doStop)

        self.clientAddress = IPv4Address("TCP", "10.0.0.1", 12345)
        self.serverAddress = IPv4Address("TCP", "192.168.100.200", 54321) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_endpoints.py

示例10: adoptDatagramPort

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def adoptDatagramPort(self, fileno, addressFamily, protocol,
                          maxPacketSize=8192):
        """
        Fake L{IReactorSocket.adoptDatagramPort}, that logs the call and returns
        a fake L{IListeningPort}.

        @see: L{twisted.internet.interfaces.IReactorSocket.adoptDatagramPort}
        """
        if addressFamily == AF_INET:
            addr = IPv4Address('UDP', '0.0.0.0', 1234)
        elif addressFamily == AF_INET6:
            addr = IPv6Address('UDP', '::', 1234)
        else:
            raise UnsupportedAddressFamily()

        self.adoptedPorts.append(
            (fileno, addressFamily, protocol, maxPacketSize))
        return _FakePort(addr) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:proto_helpers.py

示例11: setUp

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def setUp(self):
        self.peer = IPv4Address('TCP', 'kafka', 9072)
        self.protocol = KafkaBootstrapProtocol()
        self.transport = FakeTransport(self.protocol, isServer=False, peerAddress=self.peer)
        self.protocol.makeConnection(self.transport) 
开发者ID:ciena,项目名称:afkak,代码行数:7,代码来源:test_protocol.py

示例12: _addressToTuple

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [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

示例13: setCopyableState

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [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

示例14: setHost

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def setHost(self, host, port, ssl=0):
        """
        Change the host and port the request thinks it's using.

        This method is useful for working with reverse HTTP proxies (e.g.
        both Squid and Apache's mod_proxy can do this), when the address
        the HTTP client is using is different than the one we're listening on.

        For example, Apache may be listening on https://www.example.com/, and
        then forwarding requests to http://localhost:8080/, but we don't want
        HTML produced by Twisted to say b'http://localhost:8080/', they should
        say b'https://www.example.com/', so we do::

           request.setHost(b'www.example.com', 443, ssl=1)

        @type host: C{bytes}
        @param host: The value to which to change the host header.

        @type ssl: C{bool}
        @param ssl: A flag which, if C{True}, indicates that the request is
            considered secure (if C{True}, L{isSecure} will return C{True}).
        """
        self._forceSSL = ssl # set first so isSecure will work
        if self.isSecure():
            default = 443
        else:
            default = 80
        if port == default:
            hostHeader = host
        else:
            hostHeader = host + b":" + intToBytes(port)
        self.requestHeaders.setRawHeaders(b"host", [hostHeader])
        self.host = address.IPv4Address("TCP", host, port) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:35,代码来源:http.py

示例15: getClientIP

# 需要导入模块: from twisted.internet import address [as 别名]
# 或者: from twisted.internet.address import IPv4Address [as 别名]
def getClientIP(self):
        """
        Return the IP address of the client who submitted this request.

        @returns: the client IP address
        @rtype: C{str}
        """
        if isinstance(self.client, address.IPv4Address):
            return self.client.host
        else:
            return None 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:http.py


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