def handleRestrictedKey(self, xmlbit, key): for kid in xmlbit.getchildren(): value = kid.text try: rv = RestrictedValue.objects.get(keyid=key, value=value) except ObjectDoesNotExist: rv = RestrictedValue(keyid=key, value=value) self.verbose("Adding %s=%s to restricted key" % (key.key, value)) if not self.namespace.kiddingFlag: rv.save()
def handle(self, namespace): m = re.match("(?P<key>\w+)=(?P<value>.+)", namespace.keyvalue) if not m: raise HostinfoException("Must be specified in key=value format") key = m.group('key').lower() value = m.group('value').lower() keyobjlist = AllowedKey.objects.filter(key=key) if len(keyobjlist) != 1: raise HostinfoException("No key %s found" % key) keyobj = keyobjlist[0] if not keyobj.restrictedFlag: raise HostinfoException("Key %s isn't a restrictedvalue key" % key) rvallist = RestrictedValue.objects.filter(keyid=keyobj, value=value) if rvallist: raise HostinfoException("Already a key %s=%s in the restrictedvalue list" % (key, value)) rv = RestrictedValue(keyid=keyobj, value=value) rv.save() return None, 0