Skip to content

Commit 455582f

Browse files
author
Richard Jones
committed
allow list of values for id, Number and Boolean filtering in anydbm backend
1 parent c0d8946 commit 455582f

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Feature:
1515
Fixed:
1616
- force lookup of journal props in anydbm filtering
1717
- fixed lookup of "missing" Link values for new props in anydbm backend
18+
- allow list of values for id, Number and Boolean filtering in anydbm
19+
backend
1820

1921

2022
2004-06-10 0.7.4

doc/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Dan Grassi,
8989
Engelbert Gruber,
9090
Juergen Hermann,
9191
Tobias Hunger,
92+
Simon Hyde,
9293
Christophe Kalt,
9394
Brian Kelley,
9495
James Kew,

roundup/backends/back_anydbm.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
#$Id: back_anydbm.py,v 1.154 2004-06-13 00:27:45 richard Exp $
18+
#$Id: back_anydbm.py,v 1.155 2004-06-13 01:05:46 richard Exp $
1919
'''This module defines a backend that saves the hyperdatabase in a
2020
database chosen by anydbm. It is guaranteed to always be available in python
2121
versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several
@@ -1654,15 +1654,26 @@ def filter(self, search_matches, filterspec, sort=(None,None),
16541654
pass
16551655

16561656
elif isinstance(propclass, Boolean):
1657-
if type(v) is type(''):
1658-
bv = v.lower() in ('yes', 'true', 'on', '1')
1659-
else:
1660-
bv = v
1657+
if type(v) != type([]):
1658+
v = v.split(',')
1659+
bv = []
1660+
for val in v:
1661+
if type(val) is type(''):
1662+
bv.append(val.lower() in ('yes', 'true', 'on', '1'))
1663+
else:
1664+
bv.append(val)
16611665
l.append((OTHER, k, bv))
1666+
1667+
elif k == 'id':
1668+
if type(v) != type([]):
1669+
v = v.split(',')
1670+
l.append((OTHER, k, [str(int(val)) for val in v]))
1671+
16621672
elif isinstance(propclass, Number):
1663-
l.append((OTHER, k, float(v)))
1664-
else:
1665-
l.append((OTHER, k, v))
1673+
if type(v) != type([]):
1674+
v = v.split(',')
1675+
l.append((OTHER, k, [float(val) for val in v]))
1676+
16661677
filterspec = l
16671678

16681679
# now, find all the nodes that are active and pass filtering
@@ -1678,7 +1689,7 @@ def filter(self, search_matches, filterspec, sort=(None,None),
16781689
# apply filter
16791690
for t, k, v in filterspec:
16801691
# handle the id prop
1681-
if k == 'id' and v == nodeid:
1692+
if k == 'id' and nodeid in v:
16821693
continue
16831694

16841695
# make sure the node has the property
@@ -1726,7 +1737,7 @@ def filter(self, search_matches, filterspec, sort=(None,None),
17261737
break
17271738
elif t == OTHER:
17281739
# straight value comparison for the other types
1729-
if node[k] != v:
1740+
if node[k] not in v:
17301741
break
17311742
else:
17321743
matches.append([nodeid, node])

test/db_test_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: db_test_base.py,v 1.30 2004-06-09 06:35:45 richard Exp $
18+
# $Id: db_test_base.py,v 1.31 2004-06-13 01:05:46 richard Exp $
1919

2020
import unittest, os, shutil, errno, imp, sys, time, pprint
2121

@@ -846,6 +846,7 @@ def testFilteringNumber(self):
846846
ae(filt(None, {'age': '1'}, ('+','id'), (None,None)), ['3'])
847847
ae(filt(None, {'age': '1.5'}, ('+','id'), (None,None)), ['4'])
848848
ae(filt(None, {'age': '2'}, ('+','id'), (None,None)), ['5'])
849+
ae(filt(None, {'age': ['1','2']}, ('+','id'), (None,None)), ['3','5'])
849850

850851
def testFilteringString(self):
851852
ae, filt = self.filteringSetup()

0 commit comments

Comments
 (0)