comparison bindings/python/pyadb.py @ 632:41ef9e165c38

removed the raised warning as its behavior doesn't actually seem appropriate. switched the default value of strictConfig so data doesn't accidentally get deleted.
author map01bf
date Wed, 23 Sep 2009 17:54:37 +0000
parents 6ec50185b348
children c014e4d5b45d
comparison
equal deleted inserted replaced
631:6ec50185b348 632:41ef9e165c38
21 ADB_HEADER_FLAG_TIMES = 0x20#as they aren't even exported to the 21 ADB_HEADER_FLAG_TIMES = 0x20#as they aren't even exported to the
22 ADB_HEADER_FLAG_REFERENCES = 0x40#api, so this is the only way to get them. 22 ADB_HEADER_FLAG_REFERENCES = 0x40#api, so this is the only way to get them.
23 23
24 class Usage(Exception): 24 class Usage(Exception):
25 """error to indicate that a method has been called with incorrect args""" 25 """error to indicate that a method has been called with incorrect args"""
26 def __init__(self, msg):
27 self.msg = msg
28 class ConfigWarning(Warning):
29 def __init__(self, msg): 26 def __init__(self, msg):
30 self.msg = msg 27 self.msg = msg
31 28
32 class Pyadb(object): 29 class Pyadb(object):
33 """Pyadb class. Allows for creation, access, insertion and query of an audioDB vector matching database.""" 30 """Pyadb class. Allows for creation, access, insertion and query of an audioDB vector matching database."""
104 hopSize : int hopsize (1 by default)])->resultDict\n\ 101 hopSize : int hopsize (1 by default)])->resultDict\n\
105 resFmt : [\"list\"|\"dict\"](\"dict\" by default)}""" 102 resFmt : [\"list\"|\"dict\"](\"dict\" by default)}"""
106 for key in self.configQuery.keys(): 103 for key in self.configQuery.keys():
107 if key not in Pyadb.validConfigTerms.keys(): 104 if key not in Pyadb.validConfigTerms.keys():
108 if not scrub: return False 105 if not scrub: return False
106 print "scrubbing %s from query config."%str(key)
109 del self.configQuery[key] 107 del self.configQuery[key]
110 if not isinstance(self.configQuery[key], Pyadb.validConfigTerms[key]): 108 if not isinstance(self.configQuery[key], Pyadb.validConfigTerms[key]):
111 if not scrub: return False 109 if not scrub: return False
112 self.configQuery[key] = Pyadb.validConfigTerms[key](self.configQuery[key])#hrm, syntax? 110 self.configQuery[key] = Pyadb.validConfigTerms[key](self.configQuery[key])#hrm, syntax?
113 return True 111 return True
114 112
115 # 113 #
116 114
117 def query(self, key=None, featData=None, strictConfig=False): 115 def query(self, key=None, featData=None, strictConfig=True):
118 """query the database. Query parameters as defined in self.configQuery. For details on this consult the doc string in the configCheck method.""" 116 """query the database. Query parameters as defined in self.configQuery. For details on this consult the doc string in the configCheck method."""
119 if not self.configCheck(): 117 if not self.configCheck():
120 if strictConfig: 118 if strictConfig:
121 raise ValueError("configQuery dict contains unsupported terms and strict configure mode is on.\n\ 119 raise ValueError("configQuery dict contains unsupported terms and strict configure mode is on.\n\
122 Only keys found in Pyadb.validConfigTerms may be defined") 120 Only keys found in Pyadb.validConfigTerms may be defined")
123 else: 121 else:
124 raise ConfigWarning("configQuery dict contains unsupported terms and strict configure mode is off.\n\ 122 print "configQuery dict contains unsupported terms and strict configure mode is off.\n\
125 Only keys found in Pyadb.validConfigTerms should be defined. Removing invalid terms and proceeding...") 123 Only keys found in Pyadb.validConfigTerms should be defined. Removing invalid terms and proceeding..."
126 self.configCheck(scrub=True) 124 self.configCheck(scrub=True)
127 if ((not key and not featData) or (key and featData)): 125 if ((not key and not featData) or (key and featData)):
128 raise Usage("query require either key or featData to be defined, you have defined both or neither.") 126 raise Usage("query require either key or featData to be defined, you have defined both or neither.")
129 if key: 127 if key:
130 result = _pyadb._pyadb_queryFromKey(self._db, key, **self.configQuery) 128 result = _pyadb._pyadb_queryFromKey(self._db, key, **self.configQuery)