def parse_command_query(query): params = dict(urlparse.parse_qsl(query)) ret = {} expire = params.get('expire') if expire: interval = timeutil.parse_interval(expire) if interval is None: raise ValueError('Incorrect expire parameter value') ret['expire'] = str(interval) wait = params.get('wait') if wait: wait = wait.lower() if wait == 'true': ret['wait'] = wait else: raise ValueError('Incorrect wait parameter value') modify = params.get('modify') if modify: modify = modify.lower() if modify in ['insert', 'delete']: ret['modify'] = modify else: raise ValueError('Incorrect modify parameter value') return ret
def default_expire(self): """return parsed default.expire in seconds as string """ exp = self._get('default.expire') if not exp: raise self.config_error("default.expire missing") interval = timeutil.parse_interval(exp) if interval is None: raise self.config_error("default.expire missing or incorrect format") else: return str(interval)
def default_expire(self): """return parsed default.expire in seconds as string """ exp = self._get('default.expire') if not exp: raise self.config_error("default.expire missing") interval = timeutil.parse_interval(exp) if interval is None: raise self.config_error( "default.expire missing or incorrect format") else: return str(interval)
def test_parse_interval(self): self.assertEqual( timeutil.parse_interval('350'), 350 ) self.assertEqual( timeutil.parse_interval('20000s'), 20000 ) self.assertEqual( timeutil.parse_interval('10m'), 600 ) self.assertEqual( timeutil.parse_interval('2h'), 7200 ) self.assertEqual( timeutil.parse_interval('10d'), 864000 ) self.assertEqual( timeutil.parse_interval('0'), 0 ) self.assertEqual( timeutil.parse_interval('0m'), 0 ) self.assertEqual( timeutil.parse_interval('-3'), None ) self.assertEqual( timeutil.parse_interval('10u'), None ) self.assertEqual( timeutil.parse_interval('abc'), None ) self.assertEqual( timeutil.parse_interval(''), None )
def test_parse_interval(self): self.assertEqual(timeutil.parse_interval('350'), 350) self.assertEqual(timeutil.parse_interval('20000s'), 20000) self.assertEqual(timeutil.parse_interval('10m'), 600) self.assertEqual(timeutil.parse_interval('2h'), 7200) self.assertEqual(timeutil.parse_interval('10d'), 864000) self.assertEqual(timeutil.parse_interval('0'), 0) self.assertEqual(timeutil.parse_interval('0m'), 0) self.assertEqual(timeutil.parse_interval('-3'), None) self.assertEqual(timeutil.parse_interval('10u'), None) self.assertEqual(timeutil.parse_interval('abc'), None) self.assertEqual(timeutil.parse_interval(''), None)