comparison roundup/xmlrpc.py @ 3839:cf6c45201980

Varia
author Stefan Seefeld <stefan@seefeld.name>
date Tue, 03 Apr 2007 16:52:51 +0000
parents ba6ba8d6bcc1
children 9596a516d78c
comparison
equal deleted inserted replaced
3838:99bd1d59a58e 3839:cf6c45201980
1 # 1 #
2 # Copyright (C) 2007 Stefan Seefeld 2 # Copyright (C) 2007 Stefan Seefeld
3 # All rights reserved. 3 # All rights reserved.
4 # Licensed to the public under the terms of the GNU LGPL (>= 2), 4 # For license terms see the file COPYING.txt.
5 # see the file COPYING for details.
6 # 5 #
7
8 6
9 import base64 7 import base64
10 import roundup.instance 8 import roundup.instance
11 from roundup import hyperdb 9 from roundup import hyperdb
12 from roundup.cgi.exceptions import * 10 from roundup.cgi.exceptions import *
57 stored = self.db.user.get(userid, 'password') 55 stored = self.db.user.get(userid, 'password')
58 if stored != password: # Wrong password 56 if stored != password: # Wrong password
59 raise Unauthorised, 'Invalid user.' 57 raise Unauthorised, 'Invalid user.'
60 self.db.setCurrentUser(username) 58 self.db.setCurrentUser(username)
61 59
62 def __del__(self): 60 def close(self):
63 """Close the database, after committing any changes, if needed.""" 61 """Close the database, after committing any changes, if needed."""
64 62
65 if getattr(self, 'db'): 63 if getattr(self, 'db'):
66 try: 64 try:
67 if self.db.transactions: 65 if self.db.transactions:
116 114
117 r = RoundupRequest(self.tracker, username, password) 115 r = RoundupRequest(self.tracker, username, password)
118 cl = r.get_class(classname) 116 cl = r.get_class(classname)
119 if not propname: 117 if not propname:
120 propname = cl.labelprop() 118 propname = cl.labelprop()
121 return [cl.get(id, propname) for id in cl.list()] 119 result = [cl.get(id, propname) for id in cl.list()]
120 r.close()
121 return result
122 122
123 def display(self, username, password, designator, *properties): 123 def display(self, username, password, designator, *properties):
124 124
125 r = RoundupRequest(self.tracker, username, password) 125 r = RoundupRequest(self.tracker, username, password)
126 classname, nodeid = hyperdb.splitDesignator(designator) 126 classname, nodeid = hyperdb.splitDesignator(designator)
127 cl = r.get_class(classname) 127 cl = r.get_class(classname)
128 props = properties and list(properties) or cl.properties.keys() 128 props = properties and list(properties) or cl.properties.keys()
129 props.sort() 129 props.sort()
130 return dict([(property, cl.get(nodeid, property)) 130 result = [(property, cl.get(nodeid, property)) for property in props]
131 for property in props]) 131 r.close()
132 return dict(result)
132 133
133 def create(self, username, password, classname, *args): 134 def create(self, username, password, classname, *args):
134 135
135 r = RoundupRequest(self.tracker, username, password) 136 r = RoundupRequest(self.tracker, username, password)
136 cl = r.get_class(classname) 137 cl = r.get_class(classname)
143 if key and not props.has_key(key): 144 if key and not props.has_key(key):
144 raise UsageError, 'you must provide the "%s" property.'%key 145 raise UsageError, 'you must provide the "%s" property.'%key
145 146
146 # do the actual create 147 # do the actual create
147 try: 148 try:
148 return cl.create(**props) 149 result = cl.create(**props)
149 except (TypeError, IndexError, ValueError), message: 150 except (TypeError, IndexError, ValueError), message:
150 raise UsageError, message 151 raise UsageError, message
152 finally:
153 r.close()
154 return result
151 155
152 def set(self, username, password, designator, *args): 156 def set(self, username, password, designator, *args):
153 157
154 r = RoundupRequest(self.tracker, username, password) 158 r = RoundupRequest(self.tracker, username, password)
155 classname, itemid = hyperdb.splitDesignator(designator) 159 classname, itemid = hyperdb.splitDesignator(designator)
159 props = r.props_from_args(cl, args) 163 props = r.props_from_args(cl, args)
160 try: 164 try:
161 cl.set(itemid, **props) 165 cl.set(itemid, **props)
162 except (TypeError, IndexError, ValueError), message: 166 except (TypeError, IndexError, ValueError), message:
163 raise UsageError, message 167 raise UsageError, message
168 finally:
169 r.close()
164 170
165

Roundup Issue Tracker: http://roundup-tracker.org/