def add_rule(self, context, key, rule):
    ' Check rule integrity and uniqueless and add it to the db '
    if (not ('ruleID' in rule)):
        raise ValueError('Rule ID not defined.')
    if (not ('ruleLength' in rule)):
        if (rule['ruleID'] < 255):
            rule['ruleLength'] = 8
        else:
            raise ValueError('RuleID too large for default size on a byte')
    if (key == 'comp'):
        self.check_rule_compression(rule)
    elif (key in ['fragSender', 'fragReceiver', 'fragSender2', 'fragReceiver2', 'comp']):
        self.check_rule_fragmentation(rule)
    else:
        raise ValueError('key must be either comp, fragSender, fragReceiver, fragSender2, fragReceiver2')
    rule_id = rule['ruleID']
    rule_id_length = rule['ruleLength']
    self._checkRuleValue(rule_id, rule_id_length)
    for k in ['fragSender', 'fragReceiver', 'fragSender2', 'fragReceiver2', 'comp']:
        r = context.get(k)
        if (r is not None):
            if ((rule_id_length == r.ruleLength) and (rule_id == r.ruleID)):
                raise ValueError('Rule {}/{} exists'.format(rule_id, rule_id_length))
    context[key] = DictToAttrDeep(**rule)
Check rule integrity and uniqueless and add it to the db
def add_rule(self, context, key, rule):
    '  '
    if (not ('ruleID' in rule)):
        raise ValueError('Rule ID not defined.')
    if (not ('ruleLength' in rule)):
        if (rule['ruleID'] < 255):
            rule['ruleLength'] = 8
        else:
            raise ValueError('RuleID too large for default size on a byte')
    if (key == 'comp'):
        self.check_rule_compression(rule)
    elif (key in ['fragSender', 'fragReceiver', 'fragSender2', 'fragReceiver2', 'comp']):
        self.check_rule_fragmentation(rule)
    else:
        raise ValueError('key must be either comp, fragSender, fragReceiver, fragSender2, fragReceiver2')
    rule_id = rule['ruleID']
    rule_id_length = rule['ruleLength']
    self._checkRuleValue(rule_id, rule_id_length)
    for k in ['fragSender', 'fragReceiver', 'fragSender2', 'fragReceiver2', 'comp']:
        r = context.get(k)
        if (r is not None):
            if ((rule_id_length == r.ruleLength) and (rule_id == r.ruleID)):
                raise ValueError('Rule {}/{} exists'.format(rule_id, rule_id_length))
    context[key] = DictToAttrDeep(**rule)