def _to_value(cls, class_, value, k=None): if issubclass(class_, ComplexModelBase): return cls._to_dict(class_, value, k) if issubclass(class_, DateTime): return ProtocolBase.to_string(class_, value) if issubclass(class_, Decimal): if class_.Attributes.format is None: return value else: return ProtocolBase.to_string(class_, value) return value
def _to_value(cls, class_, value, k=None): if issubclass(class_, ComplexModelBase): return cls._to_dict(class_, value, k) if issubclass(class_, DateTime): return ProtocolBase.to_string(class_, value) if issubclass(class_, Decimal): if class_.Attributes.format is None: return value else: return ProtocolBase.to_string(class_, value) return value
def test_date(self): n = datetime.date(2011,12,13) ret = ProtocolBase.to_string(Date, n) self.assertEquals(ret, n.isoformat()) dt = ProtocolBase.from_string(Date, ret) self.assertEquals(n, dt)
def test_time(self): n = datetime.time(1, 2, 3, 4) ret = ProtocolBase.to_string(Time, n) self.assertEquals(ret, n.isoformat()) dt = ProtocolBase.from_string(Time, ret) self.assertEquals(n, dt)
def test_date(self): n = datetime.date(2011, 12, 13) ret = ProtocolBase.to_string(Date, n) self.assertEquals(ret, n.isoformat()) dt = ProtocolBase.from_string(Date, ret) self.assertEquals(n, dt)
def test_time(self): n = datetime.time(1, 2, 3, 4) ret = ProtocolBase.to_string(Time, n) self.assertEquals(ret, n.isoformat()) dt = ProtocolBase.from_string(Time, ret) self.assertEquals(n, dt)
def test_duration_xml_duration(self): dur = datetime.timedelta(days=5 + 30 + 365, hours=1, minutes=1, seconds=12, microseconds=8e5) str1 = 'P400DT3672.8S' str2 = 'P1Y1M5DT1H1M12.8S' self.assertEquals(dur, ProtocolBase.from_string(Duration, str1)) self.assertEquals(dur, ProtocolBase.from_string(Duration, str2)) self.assertEquals(dur, ProtocolBase.from_string(Duration, ProtocolBase.to_string(Duration, dur)))
def test_duration_xml_duration(self): dur = datetime.timedelta(days=5 + 30 + 365, hours=1, minutes=1, seconds=12, microseconds=8e5) str1 = 'P400DT3672.8S' str2 = 'P1Y1M5DT1H1M12.8S' self.assertEquals(dur, ProtocolBase.from_string(Duration, str1)) self.assertEquals(dur, ProtocolBase.from_string(Duration, str2)) self.assertEquals( dur, ProtocolBase.from_string(Duration, ProtocolBase.to_string(Duration, dur)))