'Find matching rulesets for domain in this subtree.
@param domain: domain to search for in this node\'s subtrees;
empty string matches this node. Must not contain wildcards.
@return: set of applicate rulesets'

def matchingRulesets(self, domain):

    if (domain == ''):
        return self.rulesets
    applicableRules = set()
    if ((self.depth >= 3) and (self.subDomain == '*')):
        applicableRules.update(self.rulesets)
    if (not isinstance(domain, unicode)):
        domain = domain.decode('utf-8')
    domain = domain.encode('idna')
    parts = domain.rsplit('.', 1)
    if (len(parts) == 1):
        childDomain = domain
        subLevelDomain = ''
    else:
        (subLevelDomain, childDomain) = parts
    wildcardChild = self.children.get('*')
    ruleChild = self.children.get(childDomain)
    if ruleChild:
        applicableRules.update(ruleChild.matchingRulesets(subLevelDomain))
    if wildcardChild:
        applicableRules.update(wildcardChild.matchingRulesets(subLevelDomain))
    return applicableRules
