本文整理汇总了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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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))
示例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)
示例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())
示例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())
示例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
示例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)