Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwisted_main.py
More file actions
Latest commit
62 lines (47 loc) · 1.84 KB
/
Copy pathtwisted_main.py
File metadata and controls
62 lines (47 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Run this example with:
python -m github.twisted_main
This is an example of using Effect with Twisted.
It's important to note that none of the application code relies on Twisted --
this is the only file that has any dependencies on Twisted. There's also an
example of running the same application code in ``sync_main.py`` in the same
directory.
This code has these responsibilities:
- set up a dispatcher that knows how to find performers for all intents
used in this application. The application uses ReadLine, HTTPRequest, and
ParallelEffects.
- use :func:`texeffect.perform` to perform an effect, which returns a
Deferred that we can return from our react function.
"""
from __future__ importprint_function
fromtwisted.internet.taskimportreact
fromtxeffectimportmake_twisted_dispatcher, perform
fromeffectimportComposedDispatcher, TypeDispatcher
fromehttp.http_intentimportHTTPRequest
fromehttp.twisted_httpimportperform_request_with_treq
fromreadline_intentimportReadLine, perform_readline_stdin
from .coreimportmain_effect
defget_dispatcher(reactor):
"""
Create a dispatcher that can find performers for :obj:`ReadLine`,
:obj:`HTTPRequest`, and :obj:`ParallelEffects`.
:func:`make_twisted_dispatcher` is able to provide the ``ParallelEffects``
performer, so we compose it with our own custom :obj:`TypeDispatcher`.
"""
returnComposedDispatcher(
[
TypeDispatcher(
{
ReadLine: perform_readline_stdin,
HTTPRequest: perform_request_with_treq,
}
),
make_twisted_dispatcher(reactor),
]
)
defmain(reactor):
dispatcher=get_dispatcher(reactor)
eff=main_effect()
returnperform(dispatcher, eff).addCallback(print)
if__name__=="__main__":
react(main, [])