1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
4
# You can run this .tac file directly with:
5
# twistd -ny demo_manhole.tac
7
"""An interactive Python interpreter with syntax coloring.
9
Nothing interesting is actually defined here. Two listening ports are
10
set up and attached to protocols which know how to properly set up a
11
ColoredManhole instance.
14
from twisted.conch.manhole import ColoredManhole
15
from twisted.conch.insults import insults
16
from twisted.conch.telnet import TelnetTransport, TelnetBootstrapProtocol
17
from twisted.conch.manhole_ssh import ConchFactory, TerminalRealm
19
from twisted.internet import protocol
20
from twisted.application import internet, service
21
from twisted.cred import checkers, portal
23
def makeService(args):
24
checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
26
f = protocol.ServerFactory()
27
f.protocol = lambda: TelnetTransport(TelnetBootstrapProtocol,
28
insults.ServerProtocol,
29
args['protocolFactory'],
30
*args.get('protocolArgs', ()),
31
**args.get('protocolKwArgs', {}))
32
tsvc = internet.TCPServer(args['telnet'], f)
34
def chainProtocolFactory():
35
return insults.ServerProtocol(
36
args['protocolFactory'],
37
*args.get('protocolArgs', ()),
38
**args.get('protocolKwArgs', {}))
41
rlm.chainedProtocolFactory = chainProtocolFactory
42
ptl = portal.Portal(rlm, [checker])
44
csvc = internet.TCPServer(args['ssh'], f)
46
m = service.MultiService()
47
tsvc.setServiceParent(m)
48
csvc.setServiceParent(m)
51
application = service.Application("Interactive Python Interpreter")
53
makeService({'protocolFactory': ColoredManhole,
54
'protocolArgs': (None,),
56
'ssh': 6022}).setServiceParent(application)