nodes: 0, module; 1, function_definition; 2, function_name:registry; 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 organizations available in the registry.
  
      The function will return the list of organizations. If term
      parameter is set, it will only return the information about
      the organizations which match that term. When the given term does
      not match with any organization from the registry a 'NotFounError'
      exception will be raised.
  
      :param db: database manager
      :param term: term to match with organizations names
  
      :returns: a list of organizations sorted by their name
  
      :raises NotFoundError: raised when the given term is not found on
          any organization from the registry
      """; 14, assignment; 15, with_clause; 16, block; 17, identifier:orgs; 18, identifier:orgs; 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:orgs; 48, call; 49, identifier:orgs; 50, raise_statement; 51, assignment; 52, attribute; 53, argument_list; 54, call; 55, identifier:orgs; 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:Organization; 79, identifier:name; 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:Organization; 91, identifier:name; 92, attribute; 93, argument_list; 94, attribute; 95, argument_list; 96, identifier:session; 97, identifier:query; 98, identifier:Organization; 99, identifier:session; 100, identifier:query; 101, identifier:Organization; 102, attribute; 103, identifier:like; 104, binary_operator:'%' + term + '%'; 105, identifier:Organization; 106, identifier:name; 107, binary_operator:'%' + term; 108, string; 109, string; 110, identifier:term; 111, string_content:%; 112, string_content:%
code: def registry(db, term=None):
      """List the organizations available in the registry.
  
      The function will return the list of organizations. If term
      parameter is set, it will only return the information about
      the organizations which match that term. When the given term does
      not match with any organization from the registry a 'NotFounError'
      exception will be raised.
  
      :param db: database manager
      :param term: term to match with organizations names
  
      :returns: a list of organizations sorted by their name
  
      :raises NotFoundError: raised when the given term is not found on
          any organization from the registry
      """
      orgs = []
  
      with db.connect() as session:
          if term:
              orgs = session.query(Organization).\
                  filter(Organization.name.like('%' + term + '%')).\
                  order_by(Organization.name).all()
  
              if not orgs:
                  raise NotFoundError(entity=term)
          else:
              orgs = session.query(Organization).\
                  order_by(Organization.name).all()
  
          # Detach objects from the session
          session.expunge_all()
  
      return orgs