<commit_before># Resat response filter
# Use response filters to validate responses and/or store response elements in 
# variables.
# Automatically hydrated with Kwalify from YAML definition.
# See resat.rb for usage information.
#

module Resat
  
  class Guard
    include Kwalify::Util::HashLike
    attr_accessor :failures
    
    def wait(request)
      Log.info("Waiting for guard #{@name}")
      @timeout ||= 120
      @period ||= 5
      @failures = []

      if @field
        Variables.substitute!(@pattern)
        r = Regexp.new(@pattern)
        r.match(request.get_response_field(@field, @target))
        expiration = DateTime.now + @timeout
        while !Regexp.last_match && DateTime.now < expiration && request.failures.empty?
          sleep @period
          request.send
          r.match(request.get_response_field(@field, @target))
        end
      elseif @status
        status = nil
        while status != @status && DateTime.now < expiration && request.failures.empty?
          sleep @period
          request.send
          status = request.response.status
        end
      end
      @failures << "Guard '#{@name}' timed out waiting for field '#{@field}' with pattern '#{@pattern ? @pattern : '<NONE>'}' from response #{@target}." if !Regexp.last_match
    end
  end

end<commit_msg>revert to previous version<commit_after># Resat response filter
# Use response filters to validate responses and/or store response elements in
# variables.
# Automatically hydrated with Kwalify from YAML definition.
# See resat.rb for usage information.
#

module Resat

  class Guard
    include Kwalify::Util::HashLike
    attr_accessor :failures

    def wait(request)
      Log.info("Waiting for guard #{@name}")
      @timeout ||= 120
      @period ||= 5
      @failures = []

      Variables.substitute!(@pattern)
      r = Regexp.new(@pattern)
      r.match(request.get_response_field(@field, @target))
      expiration = DateTime.now + @timeout
      while !Regexp.last_match && DateTime.now < expiration && request.failures.empty?
        sleep @period
        request.send
        r.match(request.get_response_field(@field, @target))
      end
      @failures << "Guard '#{@name}' timed out waiting for field '#{@field}' with pattern '#{@pattern ? @pattern : '<NONE>'}' from response #{@target}." if !Regexp.last_match
    end
  end

end
 
{'fraction_non_alphanumeric': 0.1132713440405748, 'fraction_numerical': 0.0033812341504649195, 'mean_word_length': 2.8550488599348536, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1913817', 'n_tokens_mistral': 698, 'n_tokens_neox': 676, 'n_words': 197}