Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 3925:603ec9630b08
i18n for hyperdb and backend errors
I got all of the hyperdb exceptions. There were some ValueErrors
in some of the backends that I left untouched.
I wasn't sure how to regenerate the roundup.pot file so
that still needs to be done
I think this takes care of [SF#1069258]
| author | Justus Pendleton <jpend@users.sourceforge.net> |
|---|---|
| date | Thu, 27 Sep 2007 06:18:53 +0000 |
| parents | 21d3d7eeea8c |
| children | fe2af84a5ca5 |
comparison
equal
deleted
inserted
replaced
| 3924:21d3d7eeea8c | 3925:603ec9630b08 |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: hyperdb.py,v 1.130 2007-09-27 06:12:56 jpend Exp $ | 18 # $Id: hyperdb.py,v 1.131 2007-09-27 06:18:53 jpend Exp $ |
| 19 | 19 |
| 20 """Hyperdatabase implementation, especially field types. | 20 """Hyperdatabase implementation, especially field types. |
| 21 """ | 21 """ |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 24 # standard python modules | 24 # standard python modules |
| 25 import sys, os, time, re, shutil, weakref | 25 import os, re, shutil, weakref |
| 26 from sets import Set | 26 from sets import Set |
| 27 | 27 |
| 28 # roundup modules | 28 # roundup modules |
| 29 import date, password | 29 import date, password |
| 30 from support import ensureParentsExist, PrioList, sorted, reversed | 30 from support import ensureParentsExist, PrioList, sorted, reversed |
| 31 from roundup.i18n import _ | |
| 31 | 32 |
| 32 # | 33 # |
| 33 # Types | 34 # Types |
| 34 # | 35 # |
| 35 class _Type(object): | 36 class _Type(object): |
| 71 if m: | 72 if m: |
| 72 # password is being given to us encrypted | 73 # password is being given to us encrypted |
| 73 p = password.Password() | 74 p = password.Password() |
| 74 p.scheme = m.group(1) | 75 p.scheme = m.group(1) |
| 75 if p.scheme not in 'SHA crypt plaintext'.split(): | 76 if p.scheme not in 'SHA crypt plaintext'.split(): |
| 76 raise HyperdbValueError, 'property %s: unknown encryption '\ | 77 raise HyperdbValueError, \ |
| 77 'scheme %r'%(kw['propname'], p.scheme) | 78 ('property %s: unknown encryption scheme %r') %\ |
| 79 (kw['propname'], p.scheme) | |
| 78 p.password = m.group(2) | 80 p.password = m.group(2) |
| 79 value = p | 81 value = p |
| 80 else: | 82 else: |
| 81 try: | 83 try: |
| 82 value = password.Password(value) | 84 value = password.Password(value) |
| 83 except password.PasswordValueError, message: | 85 except password.PasswordValueError, message: |
| 84 raise HyperdbValueError, 'property %s: %s'%(kw['propname'], message) | 86 raise HyperdbValueError, \ |
| 87 _('property %s: %s')%(kw['propname'], message) | |
| 85 return value | 88 return value |
| 86 def sort_repr (self, cls, val, name): | 89 def sort_repr (self, cls, val, name): |
| 87 if not val: | 90 if not val: |
| 88 return val | 91 return val |
| 89 return str(val) | 92 return str(val) |
| 99 return db.getUserTimezone() | 102 return db.getUserTimezone() |
| 100 def from_raw(self, value, db, **kw): | 103 def from_raw(self, value, db, **kw): |
| 101 try: | 104 try: |
| 102 value = date.Date(value, self.offset(db)) | 105 value = date.Date(value, self.offset(db)) |
| 103 except ValueError, message: | 106 except ValueError, message: |
| 104 raise HyperdbValueError, 'property %s: %r is an invalid '\ | 107 raise HyperdbValueError, _('property %s: %r is an invalid '\ |
| 105 'date (%s)'%(kw['propname'], value, message) | 108 'date (%s)')%(kw['propname'], value, message) |
| 106 return value | 109 return value |
| 107 def range_from_raw(self, value, db): | 110 def range_from_raw(self, value, db): |
| 108 """return Range value from given raw value with offset correction""" | 111 """return Range value from given raw value with offset correction""" |
| 109 return date.Range(value, date.Date, offset=self.offset(db)) | 112 return date.Range(value, date.Date, offset=self.offset(db)) |
| 110 def sort_repr (self, cls, val, name): | 113 def sort_repr (self, cls, val, name): |
| 116 """An object designating an Interval property.""" | 119 """An object designating an Interval property.""" |
| 117 def from_raw(self, value, **kw): | 120 def from_raw(self, value, **kw): |
| 118 try: | 121 try: |
| 119 value = date.Interval(value) | 122 value = date.Interval(value) |
| 120 except ValueError, message: | 123 except ValueError, message: |
| 121 raise HyperdbValueError, 'property %s: %r is an invalid '\ | 124 raise HyperdbValueError, _('property %s: %r is an invalid '\ |
| 122 'date interval (%s)'%(kw['propname'], value, message) | 125 'date interval (%s)')%(kw['propname'], value, message) |
| 123 return value | 126 return value |
| 124 def sort_repr (self, cls, val, name): | 127 def sort_repr (self, cls, val, name): |
| 125 if not val: | 128 if not val: |
| 126 return val | 129 return val |
| 127 return val.as_seconds() | 130 return val.as_seconds() |
| 211 # perform the add/remove | 214 # perform the add/remove |
| 212 if remove: | 215 if remove: |
| 213 try: | 216 try: |
| 214 curvalue.remove(itemid) | 217 curvalue.remove(itemid) |
| 215 except ValueError: | 218 except ValueError: |
| 216 raise HyperdbValueError, 'property %s: %r is not ' \ | 219 raise HyperdbValueError, _('property %s: %r is not ' \ |
| 217 'currently an element'%(propname, item) | 220 'currently an element')%(propname, item) |
| 218 else: | 221 else: |
| 219 newvalue.append(itemid) | 222 newvalue.append(itemid) |
| 220 if itemid not in curvalue: | 223 if itemid not in curvalue: |
| 221 curvalue.append(itemid) | 224 curvalue.append(itemid) |
| 222 | 225 |
| 255 def from_raw(self, value, **kw): | 258 def from_raw(self, value, **kw): |
| 256 value = value.strip() | 259 value = value.strip() |
| 257 try: | 260 try: |
| 258 value = float(value) | 261 value = float(value) |
| 259 except ValueError: | 262 except ValueError: |
| 260 raise HyperdbValueError, 'property %s: %r is not a number'%( | 263 raise HyperdbValueError, _('property %s: %r is not a number')%( |
| 261 kw['propname'], value) | 264 kw['propname'], value) |
| 262 return value | 265 return value |
| 263 # | 266 # |
| 264 # Support for splitting designators | 267 # Support for splitting designators |
| 265 # | 268 # |
| 268 def splitDesignator(designator, dre=re.compile(r'([^\d]+)(\d+)')): | 271 def splitDesignator(designator, dre=re.compile(r'([^\d]+)(\d+)')): |
| 269 ''' Take a foo123 and return ('foo', 123) | 272 ''' Take a foo123 and return ('foo', 123) |
| 270 ''' | 273 ''' |
| 271 m = dre.match(designator) | 274 m = dre.match(designator) |
| 272 if m is None: | 275 if m is None: |
| 273 raise DesignatorError, '"%s" not a node designator'%designator | 276 raise DesignatorError, _('"%s" not a node designator')%designator |
| 274 return m.group(1), m.group(2) | 277 return m.group(1), m.group(2) |
| 275 | 278 |
| 276 class Proptree(object): | 279 class Proptree(object): |
| 277 ''' Simple tree data structure for optimizing searching of | 280 ''' Simple tree data structure for optimizing searching of |
| 278 properties. Each node in the tree represents a roundup Class | 281 properties. Each node in the tree represents a roundup Class |
| 941 def setlabelprop(self, labelprop): | 944 def setlabelprop(self, labelprop): |
| 942 """Set the label property. Used for override of labelprop | 945 """Set the label property. Used for override of labelprop |
| 943 resolution order. | 946 resolution order. |
| 944 """ | 947 """ |
| 945 if labelprop not in self.getprops(): | 948 if labelprop not in self.getprops(): |
| 946 raise ValueError, "Not a property name: %s" % labelprop | 949 raise ValueError, _("Not a property name: %s") % labelprop |
| 947 self._labelprop = labelprop | 950 self._labelprop = labelprop |
| 948 | 951 |
| 949 def setorderprop(self, orderprop): | 952 def setorderprop(self, orderprop): |
| 950 """Set the order property. Used for override of orderprop | 953 """Set the order property. Used for override of orderprop |
| 951 resolution order | 954 resolution order |
| 952 """ | 955 """ |
| 953 if orderprop not in self.getprops(): | 956 if orderprop not in self.getprops(): |
| 954 raise ValueError, "Not a property name: %s" % orderprop | 957 raise ValueError, _("Not a property name: %s") % orderprop |
| 955 self._orderprop = orderprop | 958 self._orderprop = orderprop |
| 956 | 959 |
| 957 def getkey(self): | 960 def getkey(self): |
| 958 """Return the name of the key property for this class or None.""" | 961 """Return the name of the key property for this class or None.""" |
| 959 raise NotImplementedError | 962 raise NotImplementedError |
| 1232 if not idre.match(value): | 1235 if not idre.match(value): |
| 1233 if linkcl.getkey(): | 1236 if linkcl.getkey(): |
| 1234 try: | 1237 try: |
| 1235 value = linkcl.lookup(value) | 1238 value = linkcl.lookup(value) |
| 1236 except KeyError, message: | 1239 except KeyError, message: |
| 1237 raise HyperdbValueError, 'property %s: %r is not a %s.'%( | 1240 raise HyperdbValueError, _('property %s: %r is not a %s.')%( |
| 1238 propname, value, prop.classname) | 1241 propname, value, prop.classname) |
| 1239 else: | 1242 else: |
| 1240 raise HyperdbValueError, 'you may only enter ID values '\ | 1243 raise HyperdbValueError, _('you may only enter ID values '\ |
| 1241 'for property %s'%propname | 1244 'for property %s')%propname |
| 1242 return value | 1245 return value |
| 1243 | 1246 |
| 1244 def fixNewlines(text): | 1247 def fixNewlines(text): |
| 1245 """ Homogenise line endings. | 1248 """ Homogenise line endings. |
| 1246 | 1249 |
| 1265 # ensure it's a valid property name | 1268 # ensure it's a valid property name |
| 1266 propname = propname.strip() | 1269 propname = propname.strip() |
| 1267 try: | 1270 try: |
| 1268 proptype = properties[propname] | 1271 proptype = properties[propname] |
| 1269 except KeyError: | 1272 except KeyError: |
| 1270 raise HyperdbValueError, '%r is not a property of %s'%(propname, | 1273 raise HyperdbValueError, _('%r is not a property of %s')%(propname, |
| 1271 klass.classname) | 1274 klass.classname) |
| 1272 | 1275 |
| 1273 # if we got a string, strip it now | 1276 # if we got a string, strip it now |
| 1274 if isinstance(value, type('')): | 1277 if isinstance(value, type('')): |
| 1275 value = value.strip() | 1278 value = value.strip() |
