text:
require_relative "abstract_unit"
require "active_support/testing/stream"

class Deprecatee
  def initialize
    @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request)
    @_request = "there we go"
  end
  def request; @_request end
  def old_request; @request end

  def partially(foo = nil)
    ActiveSupport::Deprecation.warn("calling with foo=nil is out") if foo.nil?
  end

  def not() 2 end
  def none() 1 end
  def one(a) a end
  def multi(a, b, c) [a, b, c] end
  deprecate :none, :one, :multi

  def a; end
  def b; end
  def c; end
  def d; end
  def e; end
  deprecate :a, :b, c: :e, d: "you now need to do something extra for this one"

  def f=(v); end
  deprecate :f=

  deprecate :g
  def g(h) h end

  module B
    C = 1
  end
  A = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Deprecatee::A", "Deprecatee::B::C")

  module New
    class Descendant; end
  end
  Old = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("Deprecatee::Old", "Deprecatee::New")
end

class DeprecateeWithAccessor
  include ActiveSupport::Deprecation::DeprecatedConstantAccessor

  module B
    C = 1
  end
  deprecate_constant "A", "DeprecateeWithAccessor::B::C"

  class NewException < StandardError; end
  deprecate_constant "OldException", "DeprecateeWithAccessor::NewException"
end

class DeprecationTest < ActiveSupport::TestCase
  include ActiveSupport::Testing::Stream

  def setup
    # Track the last warning.
    @old_behavior = ActiveSupport::Deprecation.behavior
    @last_message = nil
    ActiveSupport::Deprecation.behavior = Proc.new { |message| @last_message = message }

    @dtc = Deprecatee.new
  end

  def teardown
    ActiveSupport::Deprecation.behavior = @old_behavior
  end

  def test_inline_deprecation_warning
    assert_deprecated(/foo=nil/) do
      @dtc.partially
    end
  end

  def test_undeprecated
    assert_not_deprecated do
      assert_equal 2, @dtc.not
    end
  end

  def test_deprecate_method_on_class
    assert_deprecated(/none is deprecated/) do
      assert_equal 1, @dtc.none
    end

    assert_deprecated(/one is deprecated/) do
      assert_equal 1, @dtc.one(1)
    end

    assert_deprecated(/multi is deprecated/) do
      assert_equal [1, 2, 3], @dtc.multi(1, 2, 3)
    end
  end

  def test_deprecate_method_doesnt_expand_positional_argument_hash
    hash = { k: 1 }

    assert_deprecated(/one is deprecated/) do
      assert_same hash, @dtc.one(hash)
    end

    assert_deprecated(/g is deprecated/) do
      assert_same hash, @dtc.g(hash)
    end
  end

  def test_deprecate_object
    deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, ":bomb:")
    assert_deprecated(/:bomb:/) { deprecated_object.to_s }
  end

  def test_nil_behavior_is_ignored
    ActiveSupport::Deprecation.behavior = nil
    assert_deprecated(/foo=nil/) { @dtc.partially }
  end

  def test_several_behaviors
    @a, @b, @c = nil, nil, nil

    ActiveSupport::Deprecation.behavior = [
      lambda { |msg, callstack, horizon, gem| @a = msg },
      lambda { |msg, callstack| @b = msg },
      lambda { |*args| @c = args },
    ]

    @dtc.partially
    assert_match(/foo=nil/, @a)
    assert_match(/foo=nil/, @b)
    assert_equal 4, @c.size
  end

  def test_raise_behaviour
    ActiveSupport::Deprecation.behavior = :raise

    message   = "Revise this deprecated stuff now!"
    callstack = caller_locations

    e = assert_raise ActiveSupport::DeprecationException do
      ActiveSupport::Deprecation.behavior.first.call(message, callstack, "horizon", "gem")
    end
    assert_equal message, e.message
    assert_equal callstack.map(&:to_s), e.backtrace.map(&:to_s)
  end

  def test_default_stderr_behavior
    ActiveSupport::Deprecation.behavior = :stderr
    behavior = ActiveSupport::Deprecation.behavior.first

    content = capture(:stderr) {
      assert_nil behavior.call("Some error!", ["call stack!"], "horizon", "gem")
    }
    assert_match(/Some error!/, content)
    assert_match(/call stack!/, content)
  end

  def test_default_stderr_behavior_with_warn_method
    ActiveSupport::Deprecation.behavior = :stderr

    content = capture(:stderr) {
      ActiveSupport::Deprecation.warn("Instance error!", ["instance call stack!"])
    }

    assert_match(/Instance error!/, content)
    assert_match(/instance call stack!/, content)
  end

  def test_default_silence_behavior
    ActiveSupport::Deprecation.behavior = :silence
    behavior = ActiveSupport::Deprecation.behavior.first

    stderr_output = capture(:stderr) {
      assert_nil behavior.call("Some error!", ["call stack!"], "horizon", "gem")
    }
    assert_empty stderr_output
  end

  def test_default_notify_behavior
    ActiveSupport::Deprecation.behavior = :notify
    behavior = ActiveSupport::Deprecation.behavior.first

    begin
      events = []
      ActiveSupport::Notifications.subscribe("deprecation.my_gem_custom") { |*args|
        events << args.extract_options!
      }

      assert_nil behavior.call("Some error!", ["call stack!"], "horizon", "MyGem::Custom")
      assert_equal 1, events.size
      assert_equal "Some error!", events.first[:message]
      assert_equal ["call stack!"], events.first[:callstack]
      assert_equal "horizon", events.first[:deprecation_horizon]
      assert_equal "MyGem::Custom", events.first[:gem_name]
    ensure
      ActiveSupport::Notifications.unsubscribe("deprecation.my_gem_custom")
    end
  end

  def test_default_invalid_behavior
    e = assert_raises(ArgumentError) do
      ActiveSupport::Deprecation.behavior = :invalid
    end

    assert_equal ":invalid is not a valid deprecation behavior.", e.message
  end

  def test_deprecated_instance_variable_proxy
    assert_not_deprecated { @dtc.request.size }

    assert_deprecated("@request.size") { assert_equal @dtc.request.size, @dtc.old_request.size }
    assert_deprecated("@request.to_s") { assert_equal @dtc.request.to_s, @dtc.old_request.to_s }
  end

  def test_deprecated_instance_variable_proxy_shouldnt_warn_on_inspect
    assert_not_deprecated { assert_equal @dtc.request.inspect, @dtc.old_request.inspect }
  end

  def test_deprecated_constant_proxy
    assert_not_deprecated { Deprecatee::B::C }
    assert_deprecated("Deprecatee::A") { assert_equal Deprecatee::B::C, Deprecatee::A }
    assert_not_deprecated { assert_equal Deprecatee::B::C.class, Deprecatee::A.class }
  end

  def test_deprecated_constant_descendant
    assert_not_deprecated { Deprecatee::New::Descendant }

    assert_deprecated("Deprecatee::Old") do
      assert_equal Deprecatee::Old::Descendant, Deprecatee::New::Descendant
    end

    assert_raises(NameError) do
      assert_deprecated("Deprecatee::Old") { Deprecatee::Old::NON_EXISTENCE }
    end
  end

  def test_deprecated_constant_accessor
    assert_not_deprecated { DeprecateeWithAccessor::B::C }
    assert_deprecated("DeprecateeWithAccessor::A") { assert_equal DeprecateeWithAccessor::B::C, DeprecateeWithAccessor::A }
  end

  def test_deprecated_constant_accessor_exception
    raise DeprecateeWithAccessor::NewException.new("Test")
  rescue DeprecateeWithAccessor::OldException => e
    assert_kind_of DeprecateeWithAccessor::NewException, e
  end

  def test_assert_deprecated_raises_when_method_not_deprecated
    assert_raises(Minitest::Assertion) { assert_deprecated { @dtc.not } }
  end

  def test_assert_not_deprecated
    assert_raises(Minitest::Assertion) { assert_not_deprecated { @dtc.partially } }
  end

  def test_assert_deprecation_without_match
    assert_deprecated do
      @dtc.partially
    end
  end

  def test_assert_deprecated_matches_any_warning
    assert_deprecated "abc" do
      ActiveSupport::Deprecation.warn "abc"
      ActiveSupport::Deprecation.warn "def"
    end
  rescue Minitest::Assertion
    flunk "assert_deprecated should match any warning in block, not just the last one"
  end

  def test_assert_not_deprecated_returns_result_of_block
    assert_equal 123, assert_not_deprecated { 123 }
  end

  def test_assert_deprecated_returns_result_of_block
    result = assert_deprecated("abc") do
      ActiveSupport::Deprecation.warn "abc"
      123
    end
    assert_equal 123, result
  end

  def test_assert_deprecated_warn_work_with_default_behavior
    ActiveSupport::Deprecation.instance_variable_set("@behavior", nil)
    assert_deprecated("abc") do
      ActiveSupport::Deprecation.warn "abc"
    end
  end

  def test_silence
    ActiveSupport::Deprecation.silence do
      assert_not_deprecated { @dtc.partially }
    end

    ActiveSupport::Deprecation.silenced = true
    assert_not_deprecated { @dtc.partially }
    ActiveSupport::Deprecation.silenced = false
  end

  def test_silence_threaded
    barrier = Concurrent::CyclicBarrier.new(2)

    th = Thread.new do
      ActiveSupport::Deprecation.silence do
        barrier.wait
        barrier.wait
        assert_not_deprecated { ActiveSupport::Deprecation.warn "abc" }
      end
      assert_deprecated("abc") { ActiveSupport::Deprecation.warn "abc" }
    end

    barrier.wait

    assert_deprecated("abc") { ActiveSupport::Deprecation.warn "abc" }

    ActiveSupport::Deprecation.silence do
      assert_not_deprecated { ActiveSupport::Deprecation.warn "abc" }
    end

    assert_deprecated("abc") { ActiveSupport::Deprecation.warn "abc" }

    barrier.wait
    th.join
  ensure
    th.kill
  end

  def test_deprecation_without_explanation
    assert_deprecated { @dtc.a }
    assert_deprecated { @dtc.b }
    assert_deprecated { @dtc.f = :foo }
  end

  def test_deprecation_with_alternate_method
    assert_deprecated(/use e instead/) { @dtc.c }
  end

  def test_deprecation_with_explicit_message
    assert_deprecated(/you now need to do something extra for this one/) { @dtc.d }
  end

  def test_deprecation_in_other_object
    messages = []

    klass = Class.new do
      delegate :warn, :behavior=, to: ActiveSupport::Deprecation
    end

    o = klass.new
    o.behavior = Proc.new { |message, callstack| messages << message }
    assert_difference("messages.size") do
      o.warn("warning")
    end
  end

  def test_deprecated_method_with_custom_method_warning
    deprecator = deprecator_with_messages

    class << deprecator
      private
        def deprecated_method_warning(method, message)
          "deprecator.deprecated_method_warning.#{method}"
        end
    end

    deprecatee = Class.new do
      def method
      end
      deprecate :method, deprecator: deprecator
    end

    deprecatee.new.method
    assert deprecator.messages.first.match("DEPRECATION WARNING: deprecator.deprecated_method_warning.method")
  end

  def test_deprecate_with_custom_deprecator
    custom_deprecator = Struct.new(:deprecation_warning).new

    assert_called_with(custom_deprecator, :deprecation_warning, [:method, nil]) do
      klass = Class.new do
        def method
        end
        deprecate :method, deprecator: custom_deprecator
      end

      klass.new.method
    end
  end

  def test_deprecated_constant_with_deprecator_given
    deprecator = deprecator_with_messages
    klass = Class.new
    klass.const_set(:OLD, ActiveSupport::Deprecation::DeprecatedConstantProxy.new("klass::OLD", "Object", deprecator))
    assert_difference("deprecator.messages.size") do
      klass::OLD.to_s
    end
  end

  def test_deprecated_constant_with_custom_message
    deprecator = deprecator_with_messages

    klass = Class.new
    klass.const_set(:OLD, ActiveSupport::Deprecation::DeprecatedConstantProxy.new("klass::OLD", "Object", deprecator, message: "foo"))

    klass::OLD.to_s
    assert_match "foo", deprecator.messages.last
  end

  def test_deprecated_instance_variable_with_instance_deprecator
    deprecator = deprecator_with_messages

    klass = Class.new() do
      def initialize(deprecator)
        @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
        @_request = :a_request
      end
      def request; @_request end
      def old_request; @request end
    end

    assert_difference("deprecator.messages.size") { klass.new(deprecator).old_request.to_s }
  end

  def test_deprecated_instance_variable_with_given_deprecator
    deprecator = deprecator_with_messages

    klass = Class.new do
      define_method(:initialize) do
        @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
        @_request = :a_request
      end
      def request; @_request end
      def old_request; @request end
    end

    assert_difference("deprecator.messages.size") { klass.new.old_request.to_s }
  end

  def test_delegate_deprecator_instance
    klass = Class.new do
      attr_reader :last_message
      delegate :warn, :behavior=, to: ActiveSupport::Deprecation

      def initialize
        self.behavior = [Proc.new { |message| @last_message = message }]
      end

      def deprecated_method
        warn(deprecated_method_warning(:deprecated_method, "You are calling deprecated method"))
      end

      private
        def deprecated_method_warning(method_name, message = nil)
          message || "#{method_name} is deprecated and will be removed from This Library"
        end
    end

    object = klass.new
    object.deprecated_method
    assert_match(/You are calling deprecated method/, object.last_message)
  end

  def test_default_deprecation_horizon_should_always_bigger_than_current_rails_version
    assert_operator ActiveSupport::Deprecation.new.deprecation_horizon, :>, ActiveSupport::VERSION::STRING
  end

  def test_default_gem_name
    deprecator = ActiveSupport::Deprecation.new

    deprecator.send(:deprecated_method_warning, :deprecated_method, "You are calling deprecated method").tap do |message|
      assert_match(/is deprecated and will be removed from Rails/, message)
    end
  end

  def test_custom_gem_name
    deprecator = ActiveSupport::Deprecation.new("2.0", "Custom")

    deprecator.send(:deprecated_method_warning, :deprecated_method, "You are calling deprecated method").tap do |message|
      assert_match(/is deprecated and will be removed from Custom/, message)
    end
  end

  def test_deprecate_work_before_define_method
    assert_deprecated(/g is deprecated/) { @dtc.g(1) }
  end

  def test_config_disallows_no_deprecations_by_default
    assert_equal ActiveSupport::Deprecation.disallowed_warnings, []
  end

  def test_allows_configuration_of_disallowed_warnings
    resetting_disallowed_deprecation_config do
      config_warnings = ["unsafe_method is going away"]
      ActiveSupport::Deprecation.disallowed_warnings = config_warnings
      assert_equal ActiveSupport::Deprecation.disallowed_warnings, config_warnings
    end
  end

  def test_no_disallowed_behavior_with_no_disallowed_messages
    resetting_disallowed_deprecation_config do
      ActiveSupport::Deprecation.disallowed_behavior = :raise
      @dtc.none
      @dtc.partially
    end
  end

  def test_disallowed_behavior_does_not_apply_to_allowed_messages
    resetting_disallowed_deprecation_config do
      ActiveSupport::Deprecation.disallowed_behavior = :raise
      ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]

      @dtc.none
    end
  end

  def test_disallowed_behavior_when_disallowed_message_configured_with_substring
    resetting_disallowed_deprecation_config do
      ActiveSupport::Deprecation.disallowed_behavior = :raise
      ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]

      e = assert_raise ActiveSupport::DeprecationException do
        @dtc.partially
      end

      message = "DEPRECATION WARNING: calling with foo=nil is out"
      assert_match message, e.message
    end
  end

  def test_disallowed_behavior_when_disallowed_message_configured_with_symbol_treated_as_substring
    resetting_disallowed_deprecation_config do
      ActiveSupport::Deprecation.disallowed_behavior = :raise
      ActiveSupport::Deprecation.disallowed_warnings = [:foo]

      e = assert_raise ActiveSupport::DeprecationException do
        @dtc.partially
      end

      message = "DEPRECATION WARNING: calling with foo=nil is out"
      assert_match message, e.message
    end
  end

  def test_disallowed_behavior_when_disallowed_message_configured_with_regular_expression
    resetting_disallowed_deprecation_config do
      ActiveSupport::Deprecation.disallowed_behavior = :raise
      ActiveSupport::Deprecation.disallowed_warnings = [/none|one*/]

      e = assert_raise ActiveSupport::DeprecationException do
        @dtc.none
      end

      message = "none is deprecated"
      assert_match message, e.message

      e = assert_raise ActiveSupport::DeprecationException do
        @dtc.one
      end

      message = "one is deprecated"
      assert_match message, e.message
    end
  end

  def test_disallowed_behavior_when_disallowed_message_configured_with_scalar_symbol_all
    resetting_disallowed_deprecation_config do
      allowed_message = nil
      disallowed_message = nil

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| allowed_message = msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| disallowed_message = msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = :all

      @dtc.partially
      assert_nil allowed_message
      assert_match(/foo=nil/, disallowed_message)

      allowed_message = nil
      disallowed_message = nil
      @dtc.none
      assert_nil allowed_message
      assert_match(/none is deprecated/, disallowed_message)
    end
  end

  def test_different_behaviors_for_allowed_and_disallowed_messages
    resetting_disallowed_deprecation_config do
      @a, @b, @c, @d = nil, nil, nil, nil

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @a = msg },
        lambda { |msg, callstack| @b = msg },
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @c = msg },
        lambda { |msg, callstack| @d = msg },
      ]

      ActiveSupport::Deprecation.disallowed_warnings = ["foo=nil"]

      @dtc.partially
      @dtc.none

      assert_match(/none is deprecated/, @a)
      assert_match(/none is deprecated/, @b)
      assert_match(/foo=nil/, @c)
      assert_match(/foo=nil/, @d)
    end
  end

  def test_allow
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "b is deprecated",
        "c is deprecated"
      ]

      ActiveSupport::Deprecation.allow do
        @dtc.a
        @dtc.b
        @dtc.c
      end

      assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/c is deprecated/, @warnings_allowed.join("\n"))
      assert_empty @warnings_disallowed
    end
  end

  def test_allow_only_matching_warnings
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated",
        "b is deprecated",
        "c is deprecated",
      ]

      ActiveSupport::Deprecation.allow ["b is", "c is"] do
        @dtc.none
        @dtc.a
        @dtc.b
        @dtc.c
      end

      assert_match(/none is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/b is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/c is deprecated/, @warnings_allowed.join("\n"))

      assert_no_match(/none is deprecated/, @warnings_disallowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
      assert_no_match(/b is deprecated/, @warnings_disallowed.join("\n"))
      assert_no_match(/c is deprecated/, @warnings_disallowed.join("\n"))
    end
  end

  def test_allow_with_symbol
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated",
        "b is deprecated",
        "c is deprecated",
      ]

      ActiveSupport::Deprecation.allow [:"b is", :"c is"] do
        @dtc.none
        @dtc.a
        @dtc.b
        @dtc.c
      end

      assert_match(/none is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/b is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/c is deprecated/, @warnings_allowed.join("\n"))

      assert_no_match(/none is deprecated/, @warnings_disallowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
      assert_no_match(/b is deprecated/, @warnings_disallowed.join("\n"))
      assert_no_match(/c is deprecated/, @warnings_disallowed.join("\n"))
    end
  end

  def test_allow_with_regexp
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated",
        "b is deprecated",
        "c is deprecated",
      ]

      ActiveSupport::Deprecation.allow [/(b|c)\sis/] do
        @dtc.none
        @dtc.a
        @dtc.b
        @dtc.c
      end

      assert_match(/none is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/b is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/c is deprecated/, @warnings_allowed.join("\n"))

      assert_no_match(/none is deprecated/, @warnings_disallowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
      assert_no_match(/b is deprecated/, @warnings_disallowed.join("\n"))
      assert_no_match(/c is deprecated/, @warnings_disallowed.join("\n"))
    end
  end

  def test_allow_only_has_effect_inside_provided_block
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated"
      ]

      ActiveSupport::Deprecation.allow "a is deprecated and will" do
        @dtc.a
      end

      assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))

      @warnings_allowed, @warnings_disallowed = [], []

      @dtc.a

      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
    end
  end

  def test_allow_only_has_effect_on_the_thread_on_which_it_was_called
    th1, th2 = nil, nil
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated"
      ]

      th1 = Thread.new do
        # barrier.wait
        ActiveSupport::Deprecation.allow "a is deprecated and will" do
          th2 = Thread.new do
            @dtc.a
          end
          th2.join
        end
      end

      th1.join

      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
    end
  ensure
    th1.kill
    th2.kill
  end

  def test_is_a_noop_based_on_if_kwarg_truthy_or_falsey
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated"
      ]

      ActiveSupport::Deprecation.allow "a is deprecated and will", if: true do
        @dtc.a
      end

      assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))

      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.allow "a is deprecated and will", if: Object.new do
        @dtc.a
      end

      assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))

      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.allow "a is deprecated and will", if: false do
        @dtc.a
      end

      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))

      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.allow "a is deprecated and will", if: nil do
        @dtc.a
      end

      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
    end
  end

  def test_is_a_noop_based_on_if_kwarg_using_proc
    resetting_disallowed_deprecation_config do
      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_allowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_behavior = [
        lambda { |msg, callstack, horizon, gem| @warnings_disallowed << msg }
      ]

      ActiveSupport::Deprecation.disallowed_warnings = [
        "a is deprecated"
      ]

      ActiveSupport::Deprecation.allow "a is deprecated and will", if: Proc.new { true } do
        @dtc.a
      end

      assert_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_no_match(/a is deprecated/, @warnings_disallowed.join("\n"))

      @warnings_allowed, @warnings_disallowed = [], []

      ActiveSupport::Deprecation.allow "a is deprecated and will", if: Proc.new { false } do
        @dtc.a
      end

      assert_no_match(/a is deprecated/, @warnings_allowed.join("\n"))
      assert_match(/a is deprecated/, @warnings_disallowed.join("\n"))
    end
  end

  private
    def deprecator_with_messages
      klass = Class.new(ActiveSupport::Deprecation)
      deprecator = klass.new
      deprecator.behavior = Proc.new { |message, callstack| deprecator.messages << message }
      def deprecator.messages
        @messages ||= []
      end
      deprecator
    end

    def resetting_disallowed_deprecation_config
      original_deprecations = ActiveSupport::Deprecation.disallowed_warnings
      original_behaviors = ActiveSupport::Deprecation.disallowed_behavior
      yield
    ensure
      ActiveSupport::Deprecation.disallowed_warnings = original_deprecations
      ActiveSupport::Deprecation.disallowed_behavior = original_behaviors
    end
end


text:
module LatoView
  # This class is the main class for cells.
  class Cell < Cell::Concept

    # Set cells directory
    view_paths << "#{LatoView::Engine.root}/app/cells"

    # Include cells dependencies
    include ActionView::Helpers::FormHelper
    include ActionView::Helpers::UrlHelper
    include ActionView::Helpers::CaptureHelper
    include ERB::Util
    include ::Cell::Erb

  end
end

redpajama_set_name: RedPajamaGithub


text:
package com.intellij.spring.webflow.config.model.xml.version2_0;

import com.intellij.spring.webflow.config.model.xml.WebflowConfigDomElement;
import com.intellij.util.xml.GenericAttributeValue;
import org.jetbrains.annotations.NotNull;

public interface FlowExecutionRepository extends WebflowConfigDomElement {

  @NotNull
  GenericAttributeValue<Integer> getMaxExecutions();

  @NotNull
  GenericAttributeValue<Integer> getMaxExecutionSnapshots();
}


text:
require "logstash/inputs/base"
require "logstash/namespace"

# This plugin works into getting data from your networks into logstash by leveraing
# the libpcap capabilities in your OS.

class LogStash::Inputs::Pcap < LogStash::Inputs::Base

  config_name "pcap"

  # If undefined, Logstash will complain, even if codec is unused.
  default :codec, "plain"

  # The interface you want to get data from
  config :interface, :validate => :string, :required => true

  public
  def register
    require "pcap"
    @client = Jruby::Pcap.live(@interface)
  end # def register

  def run(queue)
    @client.each do |packet|
      payload = { :timestamp => packet.timestamp }
      payload.merge!(packet.to_hash)
      event = LogStash::Event.new(payload)
      decorate(event)
      queue << event
    end
  end # def run

end # class LogStash::Inputs::Neo4j


text:
<?php
namespace Iekadou\Quickies;

abstract class BaseModel
{
    const _cn = "Iekadou\\Quickies\\BaseModel";

    protected $data = array();
    protected $db_connection = null;
    protected $id = null;
    protected $fields = array();
    protected $cached_fields = array();
    public $errors = null;

    protected function _pre_construct()
    {
    }

    public function __construct()
    {
        $this->_pre_construct();
        global $DB_CONNECTOR;
        if (!isset($DB_CONNECTOR)) {
            $DB_CONNECTOR = new DBConnector();
        }
        $this->db_connection = $DB_CONNECTOR;
        if ($this->db_connection->get_connect_errno()) {
            $this->errors[] = "db";
        }
        foreach($this->fields as $field_name => $field) {
            if (isset($field['default'])) {
                $this->data[$field_name] = $field['default'];
            } else {
                $this->data[$field_name] = "";
            }
        }
        $this->data['deleted_files'] = array();
    }

    public function __isset($field_name) {
        return $field_name == '_cn' || isset($this->id) || isset($this->data[$field_name]) || isset($this->data[$field_name.'_id']) || method_exists($this, 'get_'.$field_name) ||
            ((strpos($field_name, '_display') > 0) && isset($this->data[substr($field_name, 0, strpos($field_name, '_display'))])) ||
            ((strpos($field_name, '_file_list') > 0) && isset($this->data[substr($field_name, 0, strpos($field_name, '_file_list'))]));
    }

    public function __get($field_name) {
        if ($field_name == '_cn') {
            return self::_cn;
        }
        if ($field_name == 'id') {
            return $this->id;
        }
        if ($field_name == in_array($field_name, array_keys($this->fields)) || method_exists($this, 'get_'.$field_name)) {
            $method_name = 'get_' . $field_name;
            if (method_exists($this, $method_name)) {
                return $this->$method_name();
            }
            $field = $this->fields[$field_name]['type'];
            if ($field == "Text") {
                return;
            } else {
                $field = new $field($this->fields[$field_name]);
            }
            return $field->_get($this, $field_name);
        } else if (!empty($field_name) && $field_name == in_array($field_name.'_id', array_keys($this->fields))) {
            $field_name .= '_id';
            $method_name = 'get_' . $field_name;
            if (method_exists($this, $method_name)) {
                return $this->$method_name();
            }
            $field = $this->fields[$field_name]['type'];
            $field = new $field($this->fields[$field_name]);
            $id = $field->_get($this, $field_name);
            if (DB_CACHING) {
                if (isset($this->cached_fields[$field_name])) {
                    return $this->cached_fields[$field_name];
                }
            }
            $result = _i($this->fields[$field_name]['foreign_type'])->get($id);
            if (DB_CACHING) {
                $this->cached_fields[$field_name] = $result;
            }
            return $result;
        } else if (strpos($field_name, '_display') > 0) {
            $field_name = substr($field_name, 0, strpos($field_name, '_display'));
            $choices = _i($this->fields[$field_name]['choices']);
            return $choices::get_by_id($this->$field_name)[1];
        } else if (strpos($field_name, '_file_list') > 0) {
            $field_name = substr($field_name, 0, strpos($field_name, '_file_list'));
            $files = preg_split('/;/', $this->$field_name);
            if ($files[0] == '') {
                return array();
            }
            $result = array();
            foreach ($files as $file) {
                $re = '/\[(?P<file>[\s\S]+)\](?P<path>[\s\S]+)/';
                preg_match($re, $file, $matches);
                $result[] = array("file" => $matches['file'], "path" => $matches['path']);
            }
            return $result;
        } else {
            return $this->$field_name;
        }
    }

    public function __set($field_name, $value) {

        if (isset($value)) {
            if ($field_name == in_array($field_name, array_keys($this->fields)) || $field_name . '_id' == in_array($field_name, array_keys($this->fields))) {
                $method_name = 'set_' . $field_name;
                if (method_exists($this, $method_name)) {
                    return $this->$method_name($value);
                }
                $field = $this->fields[$field_name]['type'];
                if ($field != "Text") {
                    $field = new $field($this->fields[$field_name]);
                    $field->_set($this, $field_name, $value);
                }
                return $this;
            } else {
                $this->$field_name = $value;
                return $this;
            }
        }
        return $this;
    }

    public function makemigrations() {
        $new_fields = array();
        $del_fields = array();
        $change_fields = array();
        $dir = new \DirectoryIterator(PATH.'vendor/iekadou/quickies/lib/Quickies/migrations/');
        foreach ($dir as $fileinfo) {
            if (!$fileinfo->isDot()) {
                $filename = $fileinfo->getFilename();
                if (!file_exists(PATH.'migrations/'.$filename)) {
                    copy(PATH.'vendor/iekadou/quickies/lib/Quickies/migrations/'.$filename, PATH.'migrations/'.$filename);
                }
            }
        }

        $dir = new \DirectoryIterator(PATH.'migrations/');
        $latest_migration = 0;
        foreach ($dir as $fileinfo) {
            if (!$fileinfo->isDot()) {
                $filename = $fileinfo->getFilename();
                $regex = "/^".$this->table."_([0-9])+.php$/";
                if (preg_match($regex, $filename)) {
                    $version_number = substr($filename, strlen($this->table)+1, strlen($filename) - strlen($this->table) - strlen('.php')-1);
                    if ($version_number > $latest_migration) {
                        $latest_migration = $version_number;
                    }
                }
            }
        }
        if ($latest_migration > 0) {
            $latest_migration_name = PATH.'migrations/'.$this->table.'_'.$latest_migration.'.php';
            include($latest_migration_name);
            foreach($this->fields as $field_name => $field) {
                if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                    if (!isset($migration['fields'][$field_name])) {
                        $new_fields[$field_name] = $this->fields[$field_name];
                    } else {
                        $changes = $this->_detect_field_changes($this->fields[$field_name], $migration['fields'][$field_name]);
                        if (!empty($changes)) {
                            $change_fields[$field_name] = $changes;
                        }
                    }
                }
            }
            foreach($migration['fields'] as $field_name => $field) {
                if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                    if (!isset($this->fields[$field_name])) {
                        $del_fields[$field_name] = $migration['fields'][$field_name];
                    }
                }
            }
        } else {
            $new_fields = $this->fields;
        }
        $current_migration = $latest_migration + 1;
        $query_parts = array();
        include(PATH.'/config/secrets.php');
        if ($latest_migration == 0) {
            array_push($query_parts, "CREATE TABLE `".$secrets['db_name']."`.`".$this->table."` (`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
            foreach ($new_fields as $field_name => $field) {
                if ($this->_get_field_query($field_name, $field) != "") {
                    array_push($query_parts, ", ".$this->_get_field_query($field_name, $field));
                }
            }
            array_push($query_parts, ");");
        } else {
            if (!empty($new_fields)) {
                foreach($new_fields as $field_name => $field) {
                    array_push($query_parts, "ALTER TABLE `".$secrets['db_name']."`.`".$this->table."` ADD ".$this->_get_field_query($field_name, $field).";");
                }
            }
            if (!empty($del_fields)) {
                foreach($del_fields as $field_name => $field) {
                    array_push($query_parts, "ALTER TABLE `".$secrets['db_name']."`.`".$this->table."` DROP COLUMN `".$field_name."`;");
                }
            }
            if (!empty($change_fields)) {
                foreach($change_fields as $field_name => $field) {
                    array_push($query_parts, "ALTER TABLE `".$secrets['db_name']."`.`".$this->table."` CHANGE `".$field_name."` ".$this->_get_field_query($field_name, $field).";");
                }
            }
        }
        unset($secrets);

        if (empty($new_fields) && empty($del_fields) && empty($change_fields)) {
        } else {
            $complete_query = "";
            foreach ($query_parts as $part) {
                $complete_query .= $part;
            }
            $current_migration_filename = PATH . '/migrations/' . $this->table . '_' . $current_migration . '.php';
            $string = '<?php
$migration = array();
$migration[\'id\']  =  "' . $this->table . '_' . $current_migration . '";
$migration[\'query\'] = "' . $complete_query . '";
$migration[\'fields\'] = ' . var_export($this->fields, true) . ';';
            file_put_contents($current_migration_filename, $string);
            print "Migrations created at: ".$this->table."\n";
        }
    }

    protected function _get_field_query($field_name, $field) {
        if (class_exists($field['type'])) {
            return _i($field['type'])->get_sql_part($field_name, $field);
        }
    }

    protected function _detect_field_changes($field1, $field2) {
        $changes = array();
        if ($field1['type'] != $field2['type']) {
            return $field1;
        }
        foreach ($field1 as $key => $value) {
            if (!isset($field2[$key])) {
                $changes[$key] = $value;
            } else {
                if ($field1[$key] != $field2[$key]) {
                    if (($field1['type'] == "Iekadou\\Quickies\\PasswordField" && $key == 'max_length') ||
                        ($field1['type'] == "Iekadou\\Quickies\\UrlField" && $key == 'max_length') ||
                        ($field1['type'] == VarcharField::_cn && $key == 'max_length') ||
                        ($field1['type'] == TimestampField::_cn && $key == 'auto_create') ||
                        ($field1['type'] == TimestampField::_cn && $key == 'auto_update') ||
                        ($field1['type'] == ForeignKeyField::_cn && $key == 'foreign_type') ||
                        ($field1['type'] == IntegerChoiceField::_cn && $key == 'choices') ||
                        $key == 'required' ||
                        $key == 'default') {
                        $changes[$key] = $value;
                    }
                }
            }
        }
        if (empty($changes)) {
            return array();
        }
        return $field1;
    }

    protected function reset_errors() {
        $this->errors = null;
    }

    public function get_data($field_name)
    {
        return $this->data[$field_name];
    }

    public function set_data($field_name, $value)
    {
        $this->data[$field_name] = $value;
        return $this;
    }

    public function get($id)
    {
        $this->reset_errors();
        $id = $this->db_connection->real_escape_string($id);
        $obj_query = $this->db_connection->query("SELECT * FROM ".$this->table." WHERE id = '" . $id . "';");
        if ($obj_query->num_rows == 1) {
            $obj = $obj_query->fetch_object();
            foreach($this->fields as $field_name => $field) {
                if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                    $this->$field_name = Utils::mysql_unescape_string($obj->$field_name);
                }
            }
            $this->id = $obj->id;
            return $this;
        }
        return false;
    }

    public function save()
    {
        $this->reset_errors();
        $update_str = '';
        $i = 0;
        foreach($this->fields as $field_name => $field) {
            if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                if (!_i($this->fields[$field_name]['type'])->_validate_pre_db($this, $field_name)) {
                    $this->errors[] = $field_name;
                }
                if ($this->fields[$field_name]['type'] == TimestampField::_cn && isset($this->fields[$field_name]['auto_update']) && $this->fields[$field_name]['auto_update']) {
                    $this->$field_name = time();
                }
                if ($i > 0) {
                    $update_str .= ", ";
                }
                $i++;
                if ($this->fields[$field_name]['type'] == BooleanField::_cn) {
                    $update_str .= $field_name . " = '" . ($this->$field_name ? 1 : 0) . "'";
                } else {
                    $update_str .= $field_name . " = '" . $this->db_connection->real_escape_string($this->$field_name) . "'";
                }
            }
        }
        if (!empty($this->errors)) {
            throw new ValidationError($this->errors);
        }
        $obj_query = $this->db_connection->query("UPDATE ".$this->table." set ".$update_str." WHERE id = '" . $this->id . "';");
        if ($obj_query) {
            if (isset($this->data['deleted_files'])) {
                foreach ($this->data['deleted_files'] as $deleted_file) {
                    if (file_exists($deleted_file)) {
                        unlink($deleted_file);
                    }
                }
                $this->data['deleted_files'] = array();
            }
            return $this;
        }
        return false;
    }

    public function create()
    {
        $this->reset_errors();
        $insert_str = '(';
        $i = 0;
        foreach($this->fields as $field_name => $field) {
            if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                if (!_i($this->fields[$field_name]['type'])->_validate_pre_db($this, $field_name)) {
                    $this->errors[] = $field_name;
                }
                if ($i > 0) {
                    $insert_str .= ", ";
                }
                $i++;
                $insert_str .= $field_name;
            }
        }
        $insert_str .= ') VALUES (';
        $i = 0;
        foreach($this->fields as $field_name => $field) {
            if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                if ($i > 0) {
                    $insert_str .= ", ";
                }
                $i++;
                if ($this->fields[$field_name]['type'] == TimestampField::_cn && isset($this->fields[$field_name]['auto_create']) && $this->fields[$field_name]['auto_create']) {
                    $this->$field_name = time();
                }
                if (!isset($this->$field_name)) {
                    $this->$field_name = '';
                }
                if ($this->fields[$field_name]['type'] == BooleanField::_cn) {
                    $insert_str .= "'".($this->$field_name ? 1 : 0)."'";
                } else {
                    $insert_str .= "'".$this->db_connection->real_escape_string($this->$field_name )."'";
                }
            }
        }

        $insert_str .= ')';
        if (!empty($this->errors)) {
            throw new ValidationError($this->errors);
        }
        $obj_query = $this->db_connection->query("INSERT INTO ".$this->table." ".$insert_str.";");
        if ($obj_query) {
            $this->id = $this->db_connection->get_insert_id();
            return $this;
        }

        echo $this->db_connection->get_error();
        return false;
    }

    public function delete($id=null)
    {
        $this->reset_errors();
        if ($id) {
            $id = $this->db_connection->real_escape_string($id, ENT_QUOTES);
        } else {
            $id = $this->id;
        }
        if ($id) {
            $user_query = $this->db_connection->query("DELETE FROM ".$this->table." WHERE id = '" . $id . "';");
            if ($user_query) {
                foreach($this->fields as $field_name => $field) {
                    if ($this->fields[$field_name]['type'] == FileField::_cn) {
                        if (file_exists(PATH.$this->$field_name) && is_file(PATH.$this->$field_name)) {
                            unlink(PATH.$this->$field_name);
                        }
                    }
                }
                return true;
            }
        }
        return false;
    }

    public function delete_by($conditions)
    {
        $this->reset_errors();
        $condition_str = '';
        $i = 0;
        foreach($conditions as $condition) {
            if ($condition[0] == 'id' || in_array($condition[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $condition_str .= ' and ';
                } else {
                    $condition_str = "WHERE ";
                }
                $i++;
                $condition_str .= $condition[0]." ".$condition[1]." '".$this->db_connection->real_escape_string($condition[2])."'";
            }
        }
        if ($i > 0) {
            $obj_delete = $this->db_connection->query("DELETE FROM ".$this->table." ".$condition_str.";");
            return $obj_delete != false;
        } else {
            return false; // TODO hint: do not delete all by accident
        }

    }

    public function count_by($conditions=array(), $sortings=array())
    {
        $this->reset_errors();
        $condition_str = '';
        $i = 0;
        foreach($conditions as $condition) {
            if ($condition[0] == 'id' || in_array($condition[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $condition_str .= ' and ';
                } else {
                    $condition_str = "WHERE ";
                }
                $i++;
                $condition_str .= $condition[0]." ".$condition[1]." '".$this->db_connection->real_escape_string($condition[2])."'";
            }
        }
        $order_str = '';
        $i = 0;
        foreach($sortings as $sorting) {
            if ($sorting[0] == 'id' || in_array($sorting[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $order_str .= ', ';
                } else {
                    $order_str = 'ORDER BY ';
                }
                $i++;
                $order_str .= $sorting[0]." ".$sorting[1];
            }
        }
        $obj_count = $this->db_connection->query("SELECT count(*) as count FROM ".$this->table." ".$condition_str." ".$order_str.";");
        $obj = $obj_count->fetch_object();
        return $obj->count;
    }

    public function get_by($conditions, $sortings=array(), $limit='')
    {
        $this->reset_errors();
        $condition_str = '';
        $i = 0;
        foreach($conditions as $condition) {
            if ($condition[0] == 'id' || in_array($condition[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $condition_str .= ' and ';
                } else {
                    $condition_str = "WHERE ";
                }
                $i++;
                $condition_str .= $condition[0]." ".$condition[1]." '".$this->db_connection->real_escape_string($condition[2])."'";
            }
        }
        $order_str = '';
        $i = 0;
        foreach($sortings as $sorting) {
            if ($sorting[0] == 'id' || in_array($sorting[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $order_str .= ', ';
                } else {
                    $order_str = 'ORDER BY ';
                }
                $i++;
                $order_str .= $sorting[0]." ".$sorting[1];
            }
        }
        $limit_str = "";
        if (!empty($limit)) {
            $limit_str = "LIMIT ".$this->db_connection->real_escape_string($limit);
        }
        $obj_query = $this->db_connection->query("SELECT * FROM ".$this->table." ".$condition_str." ".$order_str." ".$limit_str.";");
        if ($obj_query && $obj_query->num_rows == 1) {
            $obj = $obj_query->fetch_object();
            foreach($this->fields as $field_name => $field) {
                if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                    $this->$field_name = Utils::mysql_unescape_string($obj->$field_name);
                }
            }
            $this->id = $obj->id;
            return $this;
        }
        return false;
    }

    public function filter_by($conditions=array(), $sortings=array(), $limit='')
    {
        $this->reset_errors();
        $condition_str = '';
        $i = 0;
        foreach($conditions as $condition) {
            if ($condition[0] == 'id' || in_array($condition[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $condition_str .= ' and ';
                } else {
                    $condition_str = "WHERE ";
                }
                $i++;
                $condition_str .= $condition[0]." ".$condition[1]." '".$this->db_connection->real_escape_string($condition[2])."'";
            }
        }
        $order_str = '';
        $i = 0;
        foreach($sortings as $sorting) {
            if ($sorting[0] == 'id' || in_array($sorting[0], array_keys($this->fields))) {
                if ($i > 0) {
                    $order_str .= ', ';
                } else {
                    $order_str = 'ORDER BY ';
                }
                $i++;
                $order_str .= $sorting[0]." ".$sorting[1];
            }
        }
        $limit_str = "";
        if (!empty($limit)) {
            $limit_str = "LIMIT ".$this->db_connection->real_escape_string($limit);
        }
        $obj_array = Array();
        $obj_query = $this->db_connection->query("SELECT * FROM ".$this->table." ".$condition_str." ".$order_str." ".$limit_str.";");
        if ($obj_query) {
            while ($row = $obj_query->fetch_object()) {
                $obj = _i(get_class($this));
                foreach($this->fields as $field_name => $field) {
                    if ($field['type'] != ReflectedForeignKeyField::_cn && $field['type'] != ReflectedM2MField::_cn) {
                        $obj->$field_name = Utils::mysql_unescape_string($row->$field_name);
                    }
                }
                $obj->id = $row->id;
                $obj_array[] = $obj;

            }
            return $obj_array;
        }
        return false;
    }

    public function interpret_request($POST, $FILES, $fields=false)
    {
        $this->reset_errors();
        foreach($this->fields as $field_name => $field) {
            if (!$fields || in_array($field_name, $fields)) {
                if (isset($POST[$field_name])) {
                    if ($this->fields[$field_name]['type'] != FileField::_cn) {
                        $this->$field_name = $POST[$field_name];
                    } else {
                        $files_str = "";
                        if (is_array($POST[$field_name])) {
                            $delete_files = $POST[$field_name];
                            $get_name = $field_name.'_file_list';
                            $file_list = $this->$get_name;
                            foreach($file_list as $file) {
                                $found = false;
                                foreach($delete_files as $delete_file) {
                                    if ($file['path'] == $delete_file) {
                                        $found = true;
                                    }
                                }
                                if (!$found) {
                                    if (!Utils::endsWith($files_str, ";") && $files_str != "") {
                                        $files_str .= ";";
                                    }
                                    $files_str .= "[" . $file['file'] . "]" . $file['path'];
                                } else {
                                    if (file_exists(PATH.$file['path'])) {
                                        $this->data['deleted_files'][] = PATH.$file['path'];
                                    }
                                }
                            }
                        }
                        $this->$field_name = $files_str;
                    }
                } elseif (isset($FILES[$field_name]) && $this->fields[$field_name]['type'] == FileField::_cn) {
                    $file_field = $FILES[$field_name];
                    if (is_array($file_field['name'])) {
                        $files = array();
                        $i = 0;
                        while ($i < sizeof($file_field['name'])) {
                            if ($file_field['tmp_name'][$i] != "" && $file_field['error'][$i] == 0) {
                                $files[] = array("name" => $file_field['name'][$i], "tmp_name" => $file_field['tmp_name'][$i], "type" => $file_field['type'][$i], "error" => $file_field['error'][$i], "size" => $file_field['size'][$i]);
                            }
                            $i++;
                        }
                    } else {
                        $files = array(array("name" => $file_field['name'], "tmp_name" => $file_field['tmp_name'], "type" => $file_field['type'], "error" => $file_field['error'], "size" => $file_field['size']));
                    }
                    $result = $this->$field_name;
                    foreach($files as $file) {
                        $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
                        $basename = pathinfo($file['name'], PATHINFO_BASENAME);
                        $i = 0;
                        $uploadfile = UPLOADDIR.md5(basename($file['name'])+$i).".".$ext;
                        while (file_exists(PATH.$uploadfile)) {
                            $i++;
                            $uploadfile = UPLOADDIR.md5(basename($file['name'])+$i).".".$ext;
                        }
                        if (isset($this->fields[$field_name]['allowed_file_types'])) {
                            preg_split('/;/', $this->fields[$field_name]['allowed_file_types']);

                            if (mime_content_type($file['tmp_name']) != image/gif) {

                            }
                        }
                        if (move_uploaded_file($file['tmp_name'], PATH.$uploadfile)) {
                            if (!Utils::endsWith($result, ";") && $result != "") {
                                $result .= ";";
                            }
                            $result .= '['.$basename.']'.$uploadfile;
                        }
                        if (file_exists($file['tmp_name'])) {
                            unlink($file['tmp_name']);
                        }
                    }
                    $this->$field_name = $result;
                } elseif (!isset($FILES[$field_name]) && $this->fields[$field_name]['type'] == FileField::_cn) {
                    $this->$field_name = "";
                } else {
//                    $this->$field_name = null;
                }
            }
        }
        if (!empty($this->errors)) {
            throw new ValidationError($this->errors);
        }
        return $this;
    }

    public static function _cn() {
        return get_called_class();
    }

    public function get_form_fields() {
        $Form = new BaseModelForm(
            $model=get_class($this),
            $fields=$this->form_fields,
            $object_id=$this->id);
        return $Form->get_form_fields();
    }

    public function get_form() {
        $Form = new BaseModelForm(
            $model=get_class($this),
            $fields=$this->form_fields,
            $object_id=$this->id);
        return $Form->render();
    }

    public function get_field_verbose_name($field_name) {
        if (isset($this->fields[$field_name]['verbose_name'])) {
            return Translation::translate($this->fields[$field_name]['verbose_name']);
        } else {
            return Translation::translate(ucfirst($field_name));
        }
    }
}


text:
''' Testing bash apps
'''
import parsl
from parsl import python_app

import time
import argparse

from parsl.tests.configs.local_threads import config

local_config = config

@python_app
def increment(x):
    return x + 1

def test_stress(count=1000):
    """Threaded app launch stress test"""
    start = time.time()
    x = {}
    for i in range(count):
        x[i] = increment(i)
    end = time.time()
    print("Launched {0} tasks in {1} s".format(count, end - start))

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--count", default="100",
                        help="width of the pipeline")
    parser.add_argument("-d", "--debug", action='store_true',
                        help="Count of apps to launch")
    args = parser.parse_args()

    if args.debug:
        parsl.set_stream_logger()

    test_stress(count=int(args.count))


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>AudioStream</title>
<meta name="date" content="2015-10-08">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

com.microsoft.bing.speech

Class AudioStream

java.lang.Object

java.io.OutputStream

com.microsoft.bing.speech.AudioStream

All Implemented Interfaces:

java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

public class AudioStream
extends java.io.OutputStream

The Audio Stream class.

Method Summary

Methods

Modifier and Type
Method and Description

void
close()

Closes this stream.

void
finalize()

Finalizes the object.

void
flush()

Flushes this stream.

void
write(byte[] buffer)

Equivalent to write(buffer, 0, buffer.length).

void
write(byte[] buffer,
     int offset,
     int length)

Writes to the audio stream.

void
write(int oneByte)

Writes to the audio stream.

void
writeAudioFormat(short encodingFormat,
                int averageBytesPerSecond,
                short bitsPerSample,
                short blockAlign,
                short channelCount,
                int samplesPerSecond,
                byte[] formatSpecificData)

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail

writeAudioFormat

public void writeAudioFormat(short encodingFormat,
                    int averageBytesPerSecond,
                    short bitsPerSample,
                    short blockAlign,
                    short channelCount,
                    int samplesPerSecond,
                    byte[] formatSpecificData)

write

public void write(byte[] buffer,
         int offset,
         int length)
           throws java.io.IOException

Writes to the audio stream.

Overrides:

write in class java.io.OutputStream

Parameters:

buffer - containing the audio to be written.

length - Number of bytes in the buffer to be written.

offset - in buffer where to write from.

Throws:

java.lang.RuntimeException

java.io.IOException

flush

public void flush()
           throws java.io.IOException

Flushes this stream. Implementations of this method should ensure that
 any buffered data is written out. This implementation does nothing.

Specified by:

flush in interface java.io.Flushable

Overrides:

flush in class java.io.OutputStream

Throws:

java.io.IOException - if an error occurs while flushing this stream.

write

public void write(byte[] buffer)
           throws java.io.IOException

Equivalent to write(buffer, 0, buffer.length).

Overrides:

write in class java.io.OutputStream

Throws:

java.io.IOException

close

public void close()
           throws java.io.IOException

Closes this stream. Frees the native audio stream.

Specified by:

close in interface java.io.Closeable

Specified by:

close in interface java.lang.AutoCloseable

Overrides:

close in class java.io.OutputStream

Throws:

java.io.IOException

write

public void write(int oneByte)
           throws java.lang.UnsupportedOperationException

Writes to the audio stream.

Specified by:

write in class java.io.OutputStream

Throws:

java.lang.UnsupportedOperationException

finalize

public void finalize()
              throws java.lang.Throwable

Finalizes the object. Called when no more reference to the object exists.

Overrides:

finalize in class java.lang.Object

Throws:

java.lang.Throwable

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method


text:
namespace vw {
  // If you have an error message that leads you here, you tried to apply a
  // functor to two user-defined (non-arithmetic) types, and we didn't know
  // what type to return.
  template <class T>
  struct TypeDeductionError;

  namespace core { namespace detail {
    struct unknown_type_tag : public boost::mpl::int_<10000> {};

    // This should be considered an implementation detail
#define _VW_INTERNAL_TYPE_DEDUCTION(Type, Number)            \
    BOOST_STATIC_ASSERT(boost::is_arithmetic<Type>::value);  \
    template <>                                              \
    struct TypeDeductionIndex<Type> {                        \
      typedef boost::mpl::int_<Number> type;                 \
      BOOST_STATIC_CONSTANT(uint32, value = type::value);  \
    }                                                        \

    template <class T>
    struct TypeDeductionIndex {
      typedef unknown_type_tag type;
      BOOST_STATIC_CONSTANT(uint32, value = type::value);
    };

    _VW_INTERNAL_TYPE_DEDUCTION(              char,  100);
    _VW_INTERNAL_TYPE_DEDUCTION(       signed char,  200);
    _VW_INTERNAL_TYPE_DEDUCTION(     unsigned char,  300);
    _VW_INTERNAL_TYPE_DEDUCTION(      signed short,  400);
    _VW_INTERNAL_TYPE_DEDUCTION(    unsigned short,  500);
    _VW_INTERNAL_TYPE_DEDUCTION(        signed int,  600);
    _VW_INTERNAL_TYPE_DEDUCTION(      unsigned int,  700);
    _VW_INTERNAL_TYPE_DEDUCTION(       signed long,  800);
    _VW_INTERNAL_TYPE_DEDUCTION(     unsigned long,  900);
#if defined(BOOST_HAS_LONG_LONG)
    _VW_INTERNAL_TYPE_DEDUCTION(  signed long long, 1000);
    _VW_INTERNAL_TYPE_DEDUCTION(unsigned long long, 1100);
#endif
#if defined(BOOST_HAS_MS_INT64)
    _VW_INTERNAL_TYPE_DEDUCTION(          __int64;, 1200);
    _VW_INTERNAL_TYPE_DEDUCTION( unsigned __int64;, 1300);
#endif
    _VW_INTERNAL_TYPE_DEDUCTION(             float, 1400);
    _VW_INTERNAL_TYPE_DEDUCTION(            double, 1500);
    _VW_INTERNAL_TYPE_DEDUCTION(       long double, 1600);
  }}

  template <class T1, class T2>
  struct TypeDeductionHelper {
    typedef typename core::detail::TypeDeductionIndex<T1>::type I1;
    typedef typename core::detail::TypeDeductionIndex<T2>::type I2;

    // If an error message leads you here, you tried to apply a functor to two
    // user-defined (non-arithmetic) types, and we didn't know what type to
    // return. (We catch the case where the types are actually the same in the
    // next specialization.)
    BOOST_STATIC_ASSERT((!boost::mpl::equal_to<I1, I2>::value));

    // If an error message leads you here, you have an arithmetic type that we
    // haven't identified. Please report this as a bug.
    //
    // (Implementation note: _VW_INTERNAL_TYPE_DEDUCTION contains an
    // is_arithmetic check which makes this logic correct)
    BOOST_STATIC_ASSERT(!(boost::mpl::and_<boost::is_arithmetic<T1>, boost::mpl::equal_to<I1, core::detail::unknown_type_tag> >::value));
    BOOST_STATIC_ASSERT(!(boost::mpl::and_<boost::is_arithmetic<T2>, boost::mpl::equal_to<I2, core::detail::unknown_type_tag> >::value));

    typedef typename
      boost::mpl::eval_if< boost::mpl::greater<I1, I2>
      , boost::mpl::identity<T1>
      , boost::mpl::identity<T2>
      >::type type;
  };

  // Both types are the same? Just use that.
  template <class ArgT>
  struct TypeDeductionHelper<ArgT, ArgT> {
    typedef ArgT type;
  };

  // ********************************************************************
  // Now we set up the default promotion behavior for general types.
  // This includes promotions of compound types (e.g. pixel types)
  // when used in operations with fundamental types.  Thus for example
  // multiplying PixelRGB<int> by float should return PixelRGB<float>.
  // We address this by recursing on the template parameter.  Users
  // can explicitly specialize PromoteTypeSpecialization<> to support
  // custom behaviors when both arguments are custom types.
  // ********************************************************************

  // First we forward-declare the specialization class.
  template <class Arg1T, class Arg2T> class PromoteTypeSpecialization;

  // This helper class forwards the default case to TypeDeductionHelper.
  template <class Arg1T, class Arg2T, bool Arg1IsCompound, bool Arg2IsCompound>
  struct PromoteTypeSpecializationHelper : public TypeDeductionHelper<Arg1T,Arg2T> {};

  // Recursive behavior when Arg1T is a compound type.
  template <class Arg1T, class Arg2T>
  struct PromoteTypeSpecializationHelper<Arg1T,Arg2T,true,false> {
    typedef typename CompoundChannelCast<Arg1T,typename PromoteTypeSpecialization<typename CompoundChannelType<Arg1T>::type, Arg2T>::type>::type type;
  };

  // Recursive behavior when Arg2T is a compound type.
  template <class Arg1T, class Arg2T>
  struct PromoteTypeSpecializationHelper<Arg1T,Arg2T,false,true> {
    typedef typename CompoundChannelCast<Arg2T,typename PromoteTypeSpecialization<Arg1T, typename CompoundChannelType<Arg2T>::type>::type>::type type;
  };

  template <class Arg1T, class Arg2T, bool SameWrapper>
  struct PromoteTypeSpecializationHelper2;

  template <class Arg1T, class Arg2T>
  struct PromoteTypeSpecializationHelper2<Arg1T, Arg2T, true> {
    typedef typename CompoundChannelCast<Arg1T, typename PromoteTypeSpecialization<typename CompoundChannelType<Arg1T>::type, typename CompoundChannelType<Arg2T>::type>::type>::type type;
  };

  template <class Arg1T, class Arg2T>
  struct PromoteTypeSpecializationHelper2<Arg1T, Arg2T, false> {
    typedef typename TypeDeductionHelper<Arg1T,Arg2T>::type type;
  };

  // Recursive behavior when both Arg1T and Arg2T are compound types.
  template <class Arg1T, class Arg2T>
  struct PromoteTypeSpecializationHelper<Arg1T,Arg2T,true,true> {
    typedef typename PromoteTypeSpecializationHelper2<Arg1T, Arg2T,
      boost::is_same<Arg1T, typename CompoundChannelCast<Arg2T,typename CompoundChannelType<Arg1T>::type>::type>::value>::type type;
    };

  // Dispatch to the appropriate helper based on which if any
  // argument is a compound type.
  template <class Arg1T, class Arg2T>
  class PromoteTypeSpecialization
    : public PromoteTypeSpecializationHelper<Arg1T, Arg2T, IsCompound<Arg1T>::value, IsCompound<Arg2T>::value>
  {};

  // ********************************************************************
  // Finally, we provide forwarding classes for the different operations
  // that the user can specifically specialize in special cases if
  // needed.  The classes the user *uses*, such as SumType, simply
  // strip off any CV-qualification and forward to the appropriate
  // specialization type.  If the user needs to override the type
  // deduction behavior, they should generally do so by overriding one
  // of the ...Specialization classes, so that they don't have to worry
  // about CV-qualification themselves.
  // ********************************************************************

  template <class Arg1T, class Arg2T>
  struct SumTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};

  template <class Arg1T, class Arg2T>
  struct DifferenceTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};

  template <class Arg1T, class Arg2T>
  struct ProductTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};

  template <class Arg1T, class Arg2T>
  struct QuotientTypeSpecialization : public PromoteTypeSpecialization<Arg1T,Arg2T> {};

  template <class Arg1T, class Arg2T>
  struct PromoteType {
    typedef typename PromoteTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
                                               typename boost::remove_cv<Arg2T>::type>::type type;
  };

  template <class Arg1T, class Arg2T>
  struct SumType {
    typedef typename SumTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
                                           typename boost::remove_cv<Arg2T>::type>::type type;
  };

  template <class Arg1T, class Arg2T>
  struct DifferenceType {
    typedef typename DifferenceTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
                                                  typename boost::remove_cv<Arg2T>::type>::type type;
  };

  template <class Arg1T, class Arg2T>
  struct ProductType {
    typedef typename ProductTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
                                               typename boost::remove_cv<Arg2T>::type>::type type;
  };

  template <class Arg1T, class Arg2T>
  struct QuotientType {
    typedef typename QuotientTypeSpecialization<typename boost::remove_cv<Arg1T>::type,
                                                typename boost::remove_cv<Arg2T>::type>::type type;
  };

  /// \endcond

} // namespace vw

#endif


text:
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    /**
     * Enable Soft Delete Security Measure
     *
     * @var boolean
     */
    protected $softDelete = true;

    /**
     * Define the table that Model it will use
     *
     * @var string
     */
    protected $table = "roles";

    /**
    * Stores the field that can be fulfill by user
    *
    * @var array
    */
    protected $fillable = ['name', 'slug'];

    /**
    * Stores the field that cant be fulfill by user
    *
    * @var array
    **/
    protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at'];

     /**
      * Specifies the type of each field
      *
      * @var array
      */
    protected $casts = [
        'name' => 'string',
        'slug' => 'string',
    ];

    /**
     * RELATIONS
     */

    /**
     * define relation of role to users
     *
     * @return Eloquent object
     */
    public function user()
    {
        return $this->hasMany(\App\Models\User::class);
    }
}


text:
class Page {
    constructor($page) {
        $page.on({
            'pageHide': function () {
                this.modeSelectionExit()
            }.bind(this)
        })
    }

    modeSelectionEnter(callback_select, callback_enter) {
        let _callback_select

        callback_select = callback_select || function () { }
        _callback_select = function () {
            //callback_select.apply( callback_select, arguments )
            callback_select(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9], arguments[10])
            setTimeout(function () {
                this.modeSelectionExit()
            }.bind(this), 10)
        }.bind(this)

        _frame.app_main.mode_selection_callback = _callback_select

        _frame.app_main.mode_selection_on(callback_enter)

        return _callback_select
    }

    modeSelectionExit() {
        if (!_frame.dom.layout.hasClass('mode-selection'))
            return false

        _frame.app_main.mode_selection_off()
    }
}

Page.hide = function (page) {
    // console.log(`========== Page hiding: ${page} ==========`)
    // const t0 = performance.now()
    page = page || _frame.app_main.cur_page
    if (typeof page == 'string') {
        if (_frame.app_main.page_dom[page])
            _frame.app_main.page_dom[page].addClass('off').trigger('pageHide').detach()
        if (_frame.dom.navs[page])
            _frame.dom.navs[page].removeClass('on')
    } else {
        page.addClass('off').trigger('pageHide').detach()
        let p = page.attr('page')
        if (p && _frame.dom.navs[p])
            _frame.dom.navs[p].removeClass('on')
    }
    _frame.app_main.cur_page = null
    // const t1 = performance.now()
    // console.log(`========== Page hide: ${page}, took ${t1 - t0}ms ==========`)
}

Page.show = function (page) {
    // console.log(`========== Page Showing: ${page} ==========`)
    // const t0 = performance.now()

    page = page || _frame.app_main.cur_page
    let p

    if (typeof page == 'string') {
        if (_frame.app_main.page_dom[page])
            _frame.app_main.page_dom[page].appendTo(_frame.dom.main).removeClass('off').trigger('pageShow')
        if (_frame.dom.navs[page])
            _frame.dom.navs[page].addClass('on')
        p = page
    } else {
        page.appendTo(_frame.dom.main).removeClass('off').trigger('pageShow')
        p = page.attr('page')
    }

    // 关闭之前的页面
    if (_frame.app_main.cur_page)
        Page.hide(_frame.app_main.cur_page)

    if (p) {
        if (_frame.dom.navs[p])
            _frame.dom.navs[p].addClass('on')
        //_frame.dom.main.attr('data-theme', p)
        _frame.dom.layout.attr('data-theme', p)
        _frame.app_main.cur_page = p
    }

    // const t1 = performance.now()
    // console.log(`========== Page Showed: ${page}, took ${t1 - t0}ms ==========`)
}

Page.resetScroll = function (page) {
    page = page || _frame.app_main.cur_page
    if (typeof page == 'string')
        page = _frame.app_main.page_dom[page]

    if (page && page.length) {
        page.attr('scrollbody', 0)
        page.find('[scrollbody]').each(function (i, el) {
            el.setAttribute('scrollbody', 0)
        })
    }
}

Page.init = function (page) {
    page = page || _frame.app_main.cur_page
    let p

    if (typeof page == 'string') {
        p = page
        page = _frame.app_main.page_dom[page]
    } else {
        page.appendTo(_frame.dom.main).removeClass('off').trigger('pageShow')
        p = page.attr('page')
    }

    if (!page || !page.length)
        return

    // function handlerScroll(e) {
    //     //$(e.currentTarget).data('scrollTop', e.currentTarget.scrollTop)
    //     e.currentTarget.setAttribute('scrollbody', e.currentTarget.scrollTop)
    // }

    if (p && _frame.app_main.page[p] && _frame.app_main.page[p].init)
        _frame.app_main.page[p].init(page)
    _p.initDOM(page)

    // page.find('[scrollbody]').on('scroll', handlerScroll)

    page.on({
        // 'scroll': handlerScroll,
        'pageShow.scrollbody': function () {
            // console.log('pageShow.scrollbody', page, page.attr('scrollbody'))
            page.scrollTop(page.attr('scrollbody') || 0)
            page.find('[scrollbody]').each(function (i, el) {
                //el.scrollTop = $(el).data('scrollTop')
                // console.log(
                //     'pageShow.scrollbody',
                //     el,
                //     el.getAttribute('scrollbody')
                // )
                el.scrollTop = el.getAttribute('scrollbody') || 0
                // setTimeout(function () {
                //     console.log(
                //         'pageShow.scrollbody',
                //         el,
                //         el.getAttribute('scrollbody')
                //     )
                //     el.scrollTop = el.getAttribute('scrollbody') || 0
                // }, 10)
            })
        }
    })
}