nodes: 0, module; 1, function_definition; 2, function_name:_GetUnsortedNotifications; 3, parameters; 4, block; 5, identifier:self; 6, identifier:queue_shard; 7, default_parameter; 8, expression_statement; 9, if_statement; 10, expression_statement; 11, for_statement; 12, return_statement; 13, identifier:notifications_by_session_id; 14, None; 15, comment:"""Returns all the available notifications for a queue_shard.
  
      Args:
        queue_shard: urn of queue shard
        notifications_by_session_id: store notifications in this dict rather than
          creating a new one
  
      Returns:
        dict of notifications. keys are session ids.
      """; 16, comparison_operator:notifications_by_session_id is None; 17, block; 18, assignment; 19, identifier:notification; 20, call; 21, block; 22, identifier:notifications_by_session_id; 23, identifier:notifications_by_session_id; 24, None; 25, expression_statement; 26, identifier:end_time; 27, boolean_operator; 28, attribute; 29, argument_list; 30, expression_statement; 31, if_statement; 32, assignment; 33, attribute; 34, call; 35, attribute; 36, identifier:GetNotifications; 37, identifier:queue_shard; 38, identifier:end_time; 39, assignment; 40, identifier:existing; 41, comment:# If we have a notification for this session_id already, we only store; 42, comment:# the one that was scheduled last.; 43, block; 44, else_clause; 45, identifier:notifications_by_session_id; 46, dictionary; 47, identifier:self; 48, identifier:frozen_timestamp; 49, attribute; 50, argument_list; 51, identifier:self; 52, identifier:data_store; 53, identifier:existing; 54, call; 55, if_statement; 56, block; 57, attribute; 58, identifier:Now; 59, attribute; 60, argument_list; 61, comparison_operator:notification.first_queued > existing.first_queued; 62, block; 63, elif_clause; 64, expression_statement; 65, identifier:rdfvalue; 66, identifier:RDFDatetime; 67, identifier:notifications_by_session_id; 68, identifier:get; 69, attribute; 70, attribute; 71, attribute; 72, expression_statement; 73, boolean_operator; 74, comment:# Multiple notifications with the same timestamp should not happen.; 75, comment:# We can still do the correct thing and use the latest one.; 76, block; 77, assignment; 78, identifier:notification; 79, identifier:session_id; 80, identifier:notification; 81, identifier:first_queued; 82, identifier:existing; 83, identifier:first_queued; 84, assignment; 85, comparison_operator:notification.first_queued == existing.first_queued; 86, parenthesized_expression; 87, expression_statement; 88, expression_statement; 89, subscript; 90, identifier:notification; 91, subscript; 92, identifier:notification; 93, attribute; 94, attribute; 95, comparison_operator:notification.last_status > existing.last_status; 96, call; 97, assignment; 98, identifier:notifications_by_session_id; 99, attribute; 100, identifier:notifications_by_session_id; 101, attribute; 102, identifier:notification; 103, identifier:first_queued; 104, identifier:existing; 105, identifier:first_queued; 106, attribute; 107, attribute; 108, attribute; 109, argument_list; 110, subscript; 111, identifier:notification; 112, identifier:notification; 113, identifier:session_id; 114, identifier:notification; 115, identifier:session_id; 116, identifier:notification; 117, identifier:last_status; 118, identifier:existing; 119, identifier:last_status; 120, identifier:logging; 121, identifier:warning; 122, string:"Notifications with equal first_queued fields detected: %s %s"; 123, identifier:notification; 124, identifier:existing; 125, identifier:notifications_by_session_id; 126, attribute; 127, identifier:notification; 128, identifier:session_id
code: def _GetUnsortedNotifications(self,
                                  queue_shard,
                                  notifications_by_session_id=None):
      """Returns all the available notifications for a queue_shard.
  
      Args:
        queue_shard: urn of queue shard
        notifications_by_session_id: store notifications in this dict rather than
          creating a new one
  
      Returns:
        dict of notifications. keys are session ids.
      """
      if notifications_by_session_id is None:
        notifications_by_session_id = {}
      end_time = self.frozen_timestamp or rdfvalue.RDFDatetime.Now()
      for notification in self.data_store.GetNotifications(queue_shard, end_time):
  
        existing = notifications_by_session_id.get(notification.session_id)
        if existing:
          # If we have a notification for this session_id already, we only store
          # the one that was scheduled last.
          if notification.first_queued > existing.first_queued:
            notifications_by_session_id[notification.session_id] = notification
          elif notification.first_queued == existing.first_queued and (
              notification.last_status > existing.last_status):
            # Multiple notifications with the same timestamp should not happen.
            # We can still do the correct thing and use the latest one.
            logging.warning(
                "Notifications with equal first_queued fields detected: %s %s",
                notification, existing)
            notifications_by_session_id[notification.session_id] = notification
        else:
          notifications_by_session_id[notification.session_id] = notification
  
      return notifications_by_session_id