def body_string(body_dict, prefix=''):
 body_list = []
 for (key, value) in sorted(body_dict.items()):
  if isinstance(value, (list, tuple)):
   for (i, arr) in enumerate(value):
    if isinstance(arr, dict):
     body_list.append(body_string(arr, u'{}.{}.'.format(key, i)))
    else:
     body_list.append(u'{}.{}:{}\n'.format(key, i, arr).encode('utf-8'))
  elif isinstance(value, dict):
   body_list.append(body_string(value, (key + ':')))
  else:
   if (value is None):
    value = 'null'
   body_list.append(u'{}{}:{}\n'.format(prefix, key, value).encode('utf-8'))
 return ''.join(body_list)

def body_string ( body_dict , prefix = '' ) : body_list = [ ] for ( key , value ) in sorted ( body_dict . items ( ) ) : if isinstance ( value , ( list , tuple ) ) : for ( i , arr ) in enumerate ( value ) : if isinstance ( arr , dict ) : body_list . append ( body_string ( arr , u'{}.{}.' . format ( key , i ) ) ) else : body_list . append ( u'{}.{}:{}\n' . format ( key , i , arr ) . encode ( 'utf-8' ) ) elif isinstance ( value , dict ) : body_list . append ( body_string ( value , ( key + ':' ) ) ) else : if ( value is None ) : value = 'null' body_list . append ( u'{}{}:{}\n' . format ( prefix , key , value ) . encode ( 'utf-8' ) ) return '' . join ( body_list )
return a canonical string representation of the body of a json request or response .