Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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)
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)))
Esempio n. 8
0
    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)))