1import datetime 2from collections.abc import Sequence 3 4 5def greater_than(value): 6 """``'>value'``.""" 7 return '>' + _stringify_predicate_value(value) 8 9 10def less_than(value): 11 """``'<value'``.""" 12 return '<' + _stringify_predicate_value(value) 13 14 15def not_equal(value): 16 """``'<>value'``.""" 17 return '<>' + _stringify_predicate_value(value) 18 19 20def inclusive_range(left, right): 21 """``'left--right'``.""" 22 return (_stringify_predicate_value(left) + '--' + 23 _stringify_predicate_value(right)) 24 25 26def like(value): 27 """``'~~value'``.""" 28 return '~~' + _stringify_predicate_value(value) 29 30 31def startswith(value): 32 """``'^value'``.""" 33 return '^' + _stringify_predicate_value(value) 34 35 36def _stringify_predicate_value(value): 37 """Convert Python objects to Space-Track compatible strings 38 39 - Booleans (``True`` -> ``'true'``) 40 - Sequences (``[25544, 34602]`` -> ``'25544,34602'``) 41 - dates/datetimes (``date(2015, 12, 23)`` -> ``'2015-12-23'``) 42 - ``None`` -> ``'null-val'`` 43 """ 44 if isinstance(value, bool): 45 return str(value).lower() 46 elif isinstance(value, Sequence) and not isinstance(value, str): 47 return ','.join(_stringify_predicate_value(x) for x in value) 48 elif isinstance(value, datetime.datetime): 49 return value.isoformat(sep=' ') 50 elif isinstance(value, datetime.date): 51 return value.isoformat() 52 elif value is None: 53 return 'null-val' 54 else: 55 return str(value) 56