[openstack-dev] [all][dev][python] constructing a deterministic representation of a python data structure

Amrith Kumar amrith at tesora.com
Thu Nov 3 18:24:58 UTC 2016


TL;DR

 

I want to take a python data structure (see later for details) and represent
it in a format that will be stable across python versions, and platforms so
that I can construct a stable hash. I'm looking for pointers to some best
practices on how to do this.

 

The longer version

 

Assume that there's some function in python that is:

 

def fn(*args, **kwargs):

    .

 

I'd like to take (args, kwargs) and construct a hash of some representation
that is deterministic. Specifically, assume that fn() is a method in the API
(oslo.messaging transport .). I'd like to construct the hash on the sender
side and on the RPC server side and make sure that the parameters are the
same.

 

So, just before calling call() or cast(), I could compute the hash and stuff
it into the dictionary that is being sent over, and I can do the same on the
receiving side. But since I cannot guarantee that the representation on the
receiving side is necessarily identical to the representation on the sending
side, I have issues computing the hash.

 

In IRC, jroll suggested json; can one safely assume that json.dumps() is a
deterministic representation?

 

Thanks for any pointers and suggestions.

 

-amrith

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20161103/6913fe68/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4805 bytes
Desc: not available
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20161103/6913fe68/attachment.bin>


More information about the OpenStack-dev mailing list