當前位置: 首頁>>代碼示例>>Python>>正文


Python policies.TrafficLoggingFactory方法代碼示例

本文整理匯總了Python中twisted.protocols.policies.TrafficLoggingFactory方法的典型用法代碼示例。如果您正苦於以下問題:Python policies.TrafficLoggingFactory方法的具體用法?Python policies.TrafficLoggingFactory怎麽用?Python policies.TrafficLoggingFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.protocols.policies的用法示例。


在下文中一共展示了policies.TrafficLoggingFactory方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_thingsGetLogged

# 需要導入模塊: from twisted.protocols import policies [as 別名]
# 或者: from twisted.protocols.policies import TrafficLoggingFactory [as 別名]
def test_thingsGetLogged(self):
        """
        Check the output produced by L{policies.TrafficLoggingFactory}.
        """
        wrappedFactory = Server()
        wrappedFactory.protocol = WriteSequenceEchoProtocol
        t = StringTransportWithDisconnection()
        f = TestLoggingFactory(wrappedFactory, 'test')
        p = f.buildProtocol(('1.2.3.4', 5678))
        t.protocol = p
        p.makeConnection(t)

        v = f.openFile.getvalue()
        self.assertIn('*', v)
        self.assertFalse(t.value())

        p.dataReceived(b'here are some bytes')

        v = f.openFile.getvalue()
        self.assertIn("C 1: %r" % (b'here are some bytes',), v)
        self.assertIn("S 1: %r" % (b'here are some bytes',), v)
        self.assertEqual(t.value(), b'here are some bytes')

        t.clear()
        p.dataReceived(b'prepare for vector! to the extreme')
        v = f.openFile.getvalue()
        self.assertIn("SV 1: %r" % ([b'prepare for vector! to the extreme'],), v)
        self.assertEqual(t.value(), b'prepare for vector! to the extreme')

        p.loseConnection()

        v = f.openFile.getvalue()
        self.assertIn('ConnectionDone', v) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:35,代碼來源:test_policies.py

示例2: test_loggingFactoryOpensLogfileAutomatically

# 需要導入模塊: from twisted.protocols import policies [as 別名]
# 或者: from twisted.protocols.policies import TrafficLoggingFactory [as 別名]
def test_loggingFactoryOpensLogfileAutomatically(self):
        """
        When the L{policies.TrafficLoggingFactory} builds a protocol, it
        automatically opens a unique log file for that protocol and attaches
        the logfile to the built protocol.
        """
        open_calls = []
        open_rvalues = []

        def mocked_open(*args, **kwargs):
            """
            Mock for the open call to prevent actually opening a log file.
            """
            open_calls.append((args, kwargs))
            io = NativeStringIO()
            io.name = args[0]
            open_rvalues.append(io)
            return io

        self.patch(builtins, 'open', mocked_open)

        wrappedFactory = protocol.ServerFactory()
        wrappedFactory.protocol = SimpleProtocol
        factory = policies.TrafficLoggingFactory(wrappedFactory, 'test')
        first_proto = factory.buildProtocol(address.IPv4Address('TCP',
                                                                '127.0.0.1',
                                                                12345))
        second_proto = factory.buildProtocol(address.IPv4Address('TCP',
                                                                 '127.0.0.1',
                                                                 12346))

        # We expect open to be called twice, with the files passed to the
        # protocols.
        first_call = (('test-1', 'w'), {})
        second_call = (('test-2', 'w'), {})
        self.assertEqual([first_call, second_call], open_calls)
        self.assertEqual(
            [first_proto.logfile, second_proto.logfile], open_rvalues
        ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:41,代碼來源:test_policies.py

示例3: _getAdder

# 需要導入模塊: from twisted.protocols import policies [as 別名]
# 或者: from twisted.protocols.policies import TrafficLoggingFactory [as 別名]
def _getAdder(self, *args, **kw):
        self.adderAPI = TrafficLoggingFactory(AdderPlugin(*args, **kw), "adder-")
        self.adderServer = reactor.listenTCP(0, self.adderAPI)
        self.adderPort = self.adderServer.getHost().port 
開發者ID:ClusterHQ,項目名稱:powerstrip,代碼行數:6,代碼來源:test_core.py

示例4: _getAdderTwo

# 需要導入模塊: from twisted.protocols import policies [as 別名]
# 或者: from twisted.protocols.policies import TrafficLoggingFactory [as 別名]
def _getAdderTwo(self, *args, **kw):
        kw["incrementBy"] = 2
        self.adderTwoAPI = TrafficLoggingFactory(AdderPlugin(*args, **kw), "adder2-")
        self.adderTwoServer = reactor.listenTCP(0, self.adderTwoAPI)
        self.adderTwoPort = self.adderTwoServer.getHost().port 
開發者ID:ClusterHQ,項目名稱:powerstrip,代碼行數:7,代碼來源:test_core.py

示例5: test_thingsGetLogged

# 需要導入模塊: from twisted.protocols import policies [as 別名]
# 或者: from twisted.protocols.policies import TrafficLoggingFactory [as 別名]
def test_thingsGetLogged(self):
        """
        Check the output produced by L{policies.TrafficLoggingFactory}.
        """
        wrappedFactory = Server()
        wrappedFactory.protocol = WriteSequenceEchoProtocol
        t = StringTransportWithDisconnection()
        f = TestLoggingFactory(wrappedFactory, 'test')
        p = f.buildProtocol(('1.2.3.4', 5678))
        t.protocol = p
        p.makeConnection(t)

        v = f.openFile.getvalue()
        self.failUnless('*' in v, "* not found in %r" % (v,))
        self.failIf(t.value())

        p.dataReceived('here are some bytes')

        v = f.openFile.getvalue()
        self.assertIn("C 1: 'here are some bytes'", v)
        self.assertIn("S 1: 'here are some bytes'", v)
        self.assertEquals(t.value(), 'here are some bytes')

        t.clear()
        p.dataReceived('prepare for vector! to the extreme')
        v = f.openFile.getvalue()
        self.assertIn("SV 1: ['prepare for vector! to the extreme']", v)
        self.assertEquals(t.value(), 'prepare for vector! to the extreme')

        p.loseConnection()

        v = f.openFile.getvalue()
        self.assertIn('ConnectionDone', v) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:35,代碼來源:test_policies.py


注:本文中的twisted.protocols.policies.TrafficLoggingFactory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。