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


Python twisted.internet方法代码示例

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


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

示例1: test_deprecated

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_deprecated(self):
        """
        Accessing L{PotentialZombieWarning} via the
        I{PotentialZombieWarning} attribute of L{twisted.internet.error}
        results in a deprecation warning being emitted.
        """
        from twisted.internet import error
        error.PotentialZombieWarning

        warnings = self.flushWarnings([self.test_deprecated])
        self.assertEqual(warnings[0]['category'], DeprecationWarning)
        self.assertEqual(
            warnings[0]['message'],
            "twisted.internet.error.PotentialZombieWarning was deprecated in "
            "Twisted 10.0.0: There is no longer any potential for zombie "
            "process.")
        self.assertEqual(len(warnings), 1) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_process.py

示例2: uninstall_twisted_reactor

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def uninstall_twisted_reactor():
    '''Uninstalls the Kivy's threaded Twisted Reactor. No more Twisted
    tasks will run after this got called. Use this to clean the
    `twisted.internet.reactor` .

    .. versionadded:: 1.9.0
    '''

    import twisted

    # prevent uninstalling more than once
    if not hasattr(twisted, '_kivy_twisted_reactor_installed'):
        return

    from kivy.base import EventLoop

    global _twisted_reactor_stopper
    _twisted_reactor_stopper()
    EventLoop.unbind(on_stop=_twisted_reactor_stopper)

    del twisted._kivy_twisted_reactor_installed 
开发者ID:BillBillBillBill,项目名称:Tickeys-linux,代码行数:23,代码来源:support.py

示例3: test_none_return_statement

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_none_return_statement(self):
        python_node = self.get_ast_node(
            """
            from twisted.internet import defer

            @defer.inlineCallbacks
            def func(arg):
                return None
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [] if IS_PYTHON_3_3 else [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=4,
                message=dlint.linters.YieldReturnStatementLinter._error_tmpl
            )
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:26,代码来源:test_yield_return_statement.py

示例4: test_empty_return_statement

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_empty_return_statement(self):
        python_node = self.get_ast_node(
            """
            from twisted.internet import defer

            @defer.inlineCallbacks
            def func(arg):
                return
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:20,代码来源:test_yield_return_statement.py

示例5: test_non_empty_return_statement

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_non_empty_return_statement(self):
        python_node = self.get_ast_node(
            """
            from twisted.internet import defer

            @defer.inlineCallbacks
            def func(arg):
                return arg
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [] if IS_PYTHON_3_3 else [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=4,
                message=dlint.linters.YieldReturnStatementLinter._error_tmpl
            )
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:26,代码来源:test_yield_return_statement.py

示例6: test_nested_function_return_statement

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_nested_function_return_statement(self):
        python_node = self.get_ast_node(
            """
            from twisted.internet import defer

            @defer.inlineCallbacks
            def func(arg):
                if arg:
                    arg += 5

                def inner_func():
                    return arg

                return
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:26,代码来源:test_yield_return_statement.py

示例7: test_nested_class_return_statement

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_nested_class_return_statement(self):
        python_node = self.get_ast_node(
            """
            from twisted.internet import defer

            @defer.inlineCallbacks
            def func(arg):
                if arg:
                    arg += 5

                class inner_class:
                    def inner_func():
                        return arg

                return
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:27,代码来源:test_yield_return_statement.py

示例8: test_short_import

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_short_import(self):
        python_node = self.get_ast_node(
            """
            import twisted

            @twisted.internet.defer.inlineCallbacks
            def func(arg):
                return arg
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [] if IS_PYTHON_3_3 else [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=4,
                message=dlint.linters.YieldReturnStatementLinter._error_tmpl
            )
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:26,代码来源:test_yield_return_statement.py

示例9: test_long_import

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_long_import(self):
        python_node = self.get_ast_node(
            """
            from twisted.internet.defer import inlineCallbacks

            @inlineCallbacks
            def func(arg):
                return arg
            """
        )

        linter = dlint.linters.YieldReturnStatementLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [] if IS_PYTHON_3_3 else [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=4,
                message=dlint.linters.YieldReturnStatementLinter._error_tmpl
            )
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:26,代码来源:test_yield_return_statement.py

示例10: test_returns_Deferred_that_wont_be_cancelled_if_called

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_returns_Deferred_that_wont_be_cancelled_if_called(self):
        clock = self.patch(internet, "reactor", Clock())

        # Called without a function argument, `deferWithTimeout` returns a new
        # Deferred, and schedules it to be cancelled in `timeout` seconds.
        timeout = randint(10, 100)
        d = deferWithTimeout(timeout)
        [delayed_call] = clock.getDelayedCalls()

        # Advance some amount of time to simulate something happening.
        clock.advance(5)
        # The timeout call is still in place.
        self.assertThat(delayed_call, DelayedCallActive)

        d.callback(sentinel.result)
        # After calling d the timeout call has been cancelled.
        self.assertThat(delayed_call, DelayedCallCancelled)
        # The result has been safely passed on.
        self.assertThat(extract_result(d), Is(sentinel.result)) 
开发者ID:maas,项目名称:maas,代码行数:21,代码来源:test_twisted.py

示例11: test_returns_Deferred_that_wont_be_cancelled_if_errored

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_returns_Deferred_that_wont_be_cancelled_if_errored(self):
        clock = self.patch(internet, "reactor", Clock())

        # Called without a function argument, `deferWithTimeout` returns a new
        # Deferred, and schedules it to be cancelled in `timeout` seconds.
        timeout = randint(10, 100)
        d = deferWithTimeout(timeout)
        [delayed_call] = clock.getDelayedCalls()

        # Advance some amount of time to simulate something happening, but
        # less than the timeout.
        clock.advance(timeout - 1)
        # The timeout call is still in place.
        self.assertThat(delayed_call, DelayedCallActive)

        error = RuntimeError()
        d.errback(error)
        # After calling d the timeout call has been cancelled.
        self.assertThat(delayed_call, DelayedCallCancelled)
        # The error has been passed safely on.
        self.assertRaises(RuntimeError, extract_result, d) 
开发者ID:maas,项目名称:maas,代码行数:23,代码来源:test_twisted.py

示例12: test_wait_waits_until_lock_can_be_acquired

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_wait_waits_until_lock_can_be_acquired(self):
        clock = self.patch(internet, "reactor", Clock())
        sleep = self.patch(fs_module, "sleep")
        sleep.side_effect = clock.advance

        lock = self.make_lock()
        do_lock = self.patch(lock._fslock, "lock")
        do_unlock = self.patch(lock._fslock, "unlock")

        do_lock.side_effect = [False, False, True]

        with lock.wait(10):
            self.assertThat(do_lock, MockCallsMatch(call(), call(), call()))
            self.assertThat(sleep, MockCallsMatch(call(1.0), call(1.0)))
            self.assertThat(do_unlock, MockNotCalled())

        self.assertThat(do_unlock, MockCalledOnceWith()) 
开发者ID:maas,项目名称:maas,代码行数:19,代码来源:test_fs.py

示例13: test_wait_raises_exception_when_time_has_run_out

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_wait_raises_exception_when_time_has_run_out(self):
        clock = self.patch(internet, "reactor", Clock())
        sleep = self.patch(fs_module, "sleep")
        sleep.side_effect = clock.advance

        lock = self.make_lock()
        do_lock = self.patch(lock._fslock, "lock")
        do_unlock = self.patch(lock._fslock, "unlock")

        do_lock.return_value = False

        with ExpectedException(self.locktype.NotAvailable):
            with lock.wait(0.2):
                pass

        self.assertThat(do_lock, MockCallsMatch(call(), call(), call()))
        self.assertThat(sleep, MockCallsMatch(call(0.1), call(0.1)))
        self.assertThat(do_unlock, MockNotCalled()) 
开发者ID:maas,项目名称:maas,代码行数:20,代码来源:test_fs.py

示例14: start

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def start(self):
        CHECK(self.deferred is None)
        self.deferred = defer.Deferred()

        self.main.showLoginStatus("Scanning For Online Nodes...", counter=1)

        # Get the main UDP socket's bind interface (usually empty)
        bind_ip = self.main.ph.transport.interface

        # Listen on an arbitrary UDP port
        try:
            reactor.listenUDP(0, self, interface=bind_ip)
        except twisted.internet.error.BindError:
            self.main.showLoginStatus("Failed to bind alt UDP port!")
            self.deferred.callback(('no_nodes', None))
        else:
            self.scheduleInitRequest()

        return self.deferred 
开发者ID:ffledgling,项目名称:dtella,代码行数:21,代码来源:core.py

示例15: test_processCommandLineArguments

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import internet [as 别名]
def test_processCommandLineArguments(self):
        """
        Arguments given to spawnProcess are passed to the child process as
        originally intended.
        """
        us = b"twisted.internet.test.process_cli"

        args = [b'hello', b'"', b' \t|<>^&', br'"\\"hello\\"', br'"foo\ bar baz\""']
        # Ensure that all non-NUL characters can be passed too.
        if _PY3:
            args.append("".join(map(chr, xrange(1,255))).encode("utf8"))
        else:
            args.append("".join(map(chr, xrange(1,255))))

        reactor = self.buildReactor()

        def processFinished(finishedArgs):
            output, err, code = finishedArgs
            output = output.split(b'\0')
            # Drop the trailing \0.
            output.pop()
            self.assertEqual(args, output)

        def shutdown(result):
            reactor.stop()
            return result

        def spawnChild():
            d = succeed(None)
            d.addCallback(lambda dummy: utils.getProcessOutputAndValue(
                pyExe, [b"-m", us] + args, env=properEnv,
                reactor=reactor))
            d.addCallback(processFinished)
            d.addBoth(shutdown)

        reactor.callWhenRunning(spawnChild)
        self.runReactor(reactor) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:39,代码来源:test_process.py


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