<commit_before>Puppet::Type.type(:winhttp_proxy).provide(:netsh, :parent => Puppet::Provider) do
  confine :operatingsystem => :windows
  defaultfor :operatingsystem => :windows

  def self.netsh_command
    if File.exists?("#{ENV['SYSTEMROOT']}\\SysWOW64\\netsh.exe")
      "#{ENV['SYSTEMROOT']}\\SysWOW64\\netsh.exe"
    elsif File.exists?("#{ENV['SYSTEMROOT']}\\System32\\netsh.exe")
      "#{ENV['SYSTEMROOT']}\\System32\\netsh.exe"
    else
      'netsh.exe'
    end
  end

  initvars
  commands :netsh => netsh_command

  def self.instances
    proxy = {
      'ensure' => :absent
    }
    cmd = [ 'cmd.exe', '/c', command(:netsh), 'winhttp', 'dump' ]
    if Puppet::PUPPETVERSION.to_f < 3.4
      raw, status = Puppet::Util::SUIDManager.run_and_capture(cmd)
    else
      raw = Puppet::Util::Execution.execute(cmd)
      status = raw.exitstatus
    end
    instances = []
    context = []
    raw.each_line() do |line|
      next if line =~ /^\s*(#|$)/
      if line =~ /^pushd (.*)$/
        context << $1
        next
      end
      if line =~ /^popd$/
        context.pop
        next
      end
      if context == [ 'winhttp' ] and line =~ /^reset proxy$/
        proxy = {
          'ensure' => :absent
        }
        next
      end
      if context == [ 'winhttp' ] and line =~ /^set proxy proxy-server="([^"]+)"( bypass-list="([^"]+)")?$/
        proxy = {
          'ensure'        => :present,
          'proxy_server'  => $1,
          'bypass_list'   => [],
        }
        if $3
          proxy['bypass_list'] = $3.split(';')
        end
        instances << proxy
        next
      end
      Puppet.warning('Unable to parse line %s' % line)
    end
    instances
  end

  def self.prefetch(resources)
    instances.each do |instance|
      if res = resources[instance.name.to_s]
        res.provider = instance
      end
    end
  end

  # Getters
  def proxy_server
    @property_hash[:proxy_server]
  end
  def bypass_list
    @property_hash[:bypass_list]
  end

  # Setters
  def proxy_server=(should)
    @property_hash[:proxy_server] = should
  end
  def bypass_list=(should)
    @property_hash[:bypass_list] = should
  end

  # Exists
  def exists?
    !(@property_hash[:ensure] == :absent or @property_hash.empty?)
  end

  # Keep resource properties, flush will actually apply
  def create
    @property_hash = {
      :ensure       => :present,
      :proxy_server => @resource[:proxy_server],
      :bypass_list  => @resource[:bypass_list]
    }
  end

  # Unlike create we actually immediately delete the item.
  def destroy
    netsh('winhttp', 'reset', 'proxy')
    @property_hash.clear
  end

  def flush
    cmd = [ 'cmd.exe', '/c', command(:netsh), 'winhttp', 'set', 'proxy', 'proxy-server="%s"' % @property_hash[:proxy_server], 'bypass-list="%s"' % @property_hash[:bypass_list] ]
    if Puppet::PUPPETVERSION.to_f < 3.4
      raw, status = Puppet::Util::SUIDManager.run_and_capture(cmd)
    else
      raw = Puppet::Util::Execution.execute(cmd)
      status = raw.exitstatus
    end
  end
end
<commit_msg>Missing name<commit_after>Puppet::Type.type(:winhttp_proxy).provide(:netsh, :parent => Puppet::Provider) do
  confine :operatingsystem => :windows
  defaultfor :operatingsystem => :windows

  def self.netsh_command
    if File.exists?("#{ENV['SYSTEMROOT']}\\SysWOW64\\netsh.exe")
      "#{ENV['SYSTEMROOT']}\\SysWOW64\\netsh.exe"
    elsif File.exists?("#{ENV['SYSTEMROOT']}\\System32\\netsh.exe")
      "#{ENV['SYSTEMROOT']}\\System32\\netsh.exe"
    else
      'netsh.exe'
    end
  end

  initvars
  commands :netsh => netsh_command

  def self.instances
    proxy = {
      'ensure' => :absent
    }
    cmd = [ 'cmd.exe', '/c', command(:netsh), 'winhttp', 'dump' ]
    if Puppet::PUPPETVERSION.to_f < 3.4
      raw, status = Puppet::Util::SUIDManager.run_and_capture(cmd)
    else
      raw = Puppet::Util::Execution.execute(cmd)
      status = raw.exitstatus
    end
    instances = []
    context = []
    raw.each_line() do |line|
      next if line =~ /^\s*(#|$)/
      if line =~ /^pushd (.*)$/
        context << $1
        next
      end
      if line =~ /^popd$/
        context.pop
        next
      end
      if context == [ 'winhttp' ] and line =~ /^reset proxy$/
        proxy = {
          'ensure' => :absent
        }
        next
      end
      if context == [ 'winhttp' ] and line =~ /^set proxy proxy-server="([^"]+)"( bypass-list="([^"]+)")?$/
        proxy = {
          'name'          => 'proxy',
          'ensure'        => :present,
          'proxy_server'  => $1,
          'bypass_list'   => [],
        }
        if $3
          proxy['bypass_list'] = $3.split(';')
        end
        instances << proxy
        next
      end
      Puppet.warning('Unable to parse line %s' % line)
    end
    instances
  end

  def self.prefetch(resources)
    instances.each do |instance|
      if res = resources[instance['name'].to_s]
        res.provider = instance
      end
    end
  end

  # Getters
  def proxy_server
    @property_hash[:proxy_server]
  end
  def bypass_list
    @property_hash[:bypass_list]
  end

  # Setters
  def proxy_server=(should)
    @property_hash[:proxy_server] = should
  end
  def bypass_list=(should)
    @property_hash[:bypass_list] = should
  end

  # Exists
  def exists?
    !(@property_hash[:ensure] == :absent or @property_hash.empty?)
  end

  # Keep resource properties, flush will actually apply
  def create
    @property_hash = {
      :ensure       => :present,
      :proxy_server => @resource[:proxy_server],
      :bypass_list  => @resource[:bypass_list]
    }
  end

  # Unlike create we actually immediately delete the item.
  def destroy
    netsh('winhttp', 'reset', 'proxy')
    @property_hash.clear
  end

  def flush
    cmd = [ 'cmd.exe', '/c', command(:netsh), 'winhttp', 'set', 'proxy', 'proxy-server="%s"' % @property_hash[:proxy_server], 'bypass-list="%s"' % @property_hash[:bypass_list] ]
    if Puppet::PUPPETVERSION.to_f < 3.4
      raw, status = Puppet::Util::SUIDManager.run_and_capture(cmd)
    else
      raw = Puppet::Util::Execution.execute(cmd)
      status = raw.exitstatus
    end
  end
end

{'fraction_non_alphanumeric': 0.1520677303809834, 'fraction_numerical': 0.005210029306414849, 'mean_word_length': 2.4569499155880696, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 28, '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': '2482270', 'n_tokens_mistral': 2142, 'n_tokens_neox': 2081, 'n_words': 435}