def _change_privilege(context, data_dict, what):
 read_only_user = _get_read_only_user(data_dict)
 if (what == 'REVOKE'):
  sql = u'REVOKE SELECT ON TABLE "{0}" FROM "{1}"'.format(data_dict['resource_id'], read_only_user)
 elif (what == 'GRANT'):
  sql = u'GRANT SELECT ON TABLE "{0}" TO "{1}"'.format(data_dict['resource_id'], read_only_user)
 else:
  raise ValidationError({'privileges': [u'Can only GRANT or REVOKE but not {0}'.format(what)]})
 try:
  context['connection'].execute(sql)
 except ProgrammingError as e:
  log.critical('Error making resource private. {0!r}'.format(e.message))
  raise ValidationError({'privileges': [u'cannot make "{resource_id}" private'.format(**data_dict)], 'info': {'orig': str(e.orig), 'pgcode': e.orig.pgcode}})

def _change_privilege ( context , data_dict , what ) : read_only_user = _get_read_only_user ( data_dict ) if ( what == 'REVOKE' ) : sql = u'REVOKE SELECT ON TABLE "{0}" FROM "{1}"' . format ( data_dict [ 'resource_id' ] , read_only_user ) elif ( what == 'GRANT' ) : sql = u'GRANT SELECT ON TABLE "{0}" TO "{1}"' . format ( data_dict [ 'resource_id' ] , read_only_user ) else : raise ValidationError ( { 'privileges' : [ u'Can only GRANT or REVOKE but not {0}' . format ( what ) ] } ) try : context [ 'connection' ] . execute ( sql ) except ProgrammingError as e : log . critical ( 'Error making resource private. {0!r}' . format ( e . message ) ) raise ValidationError ( { 'privileges' : [ u'cannot make "{resource_id}" private' . format ( ** data_dict ) ] , 'info' : { 'orig' : str ( e . orig ) , 'pgcode' : e . orig . pgcode } } )
we need a transaction for this code to work .