<commit_before>require 'rack/session/abstract/id'
require 'dalli'

module Rack
  module Session
    class Dalli < Abstract::ID
      attr_reader :pool

      DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge \
        :namespace => 'rack:session',
        :memcache_server => 'localhost:11211'

      def initialize(app, options={})
        super
        mserv = @default_options[:memcache_server]
        mopts = @default_options.reject{|k,v| !MemCache::DEFAULT_OPTIONS.include? k }
        @pool = options[:cache] || Dalli::Client.new(mserv, mopts)
      end

      def generate_sid
        loop do
          sid = super
          break sid unless @pool.get(sid)
        end
      end

      def get_session(env, sid)
        unless sid and session = @pool.get(sid)
          sid, session = generate_sid, {}
          unless @pool.add(sid, session)
            raise "Session collision on '#{sid.inspect}'"
          end
        end
        [sid, session]
      end

      def set_session(env, session_id, new_session, options)
        expiry = options[:expire_after]
        expiry = expiry.nil? ? 0 : expiry + 1

        @pool.set session_id, new_session, expiry
        session_id
      end

      def destroy_session(env, session_id, options)
        @pool.delete(session_id)
        generate_sid unless options[:drop]
      end

    end
  end
end
<commit_msg>Oops, fix issue with new Rack stuff<commit_after>require 'rack/session/abstract/id'
require 'dalli'

module Rack
  module Session
    class Dalli < Abstract::ID
      attr_reader :pool

      DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge \
        :namespace => 'rack:session',
        :memcache_server => 'localhost:11211'

      def initialize(app, options={})
        super
        mserv = @default_options[:memcache_server]
        mopts = @default_options.reject{|k,v| !DEFAULT_OPTIONS.include? k }
        @pool = options[:cache] || Dalli::Client.new(mserv, mopts)
      end

      def generate_sid
        loop do
          sid = super
          break sid unless @pool.get(sid)
        end
      end

      def get_session(env, sid)
        unless sid and session = @pool.get(sid)
          sid, session = generate_sid, {}
          unless @pool.add(sid, session)
            raise "Session collision on '#{sid.inspect}'"
          end
        end
        [sid, session]
      end

      def set_session(env, session_id, new_session, options)
        expiry = options[:expire_after]
        expiry = expiry.nil? ? 0 : expiry + 1

        @pool.set session_id, new_session, expiry
        session_id
      end

      def destroy_session(env, session_id, options)
        @pool.delete(session_id)
        generate_sid unless options[:drop]
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.09774709302325581, 'fraction_numerical': 0.005087209302325582, 'mean_word_length': 2.2123687281213535, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5416869', 'n_tokens_mistral': 867, 'n_tokens_neox': 818, 'n_words': 206}