~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Epsilon/doc/listings/amp/amp_auth_client.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2008 Divmod.  See LICENSE for details.
2
 
 
3
 
"""
4
 
An AMP client which connects to and authenticates with an AMP server using OTP,
5
 
then issues a command.
6
 
"""
7
 
 
8
 
from twisted.internet.protocol import ClientCreator
9
 
from twisted.cred.credentials import UsernamePassword
10
 
from twisted.protocols.amp import AMP
11
 
 
12
 
from epsilon.react import react
13
 
from epsilon.ampauth import OTPLogin
14
 
 
15
 
from auth_server import Add
16
 
 
17
 
 
18
 
def add(proto):
19
 
    return proto.callRemote(Add, left=17, right=33)
20
 
 
21
 
 
22
 
def display(result):
23
 
    print result
24
 
 
25
 
 
26
 
def otpLogin(client):
27
 
    client.callRemote(OTPLogin, pad='pad')
28
 
    return client
29
 
 
30
 
 
31
 
def main(reactor):
32
 
    cc = ClientCreator(reactor, AMP)
33
 
    d = cc.connectTCP('localhost', 7805)
34
 
    d.addCallback(otpLogin)
35
 
    d.addCallback(add)
36
 
    d.addCallback(display)
37
 
    return d
38
 
 
39
 
 
40
 
if __name__ == '__main__':
41
 
    from twisted.internet import reactor
42
 
    react(reactor, main, [])