Exemplo n.º 1
0
 def test_decode_microseconds(self):
     self.assertEqual(
         decode_iso_datetime(IsoDate('1970-02-01T12:14:16.123456Z')),
         datetime(1970, 2, 1, 12, 14, 16, 123456, tzinfo=pytz.utc))
     self.assertEqual(
         decode_iso_datetime(IsoDate('1970-02-01T12:14:16.000123Z')),
         datetime(1970, 2, 1, 12, 14, 16, 123, tzinfo=pytz.utc))
     self.assertEqual(
         decode_iso_datetime(IsoDate('1970-02-01T12:14:16.000123+0200')),
         datetime(1970, 2, 1, 12, 14, 16, 123,
                  tzinfo=pytz.FixedOffset(120)))
Exemplo n.º 2
0
 def _decode_iso_datetime(self, value):
     """Decode `IsoDateTime` struct to datetime object with respect to the timezone settings."""
     result = decode_iso_datetime(value)
     if not settings.USE_TZ:
         result = timezone.make_naive(result,
                                      timezone.get_default_timezone())
     return result
Exemplo n.º 3
0
 def decode(self, answer):
     if type(answer) in types.StringTypes:
         return answer.decode(self.coding)
     if type(answer) in self.BasicTypes:
         return answer
     elif type(answer) in self.IterTypes:
         return [self.decode(x) for x in answer]
     if isinstance(answer, ccReg.DateTimeType):
         return corba_to_datetime(answer)
     if isinstance(answer, ccReg.DateType):
         return corba_to_date(answer)
     if isinstance(answer, ccReg.DateType):
         return corba_to_date(answer)
     if isinstance(answer, Registry.IsoDate):
         return decode_iso_date(answer)
     if isinstance(answer, Registry.IsoDateTime):
         return decode_iso_datetime(answer)
     # OMNIOrbpy uses old style classes => check whether type is
     # InstanceType.
     if self.isInstance(answer):
         for name in dir(answer):
             item = getattr(answer, name)
             if name.startswith('_') and name != "_from":
                 # HACK to handle that OMNIOrb mangles 'from' to '_from'
                 continue  # internal module defined methods / attributes
             if isinstance(item, (types.MethodType, ) + self.BasicTypes):
                 continue  # None or methods - don't call them
             if type(item) in types.StringTypes:
                 answer.__dict__[name] = item.decode(self.coding)
                 continue
             if self.isInstance(item):
                 answer.__dict__[name] = self.decode(item)
                 continue
             if type(item) in self.IterTypes:
                 answer.__dict__[name] = [self.decode(x) for x in item]
                 continue
             raise ValueError(
                 "%s attribute in %s is not convertable to python type." %
                 (name, answer))
         return answer
Exemplo n.º 4
0
    def test_decode_zones(self):
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+0000')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.utc))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+00:00')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.utc))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16-0000')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.utc))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16-00:00')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.utc))

        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+0005')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(5)))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+0020')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(20)))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+0100')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(60)))

        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+1000')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(600)))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+10:00')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(600)))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16-1000')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(-600)))
        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16-10:00')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(-600)))

        self.assertEqual(
            decode_iso_datetime(IsoDate('1970-02-01T12:14:16+1135')),
            datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.FixedOffset(695)))
Exemplo n.º 5
0
 def test_decode(self):
     self.assertEqual(decode_iso_datetime(IsoDate('1970-02-01T12:14:16Z')),
                      datetime(1970, 2, 1, 12, 14, 16, tzinfo=pytz.utc))