<commit_before>require 'sinatra/base'
require 'multi_json'

module LXC
  class Server < Sinatra::Base
    set :environment, ENV['RACK_ENV'] || 'production'

    helpers do
      def json_response(data)
        MultiJson.encode(data)
      end
      
      def error_response(error, status=400)
        halt(400, json_response(:error => error))
      end

      def find_container
        @container = LXC.container(params[:c_name])
        unless @container.exists?
          error_response("Container #{name} does not exist")
        end
      end
    end
    
    before do
      content_type :json, :encoding => :utf8
    end
    
    error do
      err = env['sinatra.error']
      content_type :json, :encoding => :utf8
      json_response(:error => {:message => err.message, :type => err.class.to_s})
    end
    
    not_found do
      content_type :json, :encoding => :utf8
      json_response(:error => "Invalid request path")
    end
    
    get '/' do
      json_response({'time' => Time.now})
    end
    
    get '/version' do<commit_msg>Fix error message on non-existent container<commit_after>require 'sinatra/base'
require 'multi_json'

module LXC
  class Server < Sinatra::Base
    set :environment, ENV['RACK_ENV'] || 'production'

    helpers do
      def json_response(data)
        MultiJson.encode(data)
      end
      
      def error_response(error, status=400)
        halt(400, json_response(:error => error))
      end

      def find_container
        @container = LXC.container(params[:c_name])
        unless @container.exists?
          error_response("Container #{params[:c_name]} does not exist")
        end
      end
    end
    
    before do
      content_type :json, :encoding => :utf8
    end
    
    error do
      err = env['sinatra.error']
      content_type :json, :encoding => :utf8
      json_response(:error => {:message => err.message, :type => err.class.to_s})
    end
    
    not_found do
      content_type :json, :encoding => :utf8
      json_response(:error => "Invalid request path")
    end
    
    get '/' do
      json_response({'time' => Time.now})
    end
    
    get '/version' do
{'fraction_non_alphanumeric': 0.11282051282051282, 'fraction_numerical': 0.008391608391608392, 'mean_word_length': 2.34789391575663, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3258934', 'n_tokens_mistral': 671, 'n_tokens_neox': 655, 'n_words': 164}