~0x44/nova/extdoc

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/web/examples/advogato.py

  • 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
#
 
5
 
 
6
'''
 
7
Usage: 
 
8
advogato.py <name> <diary entry file>
 
9
'''
 
10
 
 
11
from twisted.web.xmlrpc import Proxy
 
12
from twisted.internet import reactor
 
13
from getpass import getpass
 
14
import sys
 
15
 
 
16
class AddDiary:
 
17
 
 
18
    def __init__(self, name, password):
 
19
        self.name = name
 
20
        self.password = password
 
21
        self.proxy = Proxy('http://advogato.org/XMLRPC')
 
22
 
 
23
    def __call__(self, filename):
 
24
        self.data = open(filename).read()
 
25
        d = self.proxy.callRemote('authenticate', self.name, self.password)
 
26
        d.addCallbacks(self.login, self.noLogin)
 
27
 
 
28
    def noLogin(self, reason):
 
29
        print "could not login"
 
30
        reactor.stop()
 
31
 
 
32
    def login(self, cookie):
 
33
        d = self.proxy.callRemote('diary.set', cookie, -1, self.data)
 
34
        d.addCallbacks(self.setDiary, self.errorSetDiary)
 
35
 
 
36
    def setDiary(self, response):
 
37
        reactor.stop()
 
38
 
 
39
    def errorSetDiary(self, error):
 
40
        print "could not set diary", error
 
41
        reactor.stop()
 
42
 
 
43
diary = AddDiary(sys.argv[1], getpass())
 
44
diary(sys.argv[2])
 
45
reactor.run()