nodes: 0, module; 1, function_definition; 2, function_name:blacklist; 3, parameters; 4, block; 5, identifier:db; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, with_statement; 10, return_statement; 11, identifier:term; 12, None; 13, comment:"""List the blacklisted entities available in the registry.
  
      The function will return the list of blacklisted entities. If term
      parameter is set, it will only return the information about the
      entities which match that term. When the given term does not match
      with any entry on the blacklist a 'NotFoundError' exception will
      be raised.
  
      :param db: database manager
      :param term: term to match with blacklisted entries
  
      :returns: a list of blacklisted entities sorted by their name
  
      :raises NotFoundError: raised when the given term is not found on
          any blacklisted entry from the registry
      """; 14, assignment; 15, with_clause; 16, block; 17, identifier:mbs; 18, identifier:mbs; 19, list; 20, with_item; 21, if_statement; 22, comment:# Detach objects from the session; 23, expression_statement; 24, as_pattern; 25, identifier:term; 26, block; 27, else_clause; 28, call; 29, call; 30, as_pattern_target; 31, expression_statement; 32, if_statement; 33, block; 34, attribute; 35, argument_list; 36, attribute; 37, argument_list; 38, identifier:session; 39, assignment; 40, not_operator; 41, block; 42, expression_statement; 43, identifier:session; 44, identifier:expunge_all; 45, identifier:db; 46, identifier:connect; 47, identifier:mbs; 48, call; 49, identifier:mbs; 50, raise_statement; 51, assignment; 52, attribute; 53, argument_list; 54, call; 55, identifier:mbs; 56, call; 57, call; 58, identifier:all; 59, identifier:NotFoundError; 60, argument_list; 61, attribute; 62, argument_list; 63, attribute; 64, argument_list; 65, keyword_argument; 66, call; 67, identifier:all; 68, call; 69, line_continuation:\; 70, identifier:order_by; 71, attribute; 72, identifier:entity; 73, identifier:term; 74, attribute; 75, argument_list; 76, attribute; 77, argument_list; 78, identifier:MatchingBlacklist; 79, identifier:excluded; 80, call; 81, line_continuation:\; 82, identifier:order_by; 83, attribute; 84, call; 85, line_continuation:\; 86, identifier:filter; 87, call; 88, attribute; 89, argument_list; 90, identifier:MatchingBlacklist; 91, identifier:excluded; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, identifier:session; 97, identifier:query; 98, identifier:MatchingBlacklist; 99, identifier:session; 100, identifier:query; 101, identifier:MatchingBlacklist; 102, attribute; 103, identifier:like; 104, binary_operator:'%' + term + '%'; 105, identifier:MatchingBlacklist; 106, identifier:excluded; 107, binary_operator:'%' + term; 108, string; 109, string; 110, identifier:term; 111, string_content:%; 112, string_content:%
code: def blacklist(db, term=None):
      """List the blacklisted entities available in the registry.
  
      The function will return the list of blacklisted entities. If term
      parameter is set, it will only return the information about the
      entities which match that term. When the given term does not match
      with any entry on the blacklist a 'NotFoundError' exception will
      be raised.
  
      :param db: database manager
      :param term: term to match with blacklisted entries
  
      :returns: a list of blacklisted entities sorted by their name
  
      :raises NotFoundError: raised when the given term is not found on
          any blacklisted entry from the registry
      """
      mbs = []
  
      with db.connect() as session:
          if term:
              mbs = session.query(MatchingBlacklist).\
                  filter(MatchingBlacklist.excluded.like('%' + term + '%')).\
                  order_by(MatchingBlacklist.excluded).all()
  
              if not mbs:
                  raise NotFoundError(entity=term)
          else:
              mbs = session.query(MatchingBlacklist).\
                  order_by(MatchingBlacklist.excluded).all()
  
          # Detach objects from the session
          session.expunge_all()
  
      return mbs