当前位置: 首页>>代码示例>>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;未经允许,请勿转载。