-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
699 lines (647 loc) · 26.5 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Twisted</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="assets/images/favicon.ico">
<link href="vendor/css/bootstrap-v4.5.3.min.css" rel="stylesheet" type="text/css" media="all" />
<link href="vendor/css/bootstrap-icons.css" rel="stylesheet" type="text/css" media="all" />
<link href="vendor/css/default.min.css" rel="stylesheet" type="text/css" media="all" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<header>
<div class="navbar-container layer-2">
<nav class="navbar navbar-expand-lg justify-content-between navbar-light shadow">
<div class="container">
<div class="col flex-fill px-0 d-flex justify-content-between">
<a class="navbar-brand" href="/" title="Twisted">
<img src="assets/images/twisted-logo-small.svg" alt="Twisted" class="logo"/>
<h1 class="d-inline align-middle">Twisted</h1>
</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target=".navbar-collapse"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link"
href="https://github.com/twisted/trac-wiki-archive/blob/trunk/FrequentlyAskedQuestions.mediawiki">
FAQ
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://docs.twisted.org/">
Docs
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://pypi.org/project/Twisted/">
Download
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">
About
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#donate">
Donate
</a>
</li>
</ul>
</div>
</div>
</nav>
</div>
</header>
<section class="pb-2">
<img src="assets/images/ribbon.svg" class="ribbon d-none d-md-block">
<div class="container">
<div class="row justify-content-center text-center mb-2 layer-2">
<div class="col-9 col-xl-12">
<h1 class="display-4 font-weight-bold">
An event-driven networking engine
</h1>
<h2>
Written in Python
</h2>
<p class="lead">Licensed under the open source MIT License</p>
<div class="d-flex flex-md-row flex-column justify-content-center align-items-center my-4">
<a href="https://github.com/twisted/twisted"
class="btn btn-lg btn-outline-dark mx-3 mb-2 mb-md-0">
<i class="bi bi-github"></i>
<span>View Github</span>
</a>
<a href="https://docs.twisted.org/" class="btn btn-lg btn-primary text-white">
View Documentation
</a>
</div>
<a href="https://pypi.org/project/Twisted/">
Check PyPi download page
<i class="bi bi-arrow-right-short"></i>
</a>
</div>
</div>
<div class="row justify-content-center mt-4">
<div class="col-xl-4 col-lg-8 col-md-8 col-12">
<div>
<pre class="bash-code">
<code class="rounded language-bash pt-0">
$ virtualenv try-twisted
$ . try-twisted/bin/activate
$ pip install twisted[tls]
$ twist --help
</code>
</pre>
</div>
</div>
</div>
</div>
</section>
<section class="p-0 pt-1 pb-4 border-bottom border-secondary premium-sponsors">
<div class="bg-secondary text-white py-1">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-auto">
<span class="h6">Premium Sponsors</span>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row align-items-center justify-content-center">
<div class="col-auto">
<a href="https://thinkst.com/" target="_blank">
<img src="assets/images/sponsor-thinkst.svg"
alt="Thinkst Canary"
title="Thinkst Canary"
class="img-fluid"/>
</a>
</div>
</div>
</div>
</section>
<section class="has-divider">
<div class="container">
<div class="row justify-content-center">
<div class="col">
<nav>
<div class="nav nav-pills nav-fill" id="nav-tab" role="tablist">
<a class="nav-item nav-link active"
id="nav-echo-server-tab"
data-toggle="tab"
href="#nav-echo-server"
role="tab"
aria-controls="nav-echo-server"
aria-selected="true">
Echo Server
</a>
<a class="nav-item nav-link"
id="nav-web-server-tab"
data-toggle="tab"
href="#nav-web-server"
role="tab"
aria-controls="nav-web-server"
aria-selected="false">
Web Server
</a>
<a class="nav-item nav-link"
id="nav-publish-tab"
data-toggle="tab"
href="#nav-publish"
role="tab"
aria-controls="nav-publish"
aria-selected="false">
Publish/Subscribe
</a>
<a class="nav-item nav-link"
id="nav-mail-tab"
data-toggle="tab"
href="#nav-mail"
role="tab"
aria-controls="nav-mail"
aria-selected="false">
Mail Client
</a>
<a class="nav-item nav-link"
id="nav-ssh-tab"
data-toggle="tab"
href="#nav-ssh"
role="tab"
aria-controls="nav-ssh"
aria-selected="false">
SSH Client
</a>
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-echo-server" role="tabpanel" aria-labelledby="nav-echo-server-tab">
<p>
Twisted makes it easy to implement custom network applications.
Here's a TCP server that echoes back everything that's written to it:
</p>
<pre>
<code class="language-python" id="server">
from twisted.internet import protocol, reactor, endpoints
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())
reactor.run()
</code>
</pre>
<p>
Learn more about
<a href="https://docs.twisted.org/en/stable/core/howto/servers.html">
writing servers</a>,
<a href="https://docs.twisted.org/en/stable/core/howto/clients.html">
writing clients</a> and the
<a href="https://docs.twisted.org/en/stable/core/howto/index.html">
core networking libraries</a>, including support for
SSL, UDP, scheduled events, unit testing infrastructure, and much more.
</p>
</div>
<div class="tab-pane fade" id="nav-web-server" role="tabpanel" aria-labelledby="nav-web-server-tab">
<p>
Twisted includes an event-driven web server. Here's a sample web application;
notice how the resource object persists in memory, rather than being recreated on each request:
</p>
<pre>
<code class="language-python">
from twisted.web import server, resource
from twisted.internet import reactor, endpoints
class Counter(resource.Resource):
isLeaf = True
numberRequests = 0
def render_GET(self, request):
self.numberRequests += 1
request.setHeader(b"content-type", b"text/plain")
content = u"I am request #{}\n".format(self.numberRequests)
return content.encode("ascii")
endpoints.serverFromString(reactor, "tcp:8080").listen(server.Site(Counter()))
reactor.run()
</code>
</pre>
<p>
Learn more about
<a href="https://docs.twisted.org/en/stable/web/howto/web-in-60/index.html">
web application development</a>,
<a href="https://docs.twisted.org/en/stable/web/howto/twisted-templates.html">
templates</a> and Twisted'
<a href="https://docs.twisted.org/en/stable/web/howto/client.html">
HTTP client</a>.
</p>
</div>
<div class="tab-pane fade" id="nav-publish" role="tabpanel" aria-labelledby="nav-publish-tab">
<p>
Here's a simple publish/subscribe server, where clients see all messages posted by other clients:
</p>
<pre>
<code class="language-python">
from twisted.internet import reactor, protocol, endpoints
from twisted.protocols import basic
class PubProtocol(basic.LineReceiver):
def __init__(self, factory):
self.factory = factory
def connectionMade(self):
self.factory.clients.add(self)
def connectionLost(self, reason):
self.factory.clients.remove(self)
def lineReceived(self, line):
for c in self.factory.clients:
source = u"<{}> ".format(self.transport.getHost()).encode("ascii")
c.sendLine(source + line)
class PubFactory(protocol.Factory):
def __init__(self):
self.clients = set()
def buildProtocol(self, addr):
return PubProtocol(self)
endpoints.serverFromString(reactor, "tcp:1025").listen(PubFactory())
reactor.run()
</code>
</pre>
<p>
You can test this out by opening two terminals and doing telnet localhost 1025 in each, then typing things.
</p>
</div>
<div class="tab-pane fade" id="nav-mail" role="tabpanel" aria-labelledby="nav-mail-tab">
<p>
Twisted includes a sophisticated IMAP4 client library.
</p>
<pre>
<code class="language-python">
import sys
from twisted.internet import protocol, defer, endpoints, task
from twisted.mail import imap4
from twisted.python import failure
async def main(
reactor, username="alice", password="secret", strport="tls:example.com:993"
):
endpoint = endpoints.clientFromString(reactor, strport)
factory = protocol.Factory.forProtocol(imap4.IMAP4Client)
try:
client = await endpoint.connect(factory)
await client.login(username.encode("utf-8"),
password.encode("utf-8"))
await client.select("INBOX")
info = await client.fetchEnvelope(imap4.MessageSet(1))
print("First message subject:", info[1]["ENVELOPE"][1])
except:
print("IMAP4 client interaction failed")
print(failure.Failure().getTraceback())
task.react(lambda *a, **k: defer.ensureDeferred(main(*a, **k)), sys.argv[1:])
</code>
</pre>
<p>
Give this a try, supplying your IMAP4 username, app password
(<a class="ext-link" href="https://support.google.com/accounts/answer/185833?hl=en">generate one for gmail</a>,
<a class="ext-link" href="https://www.fastmail.com/help/clients/apppassword.html">generate one for fastmail</a>), and
<a class="ext-link" href="https://docs.twisted.org/en/stable/core/howto/endpoints.html">
client endpoint description
</a>
for your IMAP4 server. You'll see the subject of the first message in your mailbox printed.
</p>
<p>
See the
<a class="wiki" href="https://github.com/twisted/trac-wiki-archive/blob/trunk/TwistedMail.mediawiki">
TwistedMail
</a>
documentation for more information.
</p>
</div>
<div class="tab-pane fade" id="nav-ssh" role="tabpanel" aria-labelledby="nav-ssh-tab">
<p>
Twisted includes an SSH client & server, "conch" (i.e.: the Twisted Shell).
</p>
<pre>
<code class="language-python">
import sys, os
from twisted.internet import protocol, defer, endpoints, task
from twisted.conch.endpoints import SSHCommandClientEndpoint
async def main(reactor, username="alice", sshhost="example.com", portno="22"):
envAgent = endpoints.UNIXClientEndpoint(reactor, os.environ["SSH_AUTH_SOCK"])
endpoint = SSHCommandClientEndpoint.newConnection(
reactor, "echo 'hello world'", username, sshhost,
int(portno), agentEndpoint=envAgent,
)
class ShowOutput(protocol.Protocol):
received = b""
def dataReceived(self, data):
self.received += data
def connectionLost(self, reason):
finished.callback(self.received)
finished = defer.Deferred()
factory = protocol.Factory.forProtocol(ShowOutput)
await endpoint.connect(factory)
print("SSH response:", await finished)
task.react(lambda *a, **k: defer.ensureDeferred(main(*a, **k)), sys.argv[1:])
</code>
</pre>
<p>
You can use this client to run "hello world" on any SSH server
that your local SSH agent can authenticate to,
if you pass your username, host name, and optionally port number on the command line.
</p>
</div>
</div>
</div>
</div>
</div>
<div class="divider">
<img class="bg-dark" src="assets/images/divider.svg" alt="divider graphic" data-inject-svg />
</div>
</section>
<section class="bg-dark text-light py-2" id="about">
<div class="container">
<div class="row mb-4">
<div class="col">
<h1>About Twisted</h1>
</div>
</div>
<div class="row">
<div class="col-md-4 d-flex mb-4">
<i class="icon bi bi-puzzle"></i>
<div class="ml-2">
<h3>More Protocols</h3>
<p>
Twisted also supports many common network protocols,
including SMTP, POP3, IMAP, SSHv2, and DNS.
</p>
<p>For more information see our
<a class="wiki" href="https://docs.twisted.org/">
documentation
</a>
and
<a class="ext-link" href="https://docs.twisted.org/en/stable/api/">
API reference</a>.
</p>
</div>
</div>
<div class="col-md-4 d-flex mb-4">
<i class="icon bi bi-people-fill"></i>
<div class="ml-2">
<h3>Community</h3>
<p>
Get in touch with the
<a class="wiki" href="https://docs.twisted.org/en/latest/community.html">
Twisted community
</a>
through
<a class="wiki" href="https://docs.twisted.org/en/latest/community.html#mail-lists">
email</a>,
<a class="ext-link" href="https://stackoverflow.com/questions/tagged/twisted">
Stack Overflow
</a>
or
<a class="wiki" href="https://docs.twisted.org/en/latest/community.html#real-time-chat">
Gitter / IRC</a>.
</p>
</div>
</div>
<div class="col-md-4 d-flex mb-4">
<i class="icon bi bi-lightbulb-fill"></i>
<div class="ml-2">
<h3>Contribute</h3>
<p>
Learn about the Twisted
<a class="wiki" href="https://github.com/twisted/trac-wiki-archive/blob/trunk/TwistedDevelopment.mediawiki">
development process</a>
and how to
<a class="wiki" href="https://github.com/twisted/trac-wiki-archive/blob/trunk/ContributingToTwistedLabs.mediawiki">
contribute</a>.
</p>
<p>
Help improve Twisted on
<a class="wiki" href="https://github.com/twisted/trac-wiki-archive/blob/trunk/Windows.mediawiki">
Windows</a>!
</p>
</div>
</div>
<div class="col-md-4 d-flex mb-4">
<i class="icon bi bi-search"></i>
<div class="ml-2">
<h3>Wiki</h3>
<p>
Read about
<a
class="wiki"
href="https://github.com/twisted/trac-wiki-archive/blob/trunk/ProjectsUsingTwisted.mediawiki">
software using
</a>
Twisted and their
<a class="wiki" href="https://github.com/twisted/trac-wiki-archive/blob/trunk/SuccessStories.mediawiki">
success stories</a>.
</p>
</div>
</div>
<div class="col-md-4 d-flex mb-4">
<i class="icon bi bi-gift-fill"></i>
<div class="ml-2">
<h3>Sponsors</h3>
<p>
Learn about the
<a
href="https://docs.twisted.org/en/latest/development/sponsorship.html">
individuals and organisations
</a>
that sponsor Twisted development.
</p>
</div>
</div>
<div class="col-md-4 d-flex mb-4">
<i class="icon bi bi-grid-3x3-gap"></i>
<div class="ml-2">
<h3>Twisted Matrix Laboratories</h3>
<p>
Find out what
<a
class="wiki"
href="https://github.com/twisted/trac-wiki-archive/blob/trunk/TwistedMatrixLaboratories.mediawiki">
Twisted Matrix Laboratories
</a>is.
</p>
</div>
</div>
</div>
</div>
</section>
<section class="py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-xl-11">
<div class="row">
<div class="col-md-6 d-flex mb-4" >
<div class="icon-round bg-primary mr-3">
<i class="icon bi bi-github text-primary"></i>
</div>
<div>
<h4>See our code on Github</h4>
<p>See the code
<a class="ext-link" href="https://github.com/twisted/twisted">
<span class="icon"></span>for Twisted
</a>
(<a class="ext-link" href="https://github.com/twisted"><span class="icon"></span>and more</a>)
on GitHub.
</p>
</div>
</div>
<div class="col-md-6 d-flex mb-4">
<div class="icon-round bg-primary mr-3">
<i class="icon bi bi-shield-check text-primary"></i>
</div>
<div>
<h4>Supported Python</h4>
<p class="mb-0">It supports CPython 3.7+ and PyPy3.</p>
<p class="mb-0">
<a href="https://labs.twistedmatrix.com/2020/03/twisted-drops-python-27-support.html">
Twisted 20.3.0
</a> was the last version with Python 2.7 and PyPy2 support.
</p>
</div>
</div>
<div class="col-md-6 d-flex mb-4 align-items-center">
<div class="icon-round bg-primary mr-3">
<i class="icon bi bi-envelope-open text-primary"></i>
</div>
<div>
<h4>Join the
<a href="https://mail.python.org/mailman3/lists/twisted.python.org/">
discussion list
</a>
</h4>
</div>
</div>
<div class="col-md-6 d-flex mb-4 align-items-center">
<div class="icon-round bg-primary mr-3">
<i class="icon bi bi-shield-lock-fill text-primary"></i>
</div>
<div>
<h4>Report a
<a href="https://github.com/twisted/twisted/security/policy">
security issue
</a>
</h4>
</div>
</div>
<div class="col-md-6 d-flex mb-4 align-items-center">
<div class="icon-round bg-primary mr-3">
<i class="icon bi bi-stack text-primary"></i>
</div>
<div>
<h4>Ask on
<a href="https://stackoverflow.com/questions/tagged/twisted">
Stack Overflow
</a>
</h4>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="py-0">
<div class="container-fluid">
<div class="bg-secondary text-white py-2 row text-center">
<div class="col">
<span class="h2">Twisted Sponsors</span>
</div>
</div>
<div class="premium-sponsors row align-items-center justify-content-center">
<div class="col-auto">
<a href="https://thinkst.com/" target="_blank">
<img src="assets/images/sponsor-thinkst.svg"
alt="Thinkst Canary"
title="Thinkst Canary"
class="img-fluid"/>
</a>
</div>
</div>
<div class="standard-sponsors row align-items-center justify-content-center pb-4">
<div class="col-auto">
<a href="https://www.sftpplus.com/" target="_blank">
<img src="assets/images/sponsor-sftpplus.svg"
alt=""
title=""
class="img-fluid"/>
</a>
</div>
</div>
<div class="row text-center">
<div class="col">
<p>
Financial support can be provided for the Twisted project via
<a href="https://psfmember.org/civicrm/contribute/transact/?reset=1&id=44">
the Python Software Foundation</a> or via <a href="https://github.com/sponsors/twisted/">
GitHub Sponsors</a> !
</p>
<p>
For donations greater than $400 per month, we will display your logo at the top of the page.
For donations greater than $200 per month, we will display your logo on this page.
Check <a href="https://github.com/sponsors/twisted/">
GitHub Sponsors</a> for more information about sponsoring perks.
</p>
</div>
</div>
</div>
</section>
<section class="pt-2 pb-4" id="donate">
<div class="container">
<div class="row">
<div class="col">
<div class="card card-body border-0 o-hidden mb-0 shadow-3d text-light bg-primary">
<div class="position-relative d-flex flex-column flex-md-row justify-content-between align-items-center">
<div class="text-center mb-md-0">
<h1>Donate to Twisted</h1>
<p>
Donations are tax-deductible in USA<br>
<a href="https://www.python.org/psf-landing/"
class="text-dark">
via the Python Software Foundation</a>.
</p>
</div>
<div class="donation-buttons layer-2 text-center">
<a href="https://psfmember.org/civicrm/contribute/transact/?reset=1&id=44"
class="btn btn-lg btn-light mb-2">
Donate <span class="small">(via PSF)</span>
</a>
</div>
</div>
<div class="decoration middle-x d-none d-lg-block layer-1">
<img class="bg-dark" src="assets/images/deco-blob.svg" alt="deco-blob decoration" data-inject-svg />
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Required vendor scripts (Do not remove) -->
<script type="text/javascript" src="vendor/js/jquery-v3.5.1.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous">
</script>
<script type="text/javascript" src="vendor/js/bootstrap-v4.5.3.min.js"></script>
<script type="text/javascript" src="vendor/js/highlight.min.js"></script>
<script src="vendor/js/clipboard.min.js"></script>
<!-- SVGInjector (replaces img tags with SVG code to allow easy inclusion of SVGs with the benefit of inheriting colors and styles)-->
<script type="text/javascript" src="vendor/js/svg-inject-v1.2.3.js"></script>
<script type="text/javascript" src="assets/js/code.js"></script>
</body>
</html>