<commit_before>module PrivateAddressCheck
  PrivateConnectionAttemptedError = Class.new(StandardError)

  module_function

  def only_public_connections
    Thread.current[:private_address_check] = true
    yield
  ensure
    Thread.current[:private_address_check] = false
  end

  module TCPSocketExt
    def initialize(remote_host, remote_port, local_host = nil, local_port = nil)
      if Thread.current[:private_address_check]
        if PrivateAddressCheck.resolves_to_private_address?(remote_host)
          raise PrivateAddressCheck::PrivateConnectionAttemptedError
        end

        super(remote_host, remote_port, local_host, local_port)
      else
        super
      end
    end
  end
end

TCPSocket.send(:prepend, PrivateAddressCheck::TCPSocketExt)
<commit_msg>Simplify TCP socket extension initializer<commit_after>module PrivateAddressCheck
  PrivateConnectionAttemptedError = Class.new(StandardError)

  module_function

  def only_public_connections
    Thread.current[:private_address_check] = true
    yield
  ensure
    Thread.current[:private_address_check] = false
  end

  module TCPSocketExt
    def initialize(remote_host, remote_port, local_host = nil, local_port = nil)
      if Thread.current[:private_address_check] && PrivateAddressCheck.resolves_to_private_address?(remote_host)
        raise PrivateAddressCheck::PrivateConnectionAttemptedError
      end

      super
    end
  end
end

TCPSocket.send(:prepend, PrivateAddressCheck::TCPSocketExt)

{'fraction_non_alphanumeric': 0.06009453072248481, 'fraction_numerical': 0.0, 'mean_word_length': 4.5092936802973975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5552189', 'n_tokens_mistral': 418, 'n_tokens_neox': 409, 'n_words': 81}