'set the full set of geonetwork privileges on the item with the
specified uuid based on the dictionary given of the form:
\'group_name1\': {\'operation1\': True, \'operation2\': True, ...},
\'group_name2\': ...
all unspecified operations and operations for unspecified groups
are set to False.'

def set_metadata_privs(self, uuid, privileges):

    if (self.type == 'geonetwork'):
        get_dbid_url = ('%sgeonetwork/srv/en/portal.search.present?%s' % (self.base, urllib.urlencode({'uuid': uuid})))
        request = urllib2.Request(get_dbid_url)
        response = self.urlopen(request)
        doc = etree.fromstring(response.read())
        data_dbid = doc.find('metadata/{http://www.fao.org/geonetwork}info/id').text
        if (len(self._group_ids) == 0):
            self._group_ids = self._geonetwork_get_group_ids()
        if (len(self._operation_ids) == 0):
            self._operation_ids = self._geonetwork_get_operation_ids()
        priv_params = {'id': data_dbid}
        for (group, privs) in privileges.items():
            group_id = self._group_ids[group.lower()]
            for (op, state) in privs.items():
                if (state is not True):
                    continue
                op_id = self._operation_ids[op.lower()]
                priv_params[('_%s_%s' % (group_id, op_id))] = 'on'
        update_privs_url = ('%sgeonetwork/srv/en/metadata.admin?%s' % (self.base, urllib.urlencode(priv_params)))
        request = urllib2.Request(update_privs_url)
        response = self.urlopen(request)
