<commit_before>require 'nizbel/nntp/connection'
require 'nizbel/nntp/reply_codes'
require 'nizbel/nntp/decoders/yenc_decoder'

module Nizbel
  module Nntp
    class NntpError < StandardError; end

    class Client
      attr_reader :connected, :authenticated, :group, :overview_fields

      def initialize
        @conn = nil
        @connected = @authenticated = false
        @overview_fields = [:article_id]
      end

      def connect(hostname, port, ssl = false)
        @conn = Connection.new(hostname, port.to_i, ssl)
        @connected = ReplyCodes.is_good?(@conn.open[:code])
      end

      def authenticate(user, pass)
        send_and_verify "AUTHINFO USER #{user}"
        send_and_verify "AUTHINFO PASS #{pass}"
        set_mode 'READER'
        populate_overview_fields
        @authenticated = true
      end

      def close
        return nil unless @connected
        result = @conn.puts('QUIT')
        @conn.close
        @connected = @authenticated = false
        result
      end

      def x_overview(range)
        # alt.binaries.erotica | 1906725665-1906725667
        require_group
        send_and_verify "XZVER #{range}"
        result = decode_connection_data

        decompress(result[:data]).split("\r\n").map do |r|
          values = r.split("\t")
          Hash[(0..values.count-1).map{ |i| @overview_fields[i] }.zip(values)]
        end.each do |o|
          o[:article_id] = o[:article_id].to_i
          o[:date] = Time.parse(o[:date]).utc
          o[:bytes] = o[:bytes].to_i
          o[:lines] = o[:lines].to_i
        end
      end

      def set_group(group_name)
        result = send_and_verify("GROUP #{group_name}")
        @group = group_name
        info = result[:message].split
        { :article_count => info[0].to_i, :first => info[1].to_i, :last => info[2].to_i, :group => info[3] }
      end

      def date
        result = send_and_verify('DATE')
        Time.parse(result[:message]).utc
      end

      def article_exists?(article_id)
        result = @conn.puts("STAT <#{article_id}>")
        ReplyCodes.is_good?(result[:code])<commit_msg>Remove test group/article range<commit_after>require 'nizbel/nntp/connection'
require 'nizbel/nntp/reply_codes'
require 'nizbel/nntp/decoders/yenc_decoder'

module Nizbel
  module Nntp
    class NntpError < StandardError; end

    class Client
      attr_reader :connected, :authenticated, :group, :overview_fields

      def initialize
        @conn = nil
        @connected = @authenticated = false
        @overview_fields = [:article_id]
      end

      def connect(hostname, port, ssl = false)
        @conn = Connection.new(hostname, port.to_i, ssl)
        @connected = ReplyCodes.is_good?(@conn.open[:code])
      end

      def authenticate(user, pass)
        send_and_verify "AUTHINFO USER #{user}"
        send_and_verify "AUTHINFO PASS #{pass}"
        set_mode 'READER'
        populate_overview_fields
        @authenticated = true
      end

      def close
        return nil unless @connected
        result = @conn.puts('QUIT')
        @conn.close
        @connected = @authenticated = false
        result
      end

      def x_overview(range)
        require_group
        send_and_verify "XZVER #{range}"
        result = decode_connection_data

        decompress(result[:data]).split("\r\n").map do |r|
          values = r.split("\t")
          Hash[(0..values.count-1).map{ |i| @overview_fields[i] }.zip(values)]
        end.each do |o|
          o[:article_id] = o[:article_id].to_i
          o[:date] = Time.parse(o[:date]).utc
          o[:bytes] = o[:bytes].to_i
          o[:lines] = o[:lines].to_i
        end
      end

      def set_group(group_name)
        result = send_and_verify("GROUP #{group_name}")
        @group = group_name
        info = result[:message].split
        { :article_count => info[0].to_i, :first => info[1].to_i, :last => info[2].to_i, :group => info[3] }
      end

      def date
        result = send_and_verify('DATE')
        Time.parse(result[:message]).utc
      end

      def article_exists?(article_id)
        result = @conn.puts("STAT <#{article_id}>")
        ReplyCodes.is_good?(result[:code])
{'fraction_non_alphanumeric': 0.12455089820359282, 'fraction_numerical': 0.007664670658682635, 'mean_word_length': 2.367741935483871, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '4479792', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1338, 'n_words': 272}