comparison roundup/hyperdb.py @ 4089:eddb82d0964c

Add compatibility package to allow us to deal with Python versions 2.3..2.6. Outstanding issues noted in roundup/anypy/TODO.txt
author Richard Jones <richard@users.sourceforge.net>
date Thu, 12 Mar 2009 02:52:56 +0000
parents 625915ce35b8
children 4498f5252f8b 966592263fb8
comparison
equal deleted inserted replaced
4088:34434785f308 4089:eddb82d0964c
20 """ 20 """
21 __docformat__ = 'restructuredtext' 21 __docformat__ = 'restructuredtext'
22 22
23 # standard python modules 23 # standard python modules
24 import os, re, shutil, weakref 24 import os, re, shutil, weakref
25 from sets import Set 25 # Python 2.3 ... 2.6 compatibility:
26 from roundup.anypy.sets_ import set
26 27
27 # roundup modules 28 # roundup modules
28 import date, password 29 import date, password
29 from support import ensureParentsExist, PrioList, sorted, reversed 30 from support import ensureParentsExist, PrioList, sorted, reversed
30 from roundup.i18n import _ 31 from roundup.i18n import _
191 # handle each add/remove in turn 192 # handle each add/remove in turn
192 # keep an extra list for all items that are 193 # keep an extra list for all items that are
193 # definitely in the new list (in case of e.g. 194 # definitely in the new list (in case of e.g.
194 # <propname>=A,+B, which should replace the old 195 # <propname>=A,+B, which should replace the old
195 # list with A,B) 196 # list with A,B)
196 set = 1 197 do_set = 1
197 newvalue = [] 198 newvalue = []
198 for item in value: 199 for item in value:
199 item = item.strip() 200 item = item.strip()
200 201
201 # skip blanks 202 # skip blanks
204 # handle +/- 205 # handle +/-
205 remove = 0 206 remove = 0
206 if item.startswith('-'): 207 if item.startswith('-'):
207 remove = 1 208 remove = 1
208 item = item[1:] 209 item = item[1:]
209 set = 0 210 do_set = 0
210 elif item.startswith('+'): 211 elif item.startswith('+'):
211 item = item[1:] 212 item = item[1:]
212 set = 0 213 do_set = 0
213 214
214 # look up the value 215 # look up the value
215 itemid = convertLinkValue(db, propname, self, item) 216 itemid = convertLinkValue(db, propname, self, item)
216 217
217 # perform the add/remove 218 # perform the add/remove
226 if itemid not in curvalue: 227 if itemid not in curvalue:
227 curvalue.append(itemid) 228 curvalue.append(itemid)
228 229
229 # that's it, set the new Multilink property value, 230 # that's it, set the new Multilink property value,
230 # or overwrite it completely 231 # or overwrite it completely
231 if set: 232 if do_set:
232 value = newvalue 233 value = newvalue
233 else: 234 else:
234 value = curvalue 235 value = curvalue
235 236
236 # TODO: one day, we'll switch to numeric ids and this will be 237 # TODO: one day, we'll switch to numeric ids and this will be
485 """ 486 """
486 if self.has_values: 487 if self.has_values:
487 v = self._val 488 v = self._val
488 if not isinstance(self._val, type([])): 489 if not isinstance(self._val, type([])):
489 v = [self._val] 490 v = [self._val]
490 vals = Set(v) 491 vals = set(v)
491 vals.intersection_update(val) 492 vals.intersection_update(val)
492 self._val = [v for v in vals] 493 self._val = [v for v in vals]
493 else: 494 else:
494 self._val = val 495 self._val = val
495 self.has_values = True 496 self.has_values = True

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