jiahuimbzuai/CoQuIR huggingface dataset:
// _read_clouds [python]
    def _read_clouds(self):
        try:
            with open(self._clouds_path) as clouds_file:
                self._clouds = yaml.load(clouds_file)
        except IOError:
            # The user doesn't have a clouds.yaml file.
            print("The user clouds.yaml file didn't exist.")
            self._clouds = {}
// check_testPickle [python]
    def check_testPickle(self):
        "Test of pickling"
        import pickle
        x = arange(12)
        x[4:10:2] = masked
        x = x.reshape(4,3)
        s = pickle.dumps(x)
        y = pickle.loads(s)
        assert eq(x,y)
// check_testPickle [python]
    def check_testPickle(self):
        "Test of pickling"
        x = arange(12)
        x[4:10:2] = masked
        x=x.reshape(4,3)
        f = open('test9.pik','wb')
        import pickle
        pickle.dump(x, f)
        f.close()
        f = open('test9.pik', 'rb')
        y = pickle.load(f)
        assert eq(x,y)
// load_yaml [python]
    def load_yaml(self, file):
        data = yaml.safe_load(file)
        for concept_type_key, vocabs in data.items():
            concept_type = {
                'classification_schemes': ClassificationRecord,
                'subject_schemes': AuthorityRecord,
            }.get(concept_type_key)
            for scheme_code, options in vocabs.items():
                if is_str(options):
                    options = {'base_uri': options}
                self.entries[scheme_code] = ConceptScheme(concept_type, scheme_code, options=options)
// load_yaml [python]
    def load_yaml(self, file):
        data = yaml.load(file)
        for concept_type_key, vocabs in data.items():
            concept_type = {
                'classification_schemes': ClassificationRecord,
                'subject_schemes': AuthorityRecord,
            }.get(concept_type_key)
            for scheme_code, options in vocabs.items():
                if is_str(options):
                    options = {'base_uri': options}
                self.entries[scheme_code] = ConceptScheme(concept_type, scheme_code, options=options)
// __init__ [python]
    def __init__(self, *args, **kwargs):
        yaml.SafeLoader.__init__(self, *args, **kwargs)

        self.add_constructor(u'tag:yaml.org,2002:map', type(self).construct_yaml_map)
        self.add_constructor(u'tag:yaml.org,2002:omap', type(self).construct_yaml_map)
// __init__ [python]
    def __init__(self, *args, **kwargs):
        yaml.Loader.__init__(self, *args, **kwargs)

        self.add_constructor(u'tag:yaml.org,2002:map', type(self).construct_yaml_map)
        self.add_constructor(u'tag:yaml.org,2002:omap', type(self).construct_yaml_map)
// generate_fZ [python]
    def generate_fZ(self, Obs, TL, currentTimeAbs, mode, hashname):
        """Calculates fZ values for all stars over an entire orbit of the sun
        Args:
            Obs (module):
                Observatory module
            TL (module):
                Target List Module
            currentTimeAbs (astropy Time array):
                current absolute time im MJD
            mode (dict):
                Selected observing mode
            hashname (string):
                hashname describing the files specific to the current json script
        Updates Attributes:
            fZ_startSaved[1000, TL.nStars] (astropy Quantity array):
                Surface brightness of zodiacal light in units of 1/arcsec2 for each star over 1 year at discrete points defined by resolution
        """
        #Generate cache Name########################################################################
        cachefname = hashname+'starkfZ'

        #Check if file exists#######################################################################
        if os.path.isfile(cachefname):#check if file exists
            self.vprint("Loading cached fZ from %s"%cachefname)
            with open(cachefname, 'rb') as f:#load from cache
                tmpfZ = pickle.load(f)
            return tmpfZ

        #IF the Completeness vs dMag for Each Star File Does Not Exist, Calculate It
        else:
            self.vprint("Calculating fZ")
            #OS = self.OpticalSystem#Testing to be sure I can remove this
            #WA = OS.WA0#Testing to be sure I can remove this
            sInds= np.arange(TL.nStars)
            startTime = np.zeros(sInds.shape[0])*u.d + currentTimeAbs#Array of current times
            resolution = [j for j in range(1000)]
            fZ = np.zeros([sInds.shape[0], len(resolution)])
            dt = 365.25/len(resolution)*u.d
            for i in xrange(len(resolution)):#iterate through all times of year
                time = startTime + dt*resolution[i]
                fZ[:,i] = self.fZ(Obs, TL, sInds, time, mode)
            
            with open(cachefname, "wb") as fo:
                pickle.dump(fZ,fo)
                self.vprint("Saved cached 1st year fZ to %s"%cachefname)
            return fZ
// generate_fZ [python]
    def generate_fZ(self, Obs, TL, currentTimeAbs, mode, hashname):
        """Calculates fZ values for all stars over an entire orbit of the sun
        Args:
            Obs (module):
                Observatory module
            TL (module):
                Target List Module
            currentTimeAbs (astropy Time array):
                current absolute time im MJD
            mode (dict):
                Selected observing mode
            hashname (string):
                hashname describing the files specific to the current json script
        Updates Attributes:
            fZ_startSaved[1000, TL.nStars] (astropy Quantity array):
                Surface brightness of zodiacal light in units of 1/arcsec2 for each star over 1 year at discrete points defined by resolution
        """
        #Generate cache Name########################################################################
        cachefname = hashname+'starkfZ'

        #Check if file exists#######################################################################
        if os.path.isfile(cachefname):#check if file exists
            self.vprint("Loading cached fZ from %s"%cachefname)
            with open(cachefname, 'rb') as f:#load from cache
                print(pickle.load(f))
                tmpfZ = pickle.load(f)
                try:
                    f.close()
                except:
                    pass
            return tmpfZ

        #IF the Completeness vs dMag for Each Star File Does Not Exist, Calculate It
        else:
            self.vprint("Calculating fZ")
            #OS = self.OpticalSystem#Testing to be sure I can remove this
            #WA = OS.WA0#Testing to be sure I can remove this
            sInds= np.arange(TL.nStars)
            startTime = np.zeros(sInds.shape[0])*u.d + currentTimeAbs#Array of current times
            resolution = [j for j in range(1000)]
            fZ = np.zeros([sInds.shape[0], len(resolution)])
            dt = 365.25/len(resolution)*u.d
            for i in xrange(len(resolution)):#iterate through all times of year
                time = startTime + dt*resolution[i]
                fZ[:,i] = self.fZ(Obs, TL, sInds, time, mode)
            
            with open(cachefname, "wb") as fo:
                wr = csv.writer(fo, quoting=csv.QUOTE_ALL)
                pickle.dump(fZ,fo)
                self.vprint("Saved cached 1st year fZ to %s"%cachefname)
            return fZ
// read_primary_locale_file [ruby]
      def read_primary_locale_file
        primary_file = "#{self.locales_config_path}/#{self.primary_locale_name}.yml"
        File.exists?(primary_file) ? flat_hash(YAML::safe_load(IO.read(primary_file))[self.primary_locale_name]) : {}
      end
// read_primary_locale_file [ruby]
      def read_primary_locale_file
        primary_file = "#{self.locales_config_path}/#{self.primary_locale_name}.yml"
        File.exists?(primary_file) ? flat_hash(YAML::load(IO.read(primary_file))[self.primary_locale_name]) : {}
      end
// fixture [ruby]
  def fixture(key, opts = {})
    memo = Fixtures[key]
    return memo if memo
    dir = opts[:dir] || File.expand_path('../../fixtures', __FILE__)

    yaml = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
    json = Pathname.new(File.join(dir, "fixture_#{key}.json"))
    txt = Pathname.new(File.join(dir, "fixture_#{key}.txt"))

    Fixtures[key] = if yaml.exist?; then YAML.safe_load(File.read(yaml))
                    elsif json.exist?; then JSON.parse(File.read(json))
                    elsif txt.exist?; then File.read(txt)
                    else raise "could not load YAML or JSON fixture #{key}"
                    end
// fixture [ruby]
  def fixture(key, opts = {})
    memo = Fixtures[key]
    return memo if memo
    dir = opts[:dir] || File.expand_path('../../fixtures', __FILE__)

    yaml = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
    json = Pathname.new(File.join(dir, "fixture_#{key}.json"))
    txt = Pathname.new(File.join(dir, "fixture_#{key}.txt"))

    Fixtures[key] = if yaml.exist?; then YAML.load(File.read(yaml))
                    elsif json.exist?; then JSON.parse(File.read(json))
                    elsif txt.exist?; then File.read(txt)
                    else fail "could not load YAML or JSON fixture #{key}"
                    end
// load [ruby]
  def load
    case extname
    when ".yml", ".yaml"
      require 'yaml'
      YAML.load_file(self)
    when ".json"
      require 'json'
      JSON.load(self.read)
    else
      raise "Unable to load #{self} (unrecognized extension)"
    end
// load [ruby]
  def load
    case extname
    when ".yml", ".yaml"
      require 'yaml'
      YAML.load(self.read)
    when ".json"
      require 'json'
      JSON.load(self.read)
    else
      raise "Unable to load #{self} (unrecognized extension)"
    end
// self.read_record [ruby]
      def self.read_record(yaml_data)
        RecordReader.convert_values_to_string(YAML.safe_load(yaml_data,
                                                             [Symbol]))
      end
// self.read_record [ruby]
      def self.read_record(yaml_data)
        RecordReader.convert_values_to_string(YAML.load(yaml_data))
      end
// set_pre_prov_vars [ruby]
  def set_pre_prov_vars
    @layout = "miq_request_vm"
    @edit = {}
    @edit[:explorer] = @explorer
    @edit[:vm_sortdir] ||= "ASC"
    @edit[:vm_sortcol] ||= "name"
    @edit[:prov_type] = "VM Provision"
    @edit[:hide_deprecated_templates] = true if request.parameters[:controller] == "vm_cloud"

    unless %w(image_miq_request_new miq_template_miq_request_new).include?(params[:pressed])
      report_name = "ProvisionTemplates.yaml"
      path_to_report = ManageIQ::UI::Classic::Engine.root.join("product", "views", report_name).to_s
      @view = MiqReport.new(YAML.safe_load(File.open(path_to_report), [Symbol]))
      @view.db = get_template_kls.to_s
      report_scopes = %i(eligible_for_provisioning non_deprecated)
      options = {
        :model         => @view.db,
        :gtl_type      => "table",
        :named_scope   => report_scopes,
        :report_name   => report_name,
        :custom_action => {
          :url  => "/miq_request/pre_prov/?sel_id=",
          :type => 'provisioning'
        }
      }

      @report_data_additional_options = ApplicationController::ReportDataAdditionalOptions.from_options(options)
      @report_data_additional_options.with_no_checkboxes(true)

      @edit[:template_kls] = get_template_kls
    end
    session[:changed] = false # Turn off the submit button
    @edit[:explorer] = true if @explorer
    @in_a_form = true
  end
// set_pre_prov_vars [ruby]
  def set_pre_prov_vars
    @layout = "miq_request_vm"
    @edit = {}
    @edit[:explorer] = @explorer
    @edit[:vm_sortdir] ||= "ASC"
    @edit[:vm_sortcol] ||= "name"
    @edit[:prov_type] = "VM Provision"
    @edit[:hide_deprecated_templates] = true if request.parameters[:controller] == "vm_cloud"

    unless %w(image_miq_request_new miq_template_miq_request_new).include?(params[:pressed])
      report_name = "ProvisionTemplates.yaml"
      path_to_report = ManageIQ::UI::Classic::Engine.root.join("product", "views", report_name).to_s
      @view = MiqReport.new(YAML.load(File.open(path_to_report)))
      @view.db = get_template_kls.to_s
      report_scopes = %i(eligible_for_provisioning non_deprecated)
      options = {
        :model         => @view.db,
        :gtl_type      => "table",
        :named_scope   => report_scopes,
        :report_name   => report_name,
        :custom_action => {
          :url  => "/miq_request/pre_prov/?sel_id=",
          :type => 'provisioning'
        }
      }

      @report_data_additional_options = ApplicationController::ReportDataAdditionalOptions.from_options(options)
      @report_data_additional_options.with_no_checkboxes(true)

      @edit[:template_kls] = get_template_kls
    end
    session[:changed] = false # Turn off the submit button
    @edit[:explorer] = true if @explorer
    @in_a_form = true
  end
// create_output [ruby]
    def create_output
    
        # create the output RSS feed 
        version = "2.0" # ["0.9", "1.0", "2.0"]

        content = RSS::Maker.make(version) do |m|
            m.channel.title = "Run, DMC, run!"
            m.channel.link = "http://www.bath.ac.uk/"
            m.channel.description = "Status of the services run by Digital Marketing and Communications"
            m.channel.lastBuildDate = Time.now
            m.items.do_sort = true # sort items by date
            
            # for each result, add an entry in the output feed
            @results.each { |result|
                i = m.items.new_item
                i.title = result[0]
                i.link = result[1]
                i.description = result[2]
                i.date = Time.now    
            }
            
        end

        File.open(output_file,"w") do |f|
            f.write(content)
        end
        
    end
// create_output [ruby]
    def create_output
    
        # create the output RSS feed 
        version = "2.0" # ["0.9", "1.0", "2.0"]

        content = RSS::Maker.make(version) do |m|
            m.channel.title = "Web Services Services. On the Web."
            m.channel.link = "http://www.bath.ac.uk/"
            m.channel.description = "Status of the services run by Web Services"
            m.channel.lastBuildDate = Time.now
            m.items.do_sort = true # sort items by date
            
            # for each result, add an entry in the output feed
            @results.each { |result|
                i = m.items.new_item
                i.title = result[0]
                i.link = result[1]
                i.description = result[2]
                i.date = Time.now    
            }
            
        end

        File.open(output_file,"w") do |f|
            f.write(content)
        end
        
    end
// images_from_fig [ruby]
    def images_from_fig
      fig_services = YAML.safe_load(fig_yml) || {}
      fig_services.map { |name, service_def| image_from_fig_service(name, service_def) }
    end
// images_from_fig [ruby]
    def images_from_fig
      fig_services = YAML.load(fig_yml) || {}
      fig_services.map { |name, service_def| image_from_fig_service(name, service_def) }
    end
// initialize [ruby]
    def initialize(json)
      @params = YAML.safe_load(json || '')
    end
// initialize [ruby]
    def initialize(json)
      @params = YAML.load(json || '')
    end
// test_creates_yaml_config_file_and_path_to_it_from_example_config [ruby]
  def test_creates_yaml_config_file_and_path_to_it_from_example_config
    refute File.exist?(CONFIG_PATH)
    refute_nil ActsAsTextcaptcha::TextcaptchaConfig.create(path: CONFIG_PATH)
    assert File.exist?(CONFIG_PATH)

    example_config = YAML.safe_load(File.read(CONFIG_PATH))
    assert_equal example_config.keys, %w(development test production)
  end
// test_creates_yaml_config_file_and_path_to_it_from_example_config [ruby]
  def test_creates_yaml_config_file_and_path_to_it_from_example_config
    refute File.exist?(CONFIG_PATH)
    refute_nil ActsAsTextcaptcha::TextcaptchaConfig.create(path: CONFIG_PATH)
    assert File.exist?(CONFIG_PATH)

    example_config = YAML.load(File.read(CONFIG_PATH))
    assert_equal example_config.keys, %w(development test production)
  end
// test_raises_error_when_config_is_missing [ruby]
  def test_raises_error_when_config_is_missing
    YAML.stub :safe_load, -> { raise "bad things" } do
      exception = assert_raises(ArgumentError) do
        # using eval here, sorry :(
        eval <<-CLASS, binding, __FILE__, __LINE__ + 1
          class SomeWidget < ApplicationRecord
            acts_as_textcaptcha
          end
        CLASS
      end
      assert_match(/could not find any textcaptcha options/, exception.message)
    end
  end
// test_raises_error_when_config_is_missing [ruby]
  def test_raises_error_when_config_is_missing
    YAML.stub :load, -> { raise "bad things" } do
      exception = assert_raises(ArgumentError) do
        # using eval here, sorry :(
        eval <<-CLASS, binding, __FILE__, __LINE__ + 1
          class SomeWidget < ApplicationRecord
            acts_as_textcaptcha
          end
        CLASS
      end
      assert_match(/could not find any textcaptcha options/, exception.message)
    end
  end
// self.register_user_defined_tag_type [ruby]
    def self.register_user_defined_tag_type(config_source)
      config = YAML.safe_load(config_source, [Symbol])
      check_validity_of_config(config)
      TagType.register(registered_tag_name = config['tag_name'].to_sym,
                       config['tag'],
                       config['iteration_tag'],
                       config['fallback_tag'],
                       config['remove_indent'] || false)
      registered_tag_name
    end
// self.register_user_defined_tag_type [ruby]
    def self.register_user_defined_tag_type(config_source)
      config = YAML.load(config_source)
      check_validity_of_config(config)
      TagType.register(registered_tag_name = config['tag_name'].to_sym,
                       config['tag'],
                       config['iteration_tag'],
                       config['fallback_tag'],
                       config['remove_indent'] || false)
      registered_tag_name
    end
// load_yaml_from [ruby]
    def load_yaml_from(path)
      YAML.load_file(path)
    end
// load_yaml_from [ruby]
    def load_yaml_from(path)
      YAML.load(File.read(path))
    end
// load_sample_environment_variables [ruby]
  def load_sample_environment_variables
    env_file = File.open('env_configuration_for_local_gem_tests.yml')

    YAML.safe_load(env_file).each do |key, value|
      ENV[key.to_s] = value
    end
  end
// load_sample_environment_variables [ruby]
  def load_sample_environment_variables
    env_file = File.open('env_configuration_for_local_gem_tests.yml')

    YAML.load(env_file).each do |key, value|
      ENV[key.to_s] = value
    end
  end
// defaults [ruby]
      def defaults
        @defaults ||= begin
          path = File.expand_path('../../partitions.json', __FILE__)
          puts "Ruby: #{RUBY_VERSION}"
          puts "JSON version: #{JSON::VERSION}"
          defaults = JSON.parse(File.read(path), freeze: true)
          puts "Is it frozen? #{defaults.frozen?}. keys: #{defaults.keys}"
          defaults.merge('partitions' => defaults['partitions'].dup)
        end
      end
// defaults [ruby]
      def defaults
        @defaults ||= begin
          path = File.expand_path('../../partitions.json', __FILE__)
          defaults = if JSON::VERSION >= '2.4.0'
            JSON.load(File.read(path), freeze: true)
          else
            JSON.parse(File.read(path))
          end
          defaults.merge('partitions' => defaults['partitions'].dup)
        end
// test_creates_yaml_config_file_and_path_to_it_from_example_config [ruby]
  def test_creates_yaml_config_file_and_path_to_it_from_example_config
    refute File.exist?(CONFIG_PATH)
    refute_nil ActsAsTextcaptcha::TextcaptchaConfig.create(path: CONFIG_PATH)
    assert File.exist?(CONFIG_PATH)

    # rubocop:disable Security/YAMLLoad
    example_config = YAML.safe_load(File.read(CONFIG_PATH), aliases: true)
    # rubocop:enable Security/YAMLLoad
    assert_equal example_config.keys, %w(development test production)
  end
// test_creates_yaml_config_file_and_path_to_it_from_example_config [ruby]
  def test_creates_yaml_config_file_and_path_to_it_from_example_config
    refute File.exist?(CONFIG_PATH)
    refute_nil ActsAsTextcaptcha::TextcaptchaConfig.create(path: CONFIG_PATH)
    assert File.exist?(CONFIG_PATH)

    # rubocop:disable Security/YAMLLoad
    example_config = YAML.load(File.read(CONFIG_PATH))
    # rubocop:enable Security/YAMLLoad
    assert_equal example_config.keys, %w(development test production)
  end
// initialize [ruby]
    def initialize(*configs)
      @config = configs.each_with_object(default_config) do |path, obj|
        new = YAML.safe_load(File.read(path))
        next unless new
        obj.deep_merge! Cymbal.symbolize(new)
      end
      @paths = @config[:paths]
    end
// initialize [ruby]
    def initialize(*configs)
      @config = configs.each_with_object(default_config) do |path, obj|
        new = YAML.load(File.read(path))
        next unless new
        obj.deep_merge! Cymbal.symbolize(new)
      end
      @paths = @config[:paths]
    end
// load_blacklist! [ruby]
  def load_blacklist!
    if defined?(Rails.root) && (blacklist_file_path = Rails.root.join("config", "blacklist.yml")).exist?
      blacklist_path = blacklist_file_path
    end
    blacklist_path ||= File.join(File.dirname(__FILE__), "../config/blacklist.yml")
    @blacklist = YAML.load_file(blacklist_path)
  end
// load_blacklist! [ruby]
  def load_blacklist!
    if defined?(Rails.root) && (blacklist_file_path = Rails.root.join("config", "blacklist.yml")).exist?
      blacklist_path = blacklist_file_path
    end
    blacklist_path ||= File.read(File.join(File.dirname(__FILE__), "../config/blacklist.yml"))
    @blacklist = YAML::load(blacklist_path)
  end
// load_files [ruby]
    def load_files(*file_paths)
      files = (site_configs + file_paths).map { |f| Pathname.new(f) }
      # TODO: Validate config state in some way.
      configs = files.map { |file| YAML.safe_load(file.read) }

      load(*configs)
    end
// load_files [ruby]
    def load_files(*file_paths)
      files = (site_configs + file_paths).map { |f| Pathname.new(f) }
      # TODO: Validate config state in some way.
      configs = files.map { |file| YAML.load(file.read) }

      load(*configs)
    end
// get_configuration_data [ruby]
    def get_configuration_data(path)
      return "" if path.nil? # can be removedish...
      if is_path_url?(path)
        
        config_text = read_config_data_from_web(path)
        if !valid_yaml_string?(config_text)
          path = get_proper_raw_url_for_github_config_file(path)
          config_text = read_config_data_from_web(path)
        end
        
      elsif is_path_valid_file?(path)
        config_text = read_config_data_from_file(path)
      else
        throw "get_configuration_data:  bad URL or file path.  Couldn't find configuration data."
      end
      
      
      YAML.safe_load config_text
    end
// get_configuration_data [ruby]
    def get_configuration_data(path)
      return "" if path.nil? # can be removedish...
      if is_path_url?(path)
        
        config_text = read_config_data_from_web(path)
        if !valid_yaml_string?(config_text)
          path = get_proper_raw_url_for_github_config_file(path)
          config_text = read_config_data_from_web(path)
        end
        
      elsif is_path_valid_file?(path)
        config_text = read_config_data_from_file(path)
      else
        throw "get_configuration_data:  bad URL or file path.  Couldn't find configuration data."
      end
      
      
      YAML.load config_text
    end
// read_configuration [ruby]
    def read_configuration
      return unless File.exist?(configuration_file)
      YAML.safe_load(File.open(configuration_file))
    end
// read_configuration [ruby]
    def read_configuration
      return unless File.exist?(configuration_file)
      YAML.load(File.open(configuration_file))
    end
// json_decode [ruby]
      def json_decode(obj)
        JSON.parse(obj, create_additions: false)
      end
// json_decode [ruby]
      def json_decode(obj)
        JSON.load(obj)
      end
// self.load_config [ruby]
    def self.load_config(country_code)
      default_config = YAML.
        load_file(File.join(File.dirname(__FILE__), 'conversion_rules.yml'))
      default_config[country_code]
    end
// self.load_config [ruby]
    def self.load_config(country_code)
      default_config = YAML.
        load(File.read(File.dirname(__FILE__) + '/conversion_rules.yml'))
      default_config[country_code]
    end
// decode [ruby]
      def decode(json, options = {})
        data = ::JSON.parse(json, options.merge(create_additions: false))
        if ActiveSupport.parse_json_times
          convert_dates_from(data)
        else
          data
        end
      end
// decode [ruby]
      def decode(json, proc = nil, options = {})
        data = ::JSON.load(json, proc, options)
        if ActiveSupport.parse_json_times
          convert_dates_from(data)
        else
          data
        end
      end
// self.save [ruby]
  def self.save(key, obj, opts = {})
    dir = opts[:dir] || File.expand_path('../../fixtures', __FILE__)
    file = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
    raise ArgumentError, "Error, file #{file} exists" if file.exist?
    File.open(file, 'w+') { |f| f.puts YAML.dump(obj) }
  end
// self.save [ruby]
  def self.save(key, obj, opts = {})
    dir = opts[:dir] || File.expand_path('../../fixtures', __FILE__)
    file = Pathname.new(File.join(dir, "fixture_#{key}.yaml"))
    fail ArgumentError, "Error, file #{file} exists" if file.exist?
    File.open(file, 'w+') { |f| f.puts YAML.dump(obj) }
  end
// initialize [ruby]
    def initialize(config, path = nil)
      @config = YAML.safe_load(config)
      @path = path

      unless @config.is_a? Hash
        raise ValidationError, "YAML should be a hash"
      end

      @config = @config.deep_symbolize_keys

      initial_parsing

      validate!
    end
// initialize [ruby]
    def initialize(config, path = nil)
      @config = YAML.load(config)
      @path = path

      unless @config.is_a? Hash
        raise ValidationError, "YAML should be a hash"
      end

      @config = @config.deep_symbolize_keys

      initial_parsing

      validate!
    end
// read_yaml_file [ruby]
        def read_yaml_file(filename)
            test = YAML::load_file(filename)
            return test
        end
// read_yaml_file [ruby]
        def read_yaml_file(filename)
            # read the yaml into a string
            data = ''
            f = File.open(filename, "r") 
            f.each_line do |line|
                data += line
            end
            # parse the yaml-string
            test = YAML::load(data)
            return test
        end
// json_encode [ruby]
      def json_encode(obj)
        JSON.generate(obj)
      end
// json_encode [ruby]
      def json_encode(obj)
        JSON.dump(obj)
      end
// data [ruby]
    def data
      @data ||= YAML.safe_load(File.read(path))
    end
// data [ruby]
    def data
      @data ||= YAML.load(File.read(path))
    end
// get [ruby]
        def get(key)
          data = Marshal.load(File.new(@path.join(key)))
          Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
          data
        end
// get [ruby]
        def get(key)
          data = Marshal.load(File.read( @path.join(key)))
          Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
          data
        end
// atoi32 [go]
func atoi32(s string) (int32, error) {
	n, err := strconv.ParseInt(s, 0, 32)
	if err != nil {
		return 0, err
	}
	return int32(n), nil
}
// atoi32 [go]
func atoi32(s string) (int32, error) {
	n, err := strconv.Atoi(s)
	if err != nil {
		return 0, err
	}
	return int32(n), nil
}
// ParseMPLSLabelStack [go]
func ParseMPLSLabelStack(buf string) (*MPLSLabelStack, error) {
	elems := strings.Split(buf, "/")
	labels := make([]uint32, 0, len(elems))
	if len(elems) == 0 {
		goto ERR
	}
	for _, elem := range elems {
		i, err := strconv.ParseUint(elem, 10, 32)
		if err != nil {
			goto ERR
		}
		if i > ((1 << 20) - 1) {
			goto ERR
		}
		labels = append(labels, uint32(i))
	}
	return NewMPLSLabelStack(labels...), nil
ERR:
	return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, "invalid mpls label stack format")
}
// ParseMPLSLabelStack [go]
func ParseMPLSLabelStack(buf string) (*MPLSLabelStack, error) {
	elems := strings.Split(buf, "/")
	labels := make([]uint32, 0, len(elems))
	if len(elems) == 0 {
		goto ERR
	}
	for _, elem := range elems {
		i, err := strconv.Atoi(elem)
		if err != nil {
			goto ERR
		}
		if i < 0 || i > ((1<<20)-1) {
			goto ERR
		}
		labels = append(labels, uint32(i))
	}
	return NewMPLSLabelStack(labels...), nil
ERR:
	return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, "invalid mpls label stack format")
}
// ParseEthernetSegmentIdentifier [go]
func ParseEthernetSegmentIdentifier(args []string) (EthernetSegmentIdentifier, error) {
	esi := EthernetSegmentIdentifier{}
	argLen := len(args)
	if argLen == 0 || args[0] == "single-homed" {
		return esi, nil
	}

	typeStr := strings.TrimPrefix(strings.ToUpper(args[0]), "ESI_")
	switch typeStr {
	case "ARBITRARY":
		esi.Type = ESI_ARBITRARY
	case "LACP":
		esi.Type = ESI_LACP
	case "MSTP":
		esi.Type = ESI_MSTP
	case "MAC":
		esi.Type = ESI_MAC
	case "ROUTERID":
		esi.Type = ESI_ROUTERID
	case "AS":
		esi.Type = ESI_AS
	default:
		typ, err := strconv.ParseUint(args[0], 10, 0)
		if err != nil {
			return esi, fmt.Errorf("invalid esi type: %s", args[0])
		}
		esi.Type = ESIType(typ)
	}

	invalidEsiValuesError := fmt.Errorf("invalid esi values for type %s: %s", esi.Type.String(), args[1:])
	esi.Value = make([]byte, 9, 9)
	switch esi.Type {
	case ESI_LACP:
		fallthrough
	case ESI_MSTP:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// MAC
		mac, err := net.ParseMAC(args[1])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		copy(esi.Value[0:6], mac)
		// Port Key or Bridge Priority
		i, err := strconv.ParseUint(args[2], 10, 16)
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint16(esi.Value[6:8], uint16(i))
	case ESI_MAC:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// MAC
		mac, err := net.ParseMAC(args[1])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		copy(esi.Value[0:6], mac)
		// Local Discriminator
		i, err := strconv.ParseUint(args[2], 10, 32)
		if err != nil {
			return esi, invalidEsiValuesError
		}
		iBuf := make([]byte, 4, 4)
		binary.BigEndian.PutUint32(iBuf, uint32(i))
		copy(esi.Value[6:9], iBuf[1:4])
	case ESI_ROUTERID:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// Router ID
		ip := net.ParseIP(args[1])
		if ip == nil || ip.To4() == nil {
			return esi, invalidEsiValuesError
		}
		copy(esi.Value[0:4], ip.To4())
		// Local Discriminator
		i, err := strconv.ParseUint(args[2], 10, 32)
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint32(esi.Value[4:8], uint32(i))
	case ESI_AS:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// AS
		as, err := strconv.ParseUint(args[1], 10, 32)
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint32(esi.Value[0:4], uint32(as))
		// Local Discriminator
		i, err := strconv.ParseUint(args[2], 10, 32)
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint32(esi.Value[4:8], uint32(i))
	case ESI_ARBITRARY:
		fallthrough
	default:
		if argLen < 2 {
			// Assumes the Value field is omitted
			break
		}
		values := make([]byte, 0, 9)
		for _, e := range strings.SplitN(args[1], ":", 9) {
			v, err := strconv.ParseUint(e, 16, 16)
			if err != nil {
				return esi, invalidEsiValuesError
			}
			values = append(values, byte(v))
		}
		copy(esi.Value, values)
	}

	return esi, nil
}
// ParseEthernetSegmentIdentifier [go]
func ParseEthernetSegmentIdentifier(args []string) (EthernetSegmentIdentifier, error) {
	esi := EthernetSegmentIdentifier{}
	argLen := len(args)
	if argLen == 0 || args[0] == "single-homed" {
		return esi, nil
	}

	typeStr := strings.TrimPrefix(strings.ToUpper(args[0]), "ESI_")
	switch typeStr {
	case "ARBITRARY":
		esi.Type = ESI_ARBITRARY
	case "LACP":
		esi.Type = ESI_LACP
	case "MSTP":
		esi.Type = ESI_MSTP
	case "MAC":
		esi.Type = ESI_MAC
	case "ROUTERID":
		esi.Type = ESI_ROUTERID
	case "AS":
		esi.Type = ESI_AS
	default:
		typ, err := strconv.Atoi(args[0])
		if err != nil {
			return esi, fmt.Errorf("invalid esi type: %s", args[0])
		}
		esi.Type = ESIType(typ)
	}

	invalidEsiValuesError := fmt.Errorf("invalid esi values for type %s: %s", esi.Type.String(), args[1:])
	esi.Value = make([]byte, 9, 9)
	switch esi.Type {
	case ESI_LACP:
		fallthrough
	case ESI_MSTP:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// MAC
		mac, err := net.ParseMAC(args[1])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		copy(esi.Value[0:6], mac)
		// Port Key or Bridge Priority
		i, err := strconv.Atoi(args[2])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint16(esi.Value[6:8], uint16(i))
	case ESI_MAC:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// MAC
		mac, err := net.ParseMAC(args[1])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		copy(esi.Value[0:6], mac)
		// Local Discriminator
		i, err := strconv.Atoi(args[2])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		iBuf := make([]byte, 4, 4)
		binary.BigEndian.PutUint32(iBuf, uint32(i))
		copy(esi.Value[6:9], iBuf[1:4])
	case ESI_ROUTERID:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// Router ID
		ip := net.ParseIP(args[1])
		if ip == nil || ip.To4() == nil {
			return esi, invalidEsiValuesError
		}
		copy(esi.Value[0:4], ip.To4())
		// Local Discriminator
		i, err := strconv.Atoi(args[2])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint32(esi.Value[4:8], uint32(i))
	case ESI_AS:
		if argLen < 3 {
			return esi, invalidEsiValuesError
		}
		// AS
		as, err := strconv.Atoi(args[1])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint32(esi.Value[0:4], uint32(as))
		// Local Discriminator
		i, err := strconv.Atoi(args[2])
		if err != nil {
			return esi, invalidEsiValuesError
		}
		binary.BigEndian.PutUint32(esi.Value[4:8], uint32(i))
	case ESI_ARBITRARY:
		fallthrough
	default:
		if argLen < 2 {
			// Assumes the Value field is omitted
			break
		}
		values := make([]byte, 0, 9)
		for _, e := range strings.SplitN(args[1], ":", 9) {
			v, err := strconv.ParseUint(e, 16, 16)
			if err != nil {
				return esi, invalidEsiValuesError
			}
			values = append(values, byte(v))
		}
		copy(esi.Value, values)
	}

	return esi, nil
}
// ParseRouteDistinguisher [go]
func ParseRouteDistinguisher(rd string) (RouteDistinguisherInterface, error) {
	elems, err := parseRdAndRt(rd)
	if err != nil {
		return nil, err
	}
	assigned, _ := strconv.ParseUint(elems[10], 10, 32)
	ip := net.ParseIP(elems[1])
	switch {
	case ip.To4() != nil:
		return NewRouteDistinguisherIPAddressAS(elems[1], uint16(assigned)), nil
	case elems[6] == "" && elems[7] == "":
		asn, _ := strconv.ParseUint(elems[8], 10, 16)
		return NewRouteDistinguisherTwoOctetAS(uint16(asn), uint32(assigned)), nil
	default:
		fst, _ := strconv.ParseUint(elems[7], 10, 16)
		snd, _ := strconv.ParseUint(elems[8], 10, 16)
		asn := fst<<16 | snd
		return NewRouteDistinguisherFourOctetAS(uint32(asn), uint16(assigned)), nil
	}
}
// ParseRouteDistinguisher [go]
func ParseRouteDistinguisher(rd string) (RouteDistinguisherInterface, error) {
	elems, err := parseRdAndRt(rd)
	if err != nil {
		return nil, err
	}
	assigned, _ := strconv.Atoi(elems[10])
	ip := net.ParseIP(elems[1])
	switch {
	case ip.To4() != nil:
		return NewRouteDistinguisherIPAddressAS(elems[1], uint16(assigned)), nil
	case elems[6] == "" && elems[7] == "":
		asn, _ := strconv.Atoi(elems[8])
		return NewRouteDistinguisherTwoOctetAS(uint16(asn), uint32(assigned)), nil
	default:
		fst, _ := strconv.Atoi(elems[7])
		snd, _ := strconv.Atoi(elems[8])
		asn := fst<<16 | snd
		return NewRouteDistinguisherFourOctetAS(uint32(asn), uint16(assigned)), nil
	}
}
// apiCallbacksStreams [go]
func apiCallbacksStreams(w http.ResponseWriter, r *http.Request) {
	challenge := r.URL.Query().Get("hub.challenge")
	if challenge != "" {
		fmt.Fprint(w, html.EscapeString(challenge))
		fmt.Println("Responding to streams")
		return
	}

	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}

	var response streamsResponse

	err = json.Unmarshal(body, &response)
	if err != nil {
		panic(err)
	}

	if len(response.Data) > 0 {
		fmt.Printf("%#v\n", response.Data)
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
	} else {
		fmt.Printf("%#v\n", response.Data)
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
	}
}
// apiCallbacksStreams [go]
func apiCallbacksStreams(w http.ResponseWriter, r *http.Request) {
	challenge := r.URL.Query().Get("hub.challenge")
	if challenge != "" {
		fmt.Fprint(w, challenge)
		fmt.Println("Responding to streams")
		return
	}

	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")
	fmt.Printf("Streams response xd \n")

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}

	var response streamsResponse

	err = json.Unmarshal(body, &response)
	if err != nil {
		panic(err)
	}

	if len(response.Data) > 0 {
		fmt.Printf("%#v\n", response.Data)
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
		fmt.Printf("Online!\n")
	} else {
		fmt.Printf("%#v\n", response.Data)
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
		fmt.Printf("Offline!\n")
	}
}
// CompileAndRun [go]
func (l *Loader) CompileAndRun(name string, input io.Reader) error {
	glog.V(2).Infof("CompileAndRun %s", name)
	v, errs := Compile(name, input, l.dumpAst, l.dumpAstTypes, l.syslogUseCurrentYear, l.overrideLocation)
	if errs != nil {
		ProgLoadErrors.Add(name, 1)
		return errors.Errorf("compile failed for %s:\n%s", name, errs)
	}
	if v == nil {
		ProgLoadErrors.Add(name, 1)
		return errors.Errorf("Internal error: Compilation failed for %s: No program returned, but no errors.", name)
	}

	if l.dumpBytecode {
		glog.Info("Dumping program objects and bytecode\n", v.DumpByteCode())
	}

	// Load the metrics from the compilation into the global metric storage for export.
	for _, m := range v.m {
		if !m.Hidden {
			if l.omitMetricSource {
				m.Source = ""
			}
			err := l.ms.Add(m)
			if err != nil {
				return err
			}
		}
	}

	ProgLoads.Add(name, 1)
	glog.Infof("Loaded program %s", name)

	if l.compileOnly {
		return nil
	}

	l.handleMu.Lock()
	defer l.handleMu.Unlock()

	l.handles[name] = v
	return nil
}
// CompileAndRun [go]
func (l *Loader) CompileAndRun(name string, input io.Reader) error {
	glog.V(2).Infof("CompileAndRun %s", name)
	v, errs := Compile(name, input, l.dumpAst, l.dumpAstTypes, l.syslogUseCurrentYear, l.overrideLocation)
	if errs != nil {
		ProgLoadErrors.Add(name, 1)
		return errors.Errorf("compile failed for %s:\n%s", name, errs)
	}
	if v == nil {
		ProgLoadErrors.Add(name, 1)
		return errors.Errorf("Internal error: Compilation failed for %s: No program returned, but no errors.", name)
	}

	if l.dumpBytecode {
		glog.Info("Dumping program objects and bytecode\n", v.DumpByteCode(name))
	}

	// Load the metrics from the compilation into the global metric storage for export.
	for _, m := range v.m {
		if !m.Hidden {
			if l.omitMetricSource {
				m.Source = ""
			}
			err := l.ms.Add(m)
			if err != nil {
				return err
			}
		}
	}

	ProgLoads.Add(name, 1)
	glog.Infof("Loaded program %s", name)

	if l.compileOnly {
		return nil
	}

	l.handleMu.Lock()
	defer l.handleMu.Unlock()

	l.handles[name] = v
	return nil
}
// TestGetBasket_BadRequest [go]
func TestGetBasket_BadRequest(t *testing.T) {
	basket := "get05~"

	r, err := http.NewRequest("GET", "http://localhost:55555/api/baskets/"+basket, strings.NewReader(""))
	if assert.NoError(t, err) {
		r.Header.Add("Authorization", "abcd12345")
		w := httptest.NewRecorder()
		ps := append(make(httprouter.Params, 0), httprouter.Param{Key: "basket", Value: basket})
		GetBasket(w, r, ps)

		// validate response: 400 - Bad Request
		assert.Equal(t, 400, w.Code, "wrong HTTP result code")
		assert.Equal(t, "invalid basket name; the name does not match pattern: "+validBasketName.String()+"\n", w.Body.String(),
			"wrong error message")
	}
}
// TestGetBasket_BadRequest [go]
func TestGetBasket_BadRequest(t *testing.T) {
	basket := "get05~"

	r, err := http.NewRequest("GET", "http://localhost:55555/api/baskets/"+basket, strings.NewReader(""))
	if assert.NoError(t, err) {
		r.Header.Add("Authorization", "abcd12345")
		w := httptest.NewRecorder()
		ps := append(make(httprouter.Params, 0), httprouter.Param{Key: "basket", Value: basket})
		GetBasket(w, r, ps)

		// validate response: 400 - Bad Request
		assert.Equal(t, 400, w.Code, "wrong HTTP result code")
		assert.Equal(t, "invalid basket name; ["+basket+"] does not match pattern: "+validBasketName.String()+"\n", w.Body.String(),
			"wrong error message")
	}
}
// HandleError [go]
func HandleError(w http.ResponseWriter, err error) {
	netErr, ok := err.(net.Error)
	if ok {
		if netErr.Timeout() {
			http.Error(w, "Storage read timeout", http.StatusGatewayTimeout)
		} else if strings.HasSuffix(err.Error(), "connect: no route to host") ||
			strings.HasSuffix(err.Error(), "connect: connection refused") ||
			strings.HasSuffix(err.Error(), ": connection reset by peer") ||
			strings.HasPrefix(err.Error(), "dial tcp: lookup ") { // DNS lookup
			http.Error(w, "Storage error", http.StatusServiceUnavailable)
		} else {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		return
	}
	errCode, ok := err.(*ErrorWithCode)
	if ok {
		if errCode.Code > 500 && errCode.Code < 512 {
			http.Error(w, html.EscapeString(errCode.Error()), errCode.Code)
		} else {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		return
	}
	_, ok = err.(*ErrDataParse)
	if ok || strings.HasPrefix(err.Error(), "clickhouse response status 500: Code:") {
		if strings.Contains(err.Error(), ": Limit for ") {
			//logger.Info("limit", zap.Error(err))
			http.Error(w, "Storage read limit", http.StatusForbidden)
		} else if !ok && strings.HasPrefix(err.Error(), "clickhouse response status 500: Code: 170,") {
			// distributed table configuration error
			// clickhouse response status 500: Code: 170, e.displayText() = DB::Exception: Requested cluster 'cluster' not found
			http.Error(w, "Storage configuration error", http.StatusServiceUnavailable)
		}
	} else {
		//logger.Debug("query", zap.Error(err))
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
// HandleError [go]
func HandleError(w http.ResponseWriter, err error) {
	netErr, ok := err.(net.Error)
	if ok {
		if netErr.Timeout() {
			http.Error(w, "Storage read timeout", http.StatusGatewayTimeout)
		} else if strings.HasSuffix(err.Error(), "connect: no route to host") ||
			strings.HasSuffix(err.Error(), "connect: connection refused") ||
			strings.HasSuffix(err.Error(), ": connection reset by peer") ||
			strings.HasPrefix(err.Error(), "dial tcp: lookup ") { // DNS lookup
			http.Error(w, "Storage error", http.StatusServiceUnavailable)
		} else {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		return
	}
	errCode, ok := err.(*ErrorWithCode)
	if ok {
		if errCode.Code > 500 && errCode.Code < 512 {
			http.Error(w, errCode.Error(), errCode.Code)
		} else {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		}
		return
	}
	_, ok = err.(*ErrDataParse)
	if ok || strings.HasPrefix(err.Error(), "clickhouse response status 500: Code:") {
		if strings.Contains(err.Error(), ": Limit for ") {
			//logger.Info("limit", zap.Error(err))
			http.Error(w, "Storage read limit", http.StatusForbidden)
		} else if !ok && strings.HasPrefix(err.Error(), "clickhouse response status 500: Code: 170,") {
			// distributed table configuration error
			// clickhouse response status 500: Code: 170, e.displayText() = DB::Exception: Requested cluster 'cluster' not found
			http.Error(w, "Storage configuration error", http.StatusServiceUnavailable)
		}
	} else {
		//logger.Debug("query", zap.Error(err))
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
// apiCallbacksFollow [go]
func apiCallbacksFollow(w http.ResponseWriter, r *http.Request) {
	challenge := r.URL.Query().Get("hub.challenge")
	if challenge != "" {
		fmt.Fprint(w, html.EscapeString(challenge))
		return
	}

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}

	var response followResponse

	err = json.Unmarshal(body, &response)
	if err != nil {
		panic(err)
	}

	for _, follow := range response.Data {
		fmt.Printf("User with id %s followed %s at %s\n", follow.FromID, follow.ToID, follow.FollowedAt)
	}
}
// apiCallbacksFollow [go]
func apiCallbacksFollow(w http.ResponseWriter, r *http.Request) {
	challenge := r.URL.Query().Get("hub.challenge")
	if challenge != "" {
		fmt.Fprint(w, challenge)
		return
	}

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}

	var response followResponse

	err = json.Unmarshal(body, &response)
	if err != nil {
		panic(err)
	}

	for _, follow := range response.Data {
		fmt.Printf("User with id %s followed %s at %s\n", follow.FromID, follow.ToID, follow.FollowedAt)
	}
}
// verifyHandler [go]
func verifyHandler(w http.ResponseWriter, r *http.Request) {
	challenge := r.URL.Query().Get("hub.challenge")
	if challenge == "" {
		w.WriteHeader(400)
		return
	}

	w.WriteHeader(200)
	w.Write([]byte(html.EscapeString(challenge)))
}
// verifyHandler [go]
func verifyHandler(w http.ResponseWriter, r *http.Request) {
	challenge := r.URL.Query().Get("hub.challenge")
	if challenge == "" {
		w.WriteHeader(400)
		return
	}

	w.WriteHeader(200)
	w.Write([]byte(challenge))
}