<commit_before>require 'peddler/flat_file_parser'
require 'peddler/xml_parser'

module Peddler
  # @api private
  module Parser
    class << self
      # The inevitable messiness of massaging data produced by a motley army of
      # Amazon developers
      def parse(res, encoding = 'ISO-8859-1')
        # Don't parse if there's no body
        return res unless res.body

        case res.headers['Content-Type']
        when 'text/xml'
          XMLParser.new(res)
        when 'application/octet-stream'
          FlatFileParser.new(res, encoding)
        else
          raise NotImplementedError
        end
      end
    end
  end
end<commit_msg>The XML Content Type may include charset<commit_after>require 'peddler/flat_file_parser'
require 'peddler/xml_parser'

module Peddler
  # @api private
  module Parser
    class << self
      # The inevitable messiness of massaging data produced by a motley army of
      # Amazon developers
      def parse(res, encoding = 'ISO-8859-1')
        # Don't parse if there's no body
        return res unless res.body

        content_type = res.headers['Content-Type']
        if content_type.start_with?('text/xml')
          XMLParser.new(res)
        elsif content_type == 'application/octet-stream'
          FlatFileParser.new(res, encoding)
        else
          raise NotImplementedError
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07297687861271676, 'fraction_numerical': 0.0072254335260115606, 'mean_word_length': 2.369829683698297, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7352383', 'n_tokens_mistral': 410, 'n_tokens_neox': 396, 'n_words': 120}