<commit_before>require 'nmap/scanner'
require 'nmap/scan_task'
require 'nmap/scan'
require 'nmap/host'
require 'nmap/run_stat'
require 'nmap/prescript'
require 'nmap/postscript'

require 'nokogiri'

module Nmap
  #
  # Represents an Nmap XML file.
  #
  class XML

    include Enumerable

    # Path of the Nmap XML scan file
    attr_reader :path

    #
    # Creates a new XML object.
    #
    # @param [Nokogiri::XML::Document, IO, String] document
    #   The path to the Nmap XML scan file or Nokogiri::XML::Document.
    #
    # @yield [xml]
    #   If a block is given, it will be passed the new XML object.
    #
    # @yieldparam [XML] xml
    #   The newly created XML object.
    #
    def initialize(document)
      case document
      when Nokogiri::XML::Document
        @doc = document
      when IO, StringIO
        @doc = Nokogiri::XML(document)
      else
        @path = File.expand_path(document)
        @doc  = Nokogiri::XML(open(@path))
      end

      yield self if block_given?
    end<commit_msg>Use explicit File.open to avoid open-uri weirdness.<commit_after>require 'nmap/scanner'
require 'nmap/scan_task'
require 'nmap/scan'
require 'nmap/host'
require 'nmap/run_stat'
require 'nmap/prescript'
require 'nmap/postscript'

require 'nokogiri'

module Nmap
  #
  # Represents an Nmap XML file.
  #
  class XML

    include Enumerable

    # Path of the Nmap XML scan file
    attr_reader :path

    #
    # Creates a new XML object.
    #
    # @param [Nokogiri::XML::Document, IO, String] document
    #   The path to the Nmap XML scan file or Nokogiri::XML::Document.
    #
    # @yield [xml]
    #   If a block is given, it will be passed the new XML object.
    #
    # @yieldparam [XML] xml
    #   The newly created XML object.
    #
    def initialize(document)
      case document
      when Nokogiri::XML::Document
        @doc = document
      when IO, StringIO
        @doc = Nokogiri::XML(document)
      else
        @path = File.expand_path(document)
        @doc  = Nokogiri::XML(File.open(@path))
      end

      yield self if block_given?
    end
{'fraction_non_alphanumeric': 0.09555661729574773, 'fraction_numerical': 0.0, 'mean_word_length': 2.519327731092437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6091152', 'n_tokens_mistral': 708, 'n_tokens_neox': 691, 'n_words': 211}