@requires_rw<EOL><INDENT>def edit_prefix(self, auth, spec, attr):<DEDENT>
self._logger.debug("<STR_LIT>" %<EOL>(unicode(spec), unicode(attr)))<EOL>pool = None<EOL>if '<STR_LIT>' in attr or '<STR_LIT>' in attr:<EOL><INDENT>if '<STR_LIT>' in attr:<EOL><INDENT>if attr['<STR_LIT>'] is None:<EOL><INDENT>pool = {<EOL>'<STR_LIT:id>': None,<EOL>'<STR_LIT:name>': None<EOL>}<EOL><DEDENT>else:<EOL><INDENT>pool = self._get_pool(auth, { '<STR_LIT:id>': attr['<STR_LIT>'] })<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if attr['<STR_LIT>'] is None:<EOL><INDENT>pool = {<EOL>'<STR_LIT:id>': None,<EOL>'<STR_LIT:name>': None<EOL>}<EOL><DEDENT>else:<EOL><INDENT>pool = self._get_pool(auth, { '<STR_LIT:name>': attr['<STR_LIT>'] })<EOL><DEDENT>del(attr['<STR_LIT>'])<EOL><DEDENT>attr['<STR_LIT>'] = pool['<STR_LIT:id>']<EOL><DEDENT>else:<EOL><INDENT>pool = {<EOL>'<STR_LIT:id>': None,<EOL>'<STR_LIT:name>': None<EOL>}<EOL><DEDENT>vrf = self._get_vrf(auth, attr)<EOL>if '<STR_LIT>' in attr:<EOL><INDENT>del(attr['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in attr:<EOL><INDENT>del(attr['<STR_LIT>'])<EOL><DEDENT>attr['<STR_LIT>'] = vrf['<STR_LIT:id>']<EOL>self._check_attr(attr, [], _prefix_attrs)<EOL>if '<STR_LIT>' in attr:<EOL><INDENT>attr['<STR_LIT>'] = _parse_expires(attr['<STR_LIT>'])<EOL><DEDENT>prefixes = self.list_prefix(auth, spec)<EOL>where, params1 = self._expand_prefix_spec(spec.copy())<EOL>update, params2 = self._sql_expand_update(attr)<EOL>params = dict(params2.items() + params1.items())<EOL>sql = "<STR_LIT>" + update + "<STR_LIT>" + where<EOL>sql += "<STR_LIT>"<EOL>self._execute(sql, params)<EOL>updated_prefixes = self._get_updated_rows(auth, self.search_prefix)<EOL>audit_params = {<EOL>'<STR_LIT:username>': auth.username,<EOL>'<STR_LIT>': auth.authenticated_as,<EOL>'<STR_LIT>': auth.full_name,<EOL>'<STR_LIT>': auth.authoritative_source,<EOL>'<STR_LIT>': vrf['<STR_LIT:id>'],<EOL>'<STR_LIT>': vrf['<STR_LIT>'],<EOL>'<STR_LIT>': vrf['<STR_LIT:name>']<EOL>}<EOL>for p in prefixes:<EOL><INDENT>audit_params['<STR_LIT>'] = p['<STR_LIT>']<EOL>audit_params['<STR_LIT>'] = p['<STR_LIT>']<EOL>audit_params['<STR_LIT>'] = p['<STR_LIT>']<EOL>audit_params['<STR_LIT>'] = p['<STR_LIT:id>']<EOL>audit_params['<STR_LIT>'] = p['<STR_LIT>']<EOL>audit_params['<STR_LIT:description>'] = '<STR_LIT>' % (p['<STR_LIT>'], unicode(attr))<EOL>sql, params = self._sql_expand_insert(audit_params)<EOL>self._execute('<STR_LIT>' % sql, params)<EOL>if p['<STR_LIT>'] != pool['<STR_LIT:id>']:<EOL><INDENT>audit_params2 = {<EOL>'<STR_LIT>': p['<STR_LIT:id>'],<EOL>'<STR_LIT>': p['<STR_LIT>'],<EOL>'<STR_LIT>': p['<STR_LIT>'],<EOL>'<STR_LIT>': p['<STR_LIT>'],<EOL>'<STR_LIT>': p['<STR_LIT>'],<EOL>'<STR_LIT:username>': auth.username,<EOL>'<STR_LIT>': auth.authenticated_as,<EOL>'<STR_LIT>': auth.full_name,<EOL>'<STR_LIT>': auth.authoritative_source,<EOL>}<EOL>if pool['<STR_LIT:id>'] is not None:<EOL><INDENT>audit_params2['<STR_LIT>'] = pool['<STR_LIT:id>']<EOL>audit_params2['<STR_LIT>'] = pool['<STR_LIT:name>']<EOL>audit_params2['<STR_LIT:description>'] = '<STR_LIT>' % (pool['<STR_LIT:name>'], p['<STR_LIT>'])<EOL>sql, params = self._sql_expand_insert(audit_params2)<EOL>self._execute('<STR_LIT>' % sql, params)<EOL><DEDENT>if p['<STR_LIT>'] is not None:<EOL><INDENT>pool2 = self._get_pool(auth, { '<STR_LIT:id>': p['<STR_LIT>'] })<EOL>audit_params2['<STR_LIT>'] = pool2['<STR_LIT:id>']<EOL>audit_params2['<STR_LIT>'] = pool2['<STR_LIT:name>']<EOL>audit_params2['<STR_LIT:description>'] = '<STR_LIT>' % (p['<STR_LIT>'], pool2['<STR_LIT:name>'])<EOL>sql, params = self._sql_expand_insert(audit_params2)<EOL>self._execute('<STR_LIT>' % sql, params)<EOL><DEDENT><DEDENT><DEDENT>return updated_prefixes<EOL>
Update prefix matching `spec` with attributes `attr`.

            * `auth` [BaseAuth]
                AAA options.
            * `spec` [prefix_spec]
                Specifies the prefix to edit.
            * `attr` [prefix_attr]
                Prefix attributes.

            Note that there are restrictions on when and how a prefix's type
            can be changed; reservations can be changed to assignments and vice
            versa, but only if they contain no child prefixes.

            This is the documentation of the internal backend function. It's
            exposed over XML-RPC, please also see the XML-RPC documentation for
            :py:func:`nipap.xmlrpc.NipapXMLRPC.edit_prefix` for full
            understanding.