'Get allowed library names for specified user from set of all library names'

def allowed_library_names(self, username, all_library_names):

    r = self.restrictions(username)
    if (r is None):
        return set()
    inc = r[u'allowed_library_names']
    exc = r[u'blocked_library_names']
    def check(n):
        n = n.lower()
        return (((not inc) or (n in inc)) and (n not in exc))
    return {n for n in all_library_names if check(n)}
