Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created June 5, 2012 03:41
Show Gist options
  • Save j2labs/2872483 to your computer and use it in GitHub Desktop.
Save j2labs/2872483 to your computer and use it in GitHub Desktop.
msgpack support in dictshield?
>>> m.to_json(encode=False)
{'owner': '557554ab-757f-421a-9838-8783d8555df3', '_types': ['Media'], '_cls': 'Media', 'title': u'Misc Media'}
>>> p = msgpack.packb(m.to_json(encode=False))
>>> p
'\x84\xa5owner\xda\x00$557554ab-757f-421a-9838-8783d8555df3\xa6_types\x91\xa5Media\xa4_cls\xa5Media\xa5title\xaaMisc Media'
>>> d = msgpack.unpackb(p)
{'owner': '557554ab-757f-421a-9838-8783d8555df3', '_types': ('Media',), '_cls': 'Media', 'title': 'Misc Media'}
>>> Movie(**d)
<Movie: Movie object>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment