~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/conch/examples/demo_manhole.tac

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
# You can run this .tac file directly with:
 
5
#    twistd -ny demo_manhole.tac
 
6
 
 
7
"""An interactive Python interpreter with syntax coloring.
 
8
 
 
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.
 
12
"""
 
13
 
 
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
 
18
 
 
19
from twisted.internet import protocol
 
20
from twisted.application import internet, service
 
21
from twisted.cred import checkers, portal
 
22
 
 
23
def makeService(args):
 
24
    checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(username="password")
 
25
 
 
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)
 
33
 
 
34
    def chainProtocolFactory():
 
35
        return insults.ServerProtocol(
 
36
            args['protocolFactory'],
 
37
            *args.get('protocolArgs', ()),
 
38
            **args.get('protocolKwArgs', {}))
 
39
 
 
40
    rlm = TerminalRealm()
 
41
    rlm.chainedProtocolFactory = chainProtocolFactory
 
42
    ptl = portal.Portal(rlm, [checker])
 
43
    f = ConchFactory(ptl)
 
44
    csvc = internet.TCPServer(args['ssh'], f)
 
45
 
 
46
    m = service.MultiService()
 
47
    tsvc.setServiceParent(m)
 
48
    csvc.setServiceParent(m)
 
49
    return m
 
50
 
 
51
application = service.Application("Interactive Python Interpreter")
 
52
 
 
53
makeService({'protocolFactory': ColoredManhole,
 
54
             'protocolArgs': (None,),
 
55
             'telnet': 6023,
 
56
             'ssh': 6022}).setServiceParent(application)