def to_python(self, value): value = super(Time, self).to_database(value) if value is None: return if isinstance(value, util.Time): return value return util.Time(value)
def setUpClass(cls): if PROTOCOL_VERSION < 4 or CASSANDRA_VERSION < "3.0": return cls.db_klass, cls.python_klass = UserDefinedType, User cls.first_value = User( age=1, date_param=datetime.utcnow(), map_param={ 1: time(2, 12, 7, 50), 2: util.Time(time(2, 12, 7, 49)) }, list_param=[datetime(1, 1, 2), datetime(1, 1, 3)], set_param=set((datetime(1, 1, 3), util.Date(datetime(1, 1, 1)))), tuple_param=(datetime(1, 1, 3), 2, False, 1, 2.324, uuid4())) cls.second_value = User( age=1, date_param=datetime.utcnow(), map_param={ 1: time(2, 12, 7, 50), 2: util.Time(time(2, 12, 7, 49)) }, list_param=[datetime(1, 1, 2), datetime(1, 2, 3)], set_param=None, tuple_param=(datetime(1, 1, 2), 2, False, 1, 2.324, uuid4())) cls.third_value = User( age=2, date_param=None, map_param={ 1: time(2, 12, 7, 51), 2: util.Time(time(2, 12, 7, 49)) }, list_param=[datetime(1, 1, 2), datetime(1, 1, 4)], set_param=set((datetime(1, 1, 3), util.Date(datetime(1, 1, 2)))), tuple_param=(None, 3, False, None, 2.3214, uuid4())) cls.model_class = UserModel sync_table(cls.model_class)
def setUpClass(cls): cls.db_klass, cls.python_klass = (Time, util.Time) cls.first_value, cls.second_value, cls.third_value = (None, util.Time( time( 2, 12, 7, 49)), time( 2, 12, 7, 50)) super(TestTime, cls).setUpClass()
def serialize(val, protocol_version): try: nano = val.nanosecond_time except AttributeError: nano = util.Time(val).nanosecond_time return int64_pack(nano)
def deserialize(byts, protocol_version): return util.Time(int64_unpack(byts))
def to_database(self, value): value = super(Time, self).to_database(value) if value is None: return # str(util.Time) yields desired CQL encoding return value if isinstance(value, util.Time) else util.Time(value)