<commit_before>module ZK
  # a more ruby-friendly wrapper around the low-level drivers
  #
  class Client
    extend Forwardable

    DEFAULT_TIMEOUT = 10

    attr_reader :event_handler

    attr_reader :cnx #:nodoc:

    # for backwards compatibility
    alias :watcher :event_handler #:nodoc:

    STATE_SYM_MAP = {
      Zookeeper::ZOO_CLOSED_STATE           => :closed,
      Zookeeper::ZOO_EXPIRED_SESSION_STATE  => :expired_session,
      Zookeeper::ZOO_AUTH_FAILED_STATE      => :auth_failed,
      Zookeeper::ZOO_CONNECTING_STATE       => :connecting,
      Zookeeper::ZOO_CONNECTED_STATE        => :connected,
      Zookeeper::ZOO_ASSOCIATING_STATE      => :associating,
    }.freeze

    def initialize(host, opts={})
      @event_handler = EventHandler.new(self)
      @cnx = ::Zookeeper.new(host, DEFAULT_TIMEOUT, get_default_watcher_block)
    end

    def closed?
      defined?(::JRUBY_VERSION) ? jruby_closed? : mri_closed?
    end

    private
      def jruby_closed?
        @cnx.state == Java::OrgApacheZookeeper::ZooKeeper::States::CLOSED
      end

      def mri_closed?
        @cnx.state or false
      rescue RuntimeError => e
        # gah, lame error parsing here
        raise e if (e.message != 'zookeeper handle is closed') and not defined?(::JRUBY_VERSION)
        true
      end

    public
    def state
      if defined?(::JRUBY_VERSION) 
        @cnx.state.to_string.downcase.to_sym
      else
        STATE_SYM_MAP.fetch(@cnx.state) { |k| raise IndexError, "unrecognized state: #{k}" }
      end
    end

    def connected?
      wrap_state_closed_error { @cnx.connected? }
    end

    def associating?
      wrap_state_closed_error { @cnx.associating? }
    end

    def connecting?
      wrap_state_closed_error { @cnx.connecting? }
    end<commit_msg>allow reopen of underlying connection, return state using our mapping-to-symbols<commit_after>module ZK
  # a more ruby-friendly wrapper around the low-level drivers
  #
  class Client
    extend Forwardable

    DEFAULT_TIMEOUT = 10

    attr_reader :event_handler

    attr_reader :cnx #:nodoc:

    # for backwards compatibility
    alias :watcher :event_handler #:nodoc:

    STATE_SYM_MAP = {
      Zookeeper::ZOO_CLOSED_STATE           => :closed,
      Zookeeper::ZOO_EXPIRED_SESSION_STATE  => :expired_session,
      Zookeeper::ZOO_AUTH_FAILED_STATE      => :auth_failed,
      Zookeeper::ZOO_CONNECTING_STATE       => :connecting,
      Zookeeper::ZOO_CONNECTED_STATE        => :connected,
      Zookeeper::ZOO_ASSOCIATING_STATE      => :associating,
    }.freeze

    def initialize(host, opts={})
      @event_handler = EventHandler.new(self)
      @cnx = ::Zookeeper.new(host, DEFAULT_TIMEOUT, get_default_watcher_block)
    end

    def closed?
      defined?(::JRUBY_VERSION) ? jruby_closed? : mri_closed?
    end

    private
      def jruby_closed?
        @cnx.state == Java::OrgApacheZookeeper::ZooKeeper::States::CLOSED
      end

      def mri_closed?
        @cnx.state or false
      rescue RuntimeError => e
        # gah, lame error parsing here
        raise e if (e.message != 'zookeeper handle is closed') and not defined?(::JRUBY_VERSION)
        true
      end

    public
    def state
      if defined?(::JRUBY_VERSION) 
        @cnx.state.to_string.downcase.to_sym
      else
        STATE_SYM_MAP.fetch(@cnx.state) { |k| raise IndexError, "unrecognized state: #{k}" }
      end
    end

    # reopen the underlying connection
    # returns state of connection after operation
    def reopen(timeout=10, watcher=nil)
      @cnx.reopen(timeout, watcher)
      state
    end

    def connected?
      wrap_state_closed_error { @cnx.connected? }
    end

    def associating?
      wrap_state_closed_error { @cnx.associating? }
    end

    def connecting?
      wrap_state_closed_error { @cnx.connecting? }
    end
{'fraction_non_alphanumeric': 0.08996088657105607, 'fraction_numerical': 0.0015645371577574967, 'mean_word_length': 2.735150925024343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1021773', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1253, 'n_words': 267}