def dict_error_formatting(errors, index=None):
 formatted_error_list = []
 top_level_error_keys = ['links', 'status', 'code', 'detail', 'source', 'meta']
 resource_object_identifiers = ['type', 'id']
 if (index is None):
  index = ''
 else:
  index = (str(index) + '/')
 for (error_key, error_description) in errors.iteritems():
  if isinstance(error_description, basestring):
   error_description = [error_description]
  if (error_key in top_level_error_keys):
   formatted_error_list.extend(({error_key: description} for description in error_description))
  elif (error_key in resource_object_identifiers):
   formatted_error_list.extend([{'source': {'pointer': ('/data/{}'.format(index) + error_key)}, 'detail': reason} for reason in error_description])
  elif (error_key == 'non_field_errors'):
   formatted_error_list.extend([{'detail': description for description in error_description}])
  else:
   formatted_error_list.extend([{'source': {'pointer': ('/data/{}attributes/'.format(index) + error_key)}, 'detail': reason} for reason in error_description])
 return formatted_error_list

def dict_error_formatting ( errors , index = None ) : formatted_error_list = [ ] top_level_error_keys = [ 'links' , 'status' , 'code' , 'detail' , 'source' , 'meta' ] resource_object_identifiers = [ 'type' , 'id' ] if ( index is None ) : index = '' else : index = ( str ( index ) + '/' ) for ( error_key , error_description ) in errors . iteritems ( ) : if isinstance ( error_description , basestring ) : error_description = [ error_description ] if ( error_key in top_level_error_keys ) : formatted_error_list . extend ( ( { error_key : description } for description in error_description ) ) elif ( error_key in resource_object_identifiers ) : formatted_error_list . extend ( [ { 'source' : { 'pointer' : ( '/data/{}' . format ( index ) + error_key ) } , 'detail' : reason } for reason in error_description ] ) elif ( error_key == 'non_field_errors' ) : formatted_error_list . extend ( [ { 'detail' : description for description in error_description } ] ) else : formatted_error_list . extend ( [ { 'source' : { 'pointer' : ( '/data/{}attributes/' . format ( index ) + error_key ) } , 'detail' : reason } for reason in error_description ] ) return formatted_error_list
formats all dictionary error messages for both single and bulk requests .