Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 457:6abdddc506e9
Cleaned up some bare except statements
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 15 Dec 2001 23:47:47 +0000 |
| parents | 7181efddce66 |
| children | 9c895b44240a |
comparison
equal
deleted
inserted
replaced
| 456:5f3c5c3fd524 | 457:6abdddc506e9 |
|---|---|
| 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.40 2001-12-14 23:42:57 richard Exp $ | 18 # $Id: hyperdb.py,v 1.41 2001-12-15 23:47:47 richard Exp $ |
| 19 | 19 |
| 20 __doc__ = """ | 20 __doc__ = """ |
| 21 Hyperdatabase implementation, especially field types. | 21 Hyperdatabase implementation, especially field types. |
| 22 """ | 22 """ |
| 23 | 23 |
| 157 link_class = self.properties[key].classname | 157 link_class = self.properties[key].classname |
| 158 # if it isn't a number, it's a key | 158 # if it isn't a number, it's a key |
| 159 if not num_re.match(value): | 159 if not num_re.match(value): |
| 160 try: | 160 try: |
| 161 value = self.db.classes[link_class].lookup(value) | 161 value = self.db.classes[link_class].lookup(value) |
| 162 except: | 162 except (TypeError, KeyError): |
| 163 raise IndexError, 'new property "%s": %s not a %s'%( | 163 raise IndexError, 'new property "%s": %s not a %s'%( |
| 164 key, value, link_class) | 164 key, value, link_class) |
| 165 elif not self.db.hasnode(link_class, value): | 165 elif not self.db.hasnode(link_class, value): |
| 166 raise IndexError, '%s has no node %s'%(link_class, value) | 166 raise IndexError, '%s has no node %s'%(link_class, value) |
| 167 | 167 |
| 182 raise ValueError, 'link value must be String' | 182 raise ValueError, 'link value must be String' |
| 183 # if it isn't a number, it's a key | 183 # if it isn't a number, it's a key |
| 184 if not num_re.match(entry): | 184 if not num_re.match(entry): |
| 185 try: | 185 try: |
| 186 entry = self.db.classes[link_class].lookup(entry) | 186 entry = self.db.classes[link_class].lookup(entry) |
| 187 except: | 187 except (TypeError, KeyError): |
| 188 raise IndexError, 'new property "%s": %s not a %s'%( | 188 raise IndexError, 'new property "%s": %s not a %s'%( |
| 189 key, entry, self.properties[key].classname) | 189 key, entry, self.properties[key].classname) |
| 190 l.append(entry) | 190 l.append(entry) |
| 191 value = l | 191 value = l |
| 192 propvalues[key] = value | 192 propvalues[key] = value |
| 328 if type(value) != type(''): | 328 if type(value) != type(''): |
| 329 raise ValueError, 'link value must be String' | 329 raise ValueError, 'link value must be String' |
| 330 if not num_re.match(value): | 330 if not num_re.match(value): |
| 331 try: | 331 try: |
| 332 value = self.db.classes[link_class].lookup(value) | 332 value = self.db.classes[link_class].lookup(value) |
| 333 except: | 333 except (TypeError, KeyError): |
| 334 raise IndexError, 'new property "%s": %s not a %s'%( | 334 raise IndexError, 'new property "%s": %s not a %s'%( |
| 335 key, value, self.properties[key].classname) | 335 key, value, self.properties[key].classname) |
| 336 | 336 |
| 337 if not self.db.hasnode(link_class, value): | 337 if not self.db.hasnode(link_class, value): |
| 338 raise IndexError, '%s has no node %s'%(link_class, value) | 338 raise IndexError, '%s has no node %s'%(link_class, value) |
| 357 if type(entry) != type(''): | 357 if type(entry) != type(''): |
| 358 raise ValueError, 'link value must be String' | 358 raise ValueError, 'link value must be String' |
| 359 if not num_re.match(entry): | 359 if not num_re.match(entry): |
| 360 try: | 360 try: |
| 361 entry = self.db.classes[link_class].lookup(entry) | 361 entry = self.db.classes[link_class].lookup(entry) |
| 362 except: | 362 except (TypeError, KeyError): |
| 363 raise IndexError, 'new property "%s": %s not a %s'%( | 363 raise IndexError, 'new property "%s": %s not a %s'%( |
| 364 key, entry, self.properties[key].classname) | 364 key, entry, self.properties[key].classname) |
| 365 l.append(entry) | 365 l.append(entry) |
| 366 value = l | 366 value = l |
| 367 propvalues[key] = value | 367 propvalues[key] = value |
| 597 for entry in v: | 597 for entry in v: |
| 598 if entry == '-1': entry = None | 598 if entry == '-1': entry = None |
| 599 elif not num_re.match(entry): | 599 elif not num_re.match(entry): |
| 600 try: | 600 try: |
| 601 entry = link_class.lookup(entry) | 601 entry = link_class.lookup(entry) |
| 602 except: | 602 except (TypeError,KeyError): |
| 603 raise ValueError, 'property "%s": %s not a %s'%( | 603 raise ValueError, 'property "%s": %s not a %s'%( |
| 604 k, entry, self.properties[k].classname) | 604 k, entry, self.properties[k].classname) |
| 605 u.append(entry) | 605 u.append(entry) |
| 606 | 606 |
| 607 l.append((0, k, u)) | 607 l.append((0, k, u)) |
| 613 link_class = self.db.classes[propclass.classname] | 613 link_class = self.db.classes[propclass.classname] |
| 614 for entry in v: | 614 for entry in v: |
| 615 if not num_re.match(entry): | 615 if not num_re.match(entry): |
| 616 try: | 616 try: |
| 617 entry = link_class.lookup(entry) | 617 entry = link_class.lookup(entry) |
| 618 except: | 618 except (TypeError,KeyError): |
| 619 raise ValueError, 'new property "%s": %s not a %s'%( | 619 raise ValueError, 'new property "%s": %s not a %s'%( |
| 620 k, entry, self.properties[k].classname) | 620 k, entry, self.properties[k].classname) |
| 621 u.append(entry) | 621 u.append(entry) |
| 622 l.append((1, k, u)) | 622 l.append((1, k, u)) |
| 623 elif isinstance(propclass, String): | 623 elif isinstance(propclass, String): |
| 721 if bv and bv[0] in string.uppercase: | 721 if bv and bv[0] in string.uppercase: |
| 722 bv = bn[prop] = bv.lower() | 722 bv = bn[prop] = bv.lower() |
| 723 if (isinstance(propclass, String) or | 723 if (isinstance(propclass, String) or |
| 724 isinstance(propclass, Date)): | 724 isinstance(propclass, Date)): |
| 725 # it might be a string that's really an integer | 725 # it might be a string that's really an integer |
| 726 try: | 726 av = int(av) |
| 727 av = int(av) | 727 bv = int(bv) |
| 728 bv = int(bv) | |
| 729 except: | |
| 730 pass | |
| 731 if dir == '+': | 728 if dir == '+': |
| 732 r = cmp(av, bv) | 729 r = cmp(av, bv) |
| 733 if r != 0: return r | 730 if r != 0: return r |
| 734 elif dir == '-': | 731 elif dir == '-': |
| 735 r = cmp(bv, av) | 732 r = cmp(bv, av) |
| 869 cl.create(name=option[i], order=i) | 866 cl.create(name=option[i], order=i) |
| 870 return hyperdb.Link(name) | 867 return hyperdb.Link(name) |
| 871 | 868 |
| 872 # | 869 # |
| 873 # $Log: not supported by cvs2svn $ | 870 # $Log: not supported by cvs2svn $ |
| 871 # Revision 1.40 2001/12/14 23:42:57 richard | |
| 872 # yuck, a gdbm instance tests false :( | |
| 873 # I've left the debugging code in - it should be removed one day if we're ever | |
| 874 # _really_ anal about performace :) | |
| 875 # | |
| 874 # Revision 1.39 2001/12/02 05:06:16 richard | 876 # Revision 1.39 2001/12/02 05:06:16 richard |
| 875 # . We now use weakrefs in the Classes to keep the database reference, so | 877 # . We now use weakrefs in the Classes to keep the database reference, so |
| 876 # the close() method on the database is no longer needed. | 878 # the close() method on the database is no longer needed. |
| 877 # I bumped the minimum python requirement up to 2.1 accordingly. | 879 # I bumped the minimum python requirement up to 2.1 accordingly. |
| 878 # . #487480 ] roundup-server | 880 # . #487480 ] roundup-server |
