~divmod-dev/divmod.org/compressed-resources-2747

« back to all changes in this revision

Viewing changes to Imaginary/pottery/wiring/telnet.py

  • Committer: exarkun
  • Date: 2006-02-26 02:37:39 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:4991
Merge move-pottery-to-trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from twisted.internet import protocol
 
3
from twisted.cred import credentials, portal
 
4
from twisted.application import internet
 
5
from twisted.protocols import policies
 
6
 
 
7
from twisted.conch import telnet
 
8
from twisted.conch.insults import insults
 
9
 
 
10
from pottery import ipottery
 
11
from pottery.wiring import textserver
 
12
 
 
13
class PotteryTelnetFactory(protocol.ServerFactory):
 
14
    def __init__(self, realm, portal, applicationProtocolFactory):
 
15
        self.realm = realm
 
16
        self.portal = portal
 
17
        self.applicationProtocolFactory = applicationProtocolFactory
 
18
 
 
19
    def protocol(self):
 
20
        return telnet.TelnetTransport(
 
21
            telnet.TelnetBootstrapProtocol,
 
22
            insults.ServerProtocol,
 
23
            self.applicationProtocolFactory)
 
24
 
 
25
    def login(self, username, password):
 
26
        return self.portal.login(
 
27
            credentials.UsernamePassword(username, password),
 
28
            None,
 
29
            ipottery.IPlayer)
 
30
 
 
31
    def create(self, username, password):
 
32
        return self.realm.create(username, password)
 
33
 
 
34
def makeService(realm, port, applicationProtocolFactory=textserver.TextServer, debug=True):
 
35
    p = portal.Portal(realm)
 
36
    p.registerChecker(realm)
 
37
 
 
38
    factory = PotteryTelnetFactory(realm, p, applicationProtocolFactory)
 
39
 
 
40
    if debug:
 
41
        factory = policies.TrafficLoggingFactory(factory, 'telnet')
 
42
 
 
43
    netsvc = internet.TCPServer(port, factory)
 
44
 
 
45
    return netsvc