11#
22# Copyright (C) 2007 Stefan Seefeld
33# All rights reserved.
4- # Licensed to the public under the terms of the GNU LGPL (>= 2),
5- # see the file COPYING for details.
4+ # For license terms see the file COPYING.txt.
65#
76
8-
97import base64
108import roundup .instance
119from roundup import hyperdb
@@ -59,7 +57,7 @@ def __init__(self, tracker, username, password):
5957 raise Unauthorised , 'Invalid user.'
6058 self .db .setCurrentUser (username )
6159
62- def __del__ (self ):
60+ def close (self ):
6361 """Close the database, after committing any changes, if needed."""
6462
6563 if getattr (self , 'db' ):
@@ -118,7 +116,9 @@ def list(self, username, password, classname, propname = None):
118116 cl = r .get_class (classname )
119117 if not propname :
120118 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
122122
123123 def display (self , username , password , designator , * properties ):
124124
@@ -127,8 +127,9 @@ def display(self, username, password, designator, *properties):
127127 cl = r .get_class (classname )
128128 props = properties and list (properties ) or cl .properties .keys ()
129129 props .sort ()
130- return dict ([(property , cl .get (nodeid , property ))
131- for property in props ])
130+ result = [(property , cl .get (nodeid , property )) for property in props ]
131+ r .close ()
132+ return dict (result )
132133
133134 def create (self , username , password , classname , * args ):
134135
@@ -145,9 +146,12 @@ def create(self, username, password, classname, *args):
145146
146147 # do the actual create
147148 try :
148- return cl .create (** props )
149+ result = cl .create (** props )
149150 except (TypeError , IndexError , ValueError ), message :
150151 raise UsageError , message
152+ finally :
153+ r .close ()
154+ return result
151155
152156 def set (self , username , password , designator , * args ):
153157
@@ -161,5 +165,6 @@ def set(self, username, password, designator, *args):
161165 cl .set (itemid , ** props )
162166 except (TypeError , IndexError , ValueError ), message :
163167 raise UsageError , message
164-
168+ finally :
169+ r .close ()
165170
0 commit comments