Guest User

jsonpickle test

a guest
Sep 26th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. from __future__ import print_function
  2.  
  3. import collections
  4. import jsonpickle
  5. import yaml
  6. import pickle
  7. import bson
  8.  
  9. def dumpme(item):
  10.     print("item is:", item)
  11.  
  12.     y = yaml.dump(item)
  13.     print("yaml is: ", y)
  14.     assert item==yaml.load(y)
  15.  
  16.     p = pickle.dumps(item)
  17.     print("pickle is: ", p)
  18.     assert item==pickle.loads(p)
  19.  
  20.     j = jsonpickle.encode(item)
  21.     print("jsonpickle:", j)
  22.     decoded = jsonpickle.decode(j)
  23.     print("decoded is:", decoded)
  24.     assert item==jsonpickle.decode(j)
  25.  
  26. def main():
  27.     x = collections.defaultdict(list)
  28.     x['foo'].append('bar')
  29.     x['car'] = [3, 5, 'twelve']
  30.     y = dict(foo=x,
  31.              mydeque=collections.deque((8, 2, 'noon')))
  32.     dumpme(y)
  33.  
  34. if __name__ == '__main__':
  35.     main()
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment