summaryrefslogtreecommitdiff
path: root/doc/core/howto/listings/amp/command_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/core/howto/listings/amp/command_client.py')
-rw-r--r--doc/core/howto/listings/amp/command_client.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/doc/core/howto/listings/amp/command_client.py b/doc/core/howto/listings/amp/command_client.py
new file mode 100644
index 0000000..8aa4cbd
--- /dev/null
+++ b/doc/core/howto/listings/amp/command_client.py
@@ -0,0 +1,48 @@
+
+if __name__ == '__main__':
+ import command_client
+ raise SystemExit(command_client.main())
+
+from sys import stdout
+
+from twisted.python.log import startLogging, err
+from twisted.protocols.amp import Integer, String, Unicode, Command
+from twisted.internet import reactor
+
+from basic_client import connect
+
+class UsernameUnavailable(Exception):
+ pass
+
+
+class RegisterUser(Command):
+ arguments = [('username', Unicode()),
+ ('publickey', String())]
+
+ response = [('uid', Integer())]
+
+ errors = {UsernameUnavailable: 'username-unavailable'}
+
+
+def main():
+ startLogging(stdout)
+
+ d = connect()
+ def connected(protocol):
+ return protocol.callRemote(
+ RegisterUser,
+ username=u'alice',
+ publickey='ssh-rsa AAAAB3NzaC1yc2 alice@actinium')
+ d.addCallback(connected)
+
+ def registered(result):
+ print 'Registration result:', result
+ d.addCallback(registered)
+
+ d.addErrback(err, "Failed to register")
+
+ def finished(ignored):
+ reactor.stop()
+ d.addCallback(finished)
+
+ reactor.run()