|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
18 | | -#$Id: back_anydbm.py,v 1.146.2.9 2004-06-13 01:11:23 richard Exp $ |
| 18 | +#$Id: back_anydbm.py,v 1.146.2.10 2004-06-21 05:42:45 richard Exp $ |
19 | 19 | '''This module defines a backend that saves the hyperdatabase in a |
20 | 20 | database chosen by anydbm. It is guaranteed to always be available in python |
21 | 21 | versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several |
@@ -1599,12 +1599,12 @@ def filter(self, search_matches, filterspec, sort=(None,None), |
1599 | 1599 | # optimise filterspec |
1600 | 1600 | l = [] |
1601 | 1601 | props = self.getprops() |
1602 | | - LINK = 0 |
1603 | | - MULTILINK = 1 |
1604 | | - STRING = 2 |
1605 | | - DATE = 3 |
1606 | | - INTERVAL = 4 |
1607 | | - OTHER = 6 |
| 1602 | + LINK = 'spec:link' |
| 1603 | + MULTILINK = 'spec:multilink' |
| 1604 | + STRING = 'spec:string' |
| 1605 | + DATE = 'spec:date' |
| 1606 | + INTERVAL = 'spec:interval' |
| 1607 | + OTHER = 'spec:other' |
1608 | 1608 |
|
1609 | 1609 | timezone = self.db.getUserTimezone() |
1610 | 1610 | for k, v in filterspec.items(): |
@@ -1689,56 +1689,58 @@ def filter(self, search_matches, filterspec, sort=(None,None), |
1689 | 1689 | # apply filter |
1690 | 1690 | for t, k, v in filterspec: |
1691 | 1691 | # handle the id prop |
1692 | | - if k == 'id' and nodeid in v: |
| 1692 | + if k == 'id': |
| 1693 | + if nodeid not in v: |
| 1694 | + break |
1693 | 1695 | continue |
1694 | 1696 |
|
1695 | | - # make sure the node has the property |
1696 | | - if not node.has_key(k): |
1697 | | - # this node doesn't have this property, so reject it |
1698 | | - break |
| 1697 | + # get the node value |
| 1698 | + nv = node.get(k, None) |
| 1699 | + |
| 1700 | + match = False |
1699 | 1701 |
|
1700 | 1702 | # now apply the property filter |
1701 | 1703 | if t == LINK: |
1702 | 1704 | # link - if this node's property doesn't appear in the |
1703 | 1705 | # filterspec's nodeid list, skip it |
1704 | | - if node[k] not in v: |
1705 | | - break |
| 1706 | + match = nv in v |
1706 | 1707 | elif t == MULTILINK: |
1707 | 1708 | # multilink - if any of the nodeids required by the |
1708 | 1709 | # filterspec aren't in this node's property, then skip |
1709 | 1710 | # it |
1710 | | - have = node[k] |
1711 | | - # check for matching the absence of multilink values |
1712 | | - if not v and have: |
1713 | | - break |
| 1711 | + nv = node.get(k, []) |
1714 | 1712 |
|
1715 | | - # othewise, make sure this node has each of the |
1716 | | - # required values |
1717 | | - for want in v: |
1718 | | - if want not in have: |
1719 | | - break |
| 1713 | + # check for matching the absence of multilink values |
| 1714 | + if not v: |
| 1715 | + match = not nv |
1720 | 1716 | else: |
1721 | | - continue |
1722 | | - break |
| 1717 | + # othewise, make sure this node has each of the |
| 1718 | + # required values |
| 1719 | + for want in v: |
| 1720 | + if want not in nv: |
| 1721 | + break |
| 1722 | + else: |
| 1723 | + match = True |
1723 | 1724 | elif t == STRING: |
1724 | | - if node[k] is None: |
1725 | | - break |
| 1725 | + if nv is None: |
| 1726 | + nv = '' |
1726 | 1727 | # RE search |
1727 | | - if not v.search(node[k]): |
1728 | | - break |
| 1728 | + match = v.search(nv) |
1729 | 1729 | elif t == DATE or t == INTERVAL: |
1730 | | - if node[k] is None: |
1731 | | - break |
1732 | | - if v.to_value: |
1733 | | - if not (v.from_value <= node[k] and v.to_value >= node[k]): |
1734 | | - break |
| 1730 | + if nv is None: |
| 1731 | + match = v is None |
1735 | 1732 | else: |
1736 | | - if not (v.from_value <= node[k]): |
1737 | | - break |
| 1733 | + if v.to_value: |
| 1734 | + if v.from_value <= nv and v.to_value >= nv: |
| 1735 | + match = True |
| 1736 | + else: |
| 1737 | + if v.from_value <= nv: |
| 1738 | + match = True |
1738 | 1739 | elif t == OTHER: |
1739 | 1740 | # straight value comparison for the other types |
1740 | | - if node[k] not in v: |
1741 | | - break |
| 1741 | + match = nv in v |
| 1742 | + if not match: |
| 1743 | + break |
1742 | 1744 | else: |
1743 | 1745 | matches.append([nodeid, node]) |
1744 | 1746 |
|
|
0 commit comments