Esempio n. 1
0
    def decode(cls, item):
        """Decode an `item`. If the `item` is not a string, call
        its `decode` method (`item.decode()`) before running the regular
        decoding.

        :param item: The item to decode

        :returns: The decoded item
        :rtype: `dict` or `str`
        """
        if not isinstance(item, string_types):
            item = item.decode()
        ret = json.loads(item)
        return ret
Esempio n. 2
0
 def decode(cls, item):
     if isinstance(item, basestring):
         ret = json.loads(item)
         return ret
     return None
Esempio n. 3
0
 def decode(cls, item):
     if isinstance(item, basestring):
         ret = json.loads(item)
         return ret
     return None
Esempio n. 4
0
 def decode(cls, item):
     if not isinstance(item, string_types):
         item = item.decode()
     ret = json.loads(item)
     return ret
Esempio n. 5
0
 def decode(cls, item):
     if not isinstance(item, string_types):
         item = item.decode()
     ret = json.loads(item)
     return ret
Esempio n. 6
0
 def test_encode_decode_date(self):
     dt = datetime(1972, 1, 22);
     encoded = json.dumps({'dt': dt})
     decoded = json.loads(encoded)
     assert decoded['dt'] == dt
Esempio n. 7
0
 def test_dates_in_dict(self):
     dates = dict((i, datetime.now()) for i in range(50))
     decoded = json.loads(json.dumps(dates))
     for i, value in dates.items():
         assert isinstance(i, int)
         assert isinstance(value, datetime)
Esempio n. 8
0
 def test_dates_in_lists(self):
     dates = [datetime.now() for i in range(50)]
     decoded = json.loads(json.dumps(dates))
     for value in dates:
         assert isinstance(value, datetime)
Esempio n. 9
0
 def decode(cls, item):
     if item:
         ret = json.loads(item)
         return ret
     return None