text:
This project adheres to [Semantic Versioning](http://semver.org/).

This CHANGELOG follows the format listed at [Our CHANGELOG Guidelines ](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md).
Which is based on [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]

## [2.0.3] - 2022-09-21

###Fixed
- 'check-haproxy.rb': Compatibility with HAProxy 2.3.0

## [2.0.2] - 2020-03-09

### Changed
- Fixed frozen_string_literal issues
- Removed centos6 build

## [2.0.1] - 2020-03-06

### Changed
- Nothing, empty release with Travis fixed to deploy release

## [2.0.0] - 2020-03-06
### Breaking Changes
- Bump `sensu-plugin` dependency from `~> 1.2` to `~> 4.0` you can read the changelog entries for [4.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#400---2018-02-17), [3.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#300---2018-12-04), and [2.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29)

### Added
- Travis build automation to generate Sensu Asset tarballs that can be used n conjunction with Sensu provided ruby runtime assets and the Bonsai Asset Index
- Require latest sensu-plugin for [Sensu Go support](https://github.com/sensu-plugins/sensu-plugin#sensu-go-enablement)
- Bonsai integration

### Changed
- update changelog guidelines location (@majormoses)
- Updated bundler to '~> 2.1'
- Updated rubocop to '~> 0.80.1'
- Updated rake to '~> 13.0'
- Updated codeclimate-test-reporter to '~> 1.0'
- Remediated rubocop warnings
- change backends services sessions check comparison to slim instead of smax in check-haproxy.rb - fixes issue [#39](https://github.com/sensu-plugins/sensu-plugins-haproxy/issues/39) (@jindraj)
- Extended sessions warning and critical output to also show sessions limit.

## [1.4.0] - 2017-09-09
### Added
- metrics-haproxy.rb: new flag to expose all possible metrics `--expose-all` (@bergerx)
- added flag to use raw haproxy metric names `--use-haproxy-names` (@bergerx)
- added flag to include explicit type names in generated metrics names  `--use-explicit-names` (@bergerx)

## [1.3.0] - 2017-08-05
### Added
- Flag to use SSL in `check-haproxy.rb` (@foozmeat) (@Evesey)

## [1.2.0] - 2017-07-25
### Added
- Ruby 2.4.1 testing
- Add frontend request rate metrics to `--server-metrics` (@Evesey)

## [1.1.0] - 2017-01-30
### Added
- `check-haproxy.rb`: added fail on missing service flag (@obazoud)
- Consider backends in DRAIN status as UP and add flag to include backends in MAINT status (@modax)

## [1.0.0] - 2016-12-08
### Added
- added names of the failed backends to check-haproxy.rb status
- added check status of failed backends to check-haproxy.rb output
- support for Ruby 2.3.0

### Changed
- check-haproxy.rb: Services without a health check should not be considered failed
- Update to rubocop 0.40 and cleanup

### Removed
- Ruby 1.9.3 support

## [0.1.1] - 2016-04-23
### Added
- added session_current to output for server_metrics

## [0.1.0] - 2016-03-04
### Added
- added `num_up` metric for each backend set showing the number of available backends
- added flags to check session availability per backend

### Changed
- update rubocop rules and fix errors

## [0.0.5] - 2015-11-26
### Changed
- alert on min server count
- fixed reporting of empty values

## [0.0.4] - 2015-08-04
### Changed
- general cleanup

## [0.0.3] - 2015-07-14
### Changed
- updated sensu-plugin gem to 1.2.0

## [0.0.2] - 2015-06-02
### Fixed
- added binstubs

### Changed
- removed cruft from /lib

## 0.0.1 - 2015-05-21
### Added
- initial release

[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/2.0.3...HEAD
[2.0.3]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/2.0.2...2.0.3
[2.0.2]:https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/2.0.1...2.0.2
[2.0.1]:https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/2.0.0...2.0.1
[2.0.0]:https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/1.4.0...2.0.0
[1.4.0]:https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/1.3.0...1.4.0
[1.3.0]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/1.2.0...1.3.0
[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/1.1.0...1.2.0
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.1.1...1.0.0
[0.1.1]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.1.0...0.1.1
[0.1.0]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.0.5...0.1.0
[0.0.5]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.0.4...0.0.5
[0.0.4]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.0.3...0.0.4
[0.0.3]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.0.2...0.0.3
[0.0.2]: https://github.com/sensu-plugins/sensu-plugins-haproxy/compare/0.0.1...0.0.2


text:
require 'contest'
require 'tilt'

begin
  require 'rdiscount'

  class RDiscountTemplateTest < Test::Unit::TestCase
    test "registered for '.md' files" do
      assert Tilt.mappings['md'].include?(Tilt::RDiscountTemplate)
    end

    test "registered for '.mkd' files" do
      assert Tilt.mappings['mkd'].include?(Tilt::RDiscountTemplate)
    end

    test "registered for '.markdown' files" do
      assert Tilt.mappings['markdown'].include?(Tilt::RDiscountTemplate)
    end

    test "registered above BlueCloth" do
      %w[md mkd markdown].each do |ext|
        mappings = Tilt.mappings[ext]
        blue_idx = mappings.index(Tilt::BlueClothTemplate)
        rdis_idx = mappings.index(Tilt::RDiscountTemplate)
        assert rdis_idx < blue_idx,
          "#{rdis_idx} should be lower than #{blue_idx}"
      end
    end

    test "preparing and evaluating templates on #render" do
      template = Tilt::RDiscountTemplate.new { |t| "# Hello World!" }
      assert_equal "
Hello World!
\n", template.render
    end

    test "can be rendered more than once" do
      template = Tilt::RDiscountTemplate.new { |t| "# Hello World!" }
      3.times { assert_equal "
Hello World!
\n", template.render }
    end

    test "smartypants when :smart is set" do
      template = Tilt::RDiscountTemplate.new(:smart => true) { |t|
        "OKAY -- 'Smarty Pants'" }
      assert_equal "
OKAY — ‘Smarty Pants’
\n",
        template.render
    end

    test "stripping HTML when :filter_html is set" do
      template = Tilt::RDiscountTemplate.new(:filter_html => true) { |t|
        "HELLO <blink>WORLD</blink>" }
      assert_equal "
HELLO <blink>WORLD</blink>
\n", template.render
    end
  end
rescue LoadError => boom
  warn "Tilt::RDiscountTemplate (disabled)"
end

redpajama_set_name: RedPajamaGithub


text:
/*
  Object.assign polyfill for ES5 browsers.

  This polyfill doesn't support symbol properties, since ES5 doesn't have symbols anyway.

*/
if (typeof Object.assign != 'function') {
  Object.defineProperty(Object, 'assign', {
    configurable: true,
    writable: true,
    value: function (dest) {
      if (dest == null) {
        throw new TypeError('Cannot convert dest to object');
      }
      var arg = arguments;

      dest = Object(dest);
      for (var ix = 1; ix < arg.length; ix++) {
        var src = arg[ix];
        if (src != null) {
          var k, key, keys = Object.keys(Object(src));
          for (k = 0; k < keys.length; k++) {
            key = keys[k];
            dest[key] = src[key];
          }
        }
      }
      return dest;
    }
  });
}


text:
DROP VIEW IF EXISTS view_persediaan_barang2_kehutanan;

CREATE VIEW view_persediaan_barang2_kehutanan AS

SELECT
*,
sum(jumlah) OVER (PARTITION BY kode_barang ORDER BY serial, tanggal, id_persediaan) as pra_saldo

FROM
view_persediaan_barang_kehutanan

WHERE
1 = 1  AND
id_skpd = 14;

GRANT ALL PRIVILEGES ON view_persediaan_barang2_kehutanan TO lap_kehutanan;
REVOKE INSERT, UPDATE, DELETE ON view_persediaan_barang2_kehutanan FROM lap_kehutanan;


text:
package org.broadinstitute.hellbender.tools.coveragemodel;

import org.broadinstitute.hellbender.tools.exome.Target;
import org.broadinstitute.hellbender.utils.Utils;
import org.broadinstitute.hellbender.utils.hmm.ForwardBackwardAlgorithm;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * This class stores the results of forward-backward and Viterbi algorithms for HMM-based
 * copy ratio (or copy number) models.
 *
 * @param <DATA> copy ratio emission data type
 * @param <STATE> type of hidden state
 *
 * @author Mehrtash Babadi <mehrtash@broadinstitute.org>
 */
public final class CopyRatioHMMResults<DATA, STATE> implements Serializable {

    private static final long serialVersionUID = 1891158919985229044L;
    private final CopyRatioCallingMetadata metaData;
    private final ForwardBackwardAlgorithm.Result<DATA, Target, STATE> fbResult;
    private final List<STATE> viterbiResult;

    /**
     * Public constructor.
     *
     * @param fbResult the result of forward-backward algorithm
     * @param viterbiResult the result of Viterbi algorithm
     */
    public CopyRatioHMMResults(@Nonnull final CopyRatioCallingMetadata metaData,
                               @Nonnull final ForwardBackwardAlgorithm.Result<DATA, Target, STATE> fbResult,
                               @Nonnull final List<STATE> viterbiResult) {
        this.metaData = Utils.nonNull(metaData, "Copy ratio calling metadata must be non-null");
        this.fbResult = Utils.nonNull(fbResult, "The forward-backward result must be non-null");
        this.viterbiResult = Collections.unmodifiableList(Utils.nonNull(viterbiResult, "The viterbi result must be non-null"));
        Utils.validateArg(viterbiResult.size() == fbResult.positions().size(), "The target list used in the" +
                " forward-backward algorithm has a different length that the Viterbi chain of states. This is" +
                " an inconsistency.");
    }

    public ForwardBackwardAlgorithm.Result<DATA, Target, STATE> getForwardBackwardResult() {
        return fbResult;
    }

    public List<STATE> getViterbiResult() {
        return viterbiResult;
    }

    public CopyRatioCallingMetadata getMetaData() {
        return metaData;
    }
}


text:
//Originally written by Erwin Coumans

#include "Win32OpenGLWindow.h"

#include "OpenGLInclude.h"

//#include "Bullet3Common/b3Vector3.h"

#include "Win32InternalWindowData.h"
#include <stdio.h>

static void printGLString(const char *name, GLenum s) {
    const char *v = (const char *) glGetString(s);
  printf("%s = %s\n",name, v);
}

bool sOpenGLVerbose = true;

void Win32OpenGLWindow::enableOpenGL()
{

	PIXELFORMATDESCRIPTOR pfd;
	int format;

	// get the device context (DC)
	m_data->m_hDC = GetDC( m_data->m_hWnd );

	// set the pixel format for the DC
	ZeroMemory( &pfd, sizeof( pfd ) );
	pfd.nSize = sizeof( pfd );
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 16;
	pfd.cStencilBits = 1;
	pfd.iLayerType = PFD_MAIN_PLANE;
	format = ChoosePixelFormat( m_data->m_hDC, &pfd );
	SetPixelFormat( m_data->m_hDC, format, &pfd );

	// create and enable the render context (RC)
	m_data->m_hRC = wglCreateContext( m_data->m_hDC );
	wglMakeCurrent( m_data->m_hDC, m_data->m_hRC );

	if (sOpenGLVerbose)
	{
		 printGLString("Version", GL_VERSION);
		printGLString("Vendor", GL_VENDOR);
		printGLString("Renderer", GL_RENDERER);
	}
    //printGLString("Extensions", GL_EXTENSIONS);

}

void Win32OpenGLWindow::disableOpenGL()
{
	wglMakeCurrent( NULL, NULL );
	wglDeleteContext( m_data->m_hRC );
//	ReleaseDC( m_data->m_hWnd, m_data->m_hDC );

}

void	Win32OpenGLWindow::createWindow(const b3gWindowConstructionInfo& ci)
{
	Win32Window::createWindow(ci);

	//VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
	enableOpenGL();

}

Win32OpenGLWindow::Win32OpenGLWindow()
{

}

Win32OpenGLWindow::~Win32OpenGLWindow()
{

}

void	Win32OpenGLWindow::closeWindow()
{
	disableOpenGL();

	Win32Window::closeWindow();
}

void	Win32OpenGLWindow::startRendering()
{
		pumpMessage();

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);	//clear buffers

		//glCullFace(GL_BACK);
		//glFrontFace(GL_CCW);
		glEnable(GL_DEPTH_TEST);

}

void	Win32OpenGLWindow::renderAllObjects()
{
}

void	Win32OpenGLWindow::endRendering()
 {
	SwapBuffers( m_data->m_hDC );

}


text:
from django.contrib.auth import get_user_model
from decimal import Decimal
from questions.models import UserAnswer, Question
from django.db.models import Q

# User = get_user_model()

# users = User.objects.all() #[user1 ,user2]
# all_user_answers = UserAnswer.objects.all().order_by("user_id")

def get_match(user_a, user_b):
    q1 = Q(useranswer__user=user_a)
    q2 = Q(useranswer__user=user_b)
    # question_set = Question.objects.filter(q1 | q2).distinct()
    question_set1 = Question.objects.filter(q1)
    question_set2 = Question.objects.filter(q2)
    if question_set1.count() == 0:
        return 0.0, 0
    if question_set2.count() == 0:
        return 0.0, 0
    question_set = (question_set1 | question_set2).distinct()
    a_points = 0
    b_points = 0
    a_total_points = 0.000001
    b_total_points = 0.000001
    questions_in_common = 0
    for question in question_set:
        try:
            a = UserAnswer.objects.get(user=user_a, question=question)
        except:
            a = None
        try:
            b = UserAnswer.objects.get(user=user_b, question=question)
        except:
            b = None
        if a and b:
            questions_in_common += 1
            if a.their_answer == b.my_answer:
                b_points += a.their_points
            b_total_points += a.their_points
            if b.their_answer == a.my_answer:
                a_points += b.their_points
            a_total_points += b.their_points
    if questions_in_common > 0:
        a_decimal = a_points / Decimal(a_total_points)
        b_decimal = b_points / Decimal(b_total_points)
        print b_decimal, a_decimal
        if a_decimal == 0:
            a_decimal = 0.000001
        if b_decimal == 0:
            b_decimal = 0.000001
        match_percentage = (Decimal(a_decimal) * Decimal(b_decimal)) ** (1 / Decimal(questions_in_common))
        return match_percentage, questions_in_common
    else:
        return 0.0, 0


text:
<?php

declare(strict_types=1);

namespace DesignPatterns\Behavioral\Visitor;

class Group implements Role
{
    public function __construct(private string $name)
    {
    }

    public function getName(): string
    {
        return sprintf('Group: %s', $this->name);
    }

    public function accept(RoleVisitor $visitor)
    {
        $visitor->visitGroup($this);
    }
}


text:
/* This file is part of Lwt, released under the MIT license. See LICENSE.md for
   details, or visit https://github.com/ocsigen/lwt/blob/master/LICENSE.md. */

#include "lwt_config.h"

#if !defined(LWT_ON_WINDOWS)

#include <caml/alloc.h>
#include <caml/bigarray.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
#include <caml/socketaddr.h>
#include <caml/unixsupport.h>
#include <sys/types.h>
#include <sys/socket.h>

#include "unix_recv_send_utils.h"

value lwt_unix_bytes_recvfrom(value fd, value buf, value ofs, value len,
                              value flags)
{
    CAMLparam5(fd, buf, ofs, len, flags);
    CAMLlocal2(result, address);
    int ret;
    union sock_addr_union addr;
    socklen_t addr_len;
    addr_len = sizeof(addr);
    ret = recvfrom(Int_val(fd), (char *)Caml_ba_data_val(buf) + Long_val(ofs),
                   Long_val(len), caml_convert_flag_list(flags, msg_flag_table),
                   &addr.s_gen, &addr_len);
    if (ret == -1) uerror("recvfrom", Nothing);
    address = alloc_sockaddr(&addr, addr_len, -1);
    result = caml_alloc_tuple(2);
    Field(result, 0) = Val_int(ret);
    Field(result, 1) = address;
    CAMLreturn(result);
}
#endif


text:
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/sys/dev/ata/ata-lowlevel.c,v 1.24.2.3 2004/02/11 08:47:21 scottl Exp $");

#include "opt_ata.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ata.h>
#include <sys/kernel.h>
#include <sys/conf.h>
#include <sys/bus.h>
#include <sys/sema.h>
#include <sys/taskqueue.h>
#include <vm/uma.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <dev/ata/ata-all.h>

/* prototypes */
static int ata_transaction(struct ata_request *);
static void ata_interrupt(void *);
static void ata_reset(struct ata_channel *);
static int ata_wait(struct ata_device *, u_int8_t);
static int ata_command(struct ata_device *, u_int8_t, u_int64_t, u_int16_t, u_int16_t);
static void ata_pio_read(struct ata_request *, int);
static void ata_pio_write(struct ata_request *, int);

/* local vars */
static int atadebug = 0;

/*
 * low level ATA functions
 */
void
ata_generic_hw(struct ata_channel *ch)
{
    ch->hw.reset = ata_reset;
    ch->hw.transaction = ata_transaction;
    ch->hw.interrupt = ata_interrupt;
}

/* must be called with ATA channel locked */
static int
ata_transaction(struct ata_request *request)
{
    /* safety check, device might have been detached FIXME SOS */
    if (!request->device->param) {
	request->result = ENXIO;
	return ATA_OP_FINISHED;
    }

    /* record the request as running */
    request->device->channel->running = request;

    ATA_DEBUG_RQ(request, "transaction");

    /* disable ATAPI DMA writes if HW doesn't support it */
    if ((request->device->channel->flags & ATA_ATAPI_DMA_RO) &&
	((request->flags & (ATA_R_ATAPI | ATA_R_DMA | ATA_R_WRITE)) ==
	 (ATA_R_ATAPI | ATA_R_DMA | ATA_R_WRITE)))
	request->flags &= ~ATA_R_DMA;

    switch (request->flags & (ATA_R_ATAPI | ATA_R_DMA)) {

    /* ATA PIO data transfer and control commands */
    default:
	{
	/* record command direction here as our request might be gone later */
	int write = (request->flags & ATA_R_WRITE);

	    /* issue command */
	    if (ata_command(request->device, request->u.ata.command,
			    request->u.ata.lba, request->u.ata.count,
			    request->u.ata.feature)) {
		ata_prtdev(request->device, "error issueing PIO command\n");
		request->result = EIO;
		break;
	    }

	    /* if write command output the data */
	    if (write) {
		if (ata_wait(request->device,
			     (ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)) < 0) {
		    ata_prtdev(request->device,"timeout waiting for write DRQ");
		    request->result = EIO;
		    break;
		}
		ata_pio_write(request, request->transfersize);
	    }
	}

	/* return and wait for interrupt */
	return ATA_OP_CONTINUES;

    /* ATA DMA data transfer commands */
    case ATA_R_DMA:
	/* check sanity, setup SG list and DMA engine */
	if (request->device->channel->dma->load(request->device,
						request->data,
						request->bytecount,
						request->flags & ATA_R_READ)) {
	    ata_prtdev(request->device, "setting up DMA failed\n");
	    request->result = EIO;
	    break;
	}

	/* issue command */
	if (ata_command(request->device, request->u.ata.command,
			request->u.ata.lba, request->u.ata.count,
			request->u.ata.feature)) {
	    ata_prtdev(request->device, "error issuing DMA command\n");
	    request->result = EIO;
	    break;
	}

	/* start DMA engine */
	if (request->device->channel->dma->start(request->device->channel)) {
	    ata_prtdev(request->device, "error starting DMA\n");
	    request->result = EIO;
	    break;
	}

	/* return and wait for interrupt */
	return ATA_OP_CONTINUES;

    /* ATAPI PIO commands */
    case ATA_R_ATAPI:
	/* is this just a POLL DSC command ? */
	if (request->u.atapi.ccb[0] == ATAPI_POLL_DSC) {
	    ATA_IDX_OUTB(request->device->channel, ATA_DRIVE,
			 ATA_D_IBM | request->device->unit);
	    DELAY(10);
	    if (!(ATA_IDX_INB(request->device->channel, ATA_ALTSTAT)&ATA_S_DSC))
		request->result = EBUSY;
	    break;
	}

	/* start ATAPI operation */
	if (ata_command(request->device, ATA_PACKET_CMD,
			request->transfersize << 8, 0, 0)) {
	    ata_prtdev(request->device, "error issuing ATA PACKET command\n");
	    request->result = EIO;
	    break;
	}

	/* command interrupt device ? just return and wait for interrupt */
	if ((request->device->param->config & ATA_DRQ_MASK) == ATA_DRQ_INTR)
	    return ATA_OP_CONTINUES;

	/* wait for ready to write ATAPI command block */
	{
	    int timeout = 5000; /* might be less for fast devices */
	    while (timeout--) {
		int reason = ATA_IDX_INB(request->device->channel, ATA_IREASON);
		int status = ATA_IDX_INB(request->device->channel, ATA_STATUS);

		if (((reason & (ATA_I_CMD | ATA_I_IN)) |
		     (status & (ATA_S_DRQ | ATA_S_BUSY))) == ATAPI_P_CMDOUT)
		    break;
		DELAY(20);
	    }
	    if (timeout <= 0) {
		ata_prtdev(request->device,
			   "timeout waiting for ATAPI ready\n");
		request->result = EIO;
		break;
	    }
	}

	/* this seems to be needed for some (slow) devices */
	DELAY(10);

	/* output actual command block */
	ATA_IDX_OUTSW_STRM(request->device->channel, ATA_DATA,
			   (int16_t *)request->u.atapi.ccb,
			   (request->device->param->config & ATA_PROTO_MASK) ==
			   ATA_PROTO_ATAPI_12 ? 6 : 8);

	/* return and wait for interrupt */
	return ATA_OP_CONTINUES;

    case ATA_R_ATAPI|ATA_R_DMA:
	/* is this just a POLL DSC command ? */
	if (request->u.atapi.ccb[0] == ATAPI_POLL_DSC) {
	    ATA_IDX_OUTB(request->device->channel, ATA_DRIVE,
			 ATA_D_IBM | request->device->unit);
	    DELAY(10);
	    if (!(ATA_IDX_INB(request->device->channel, ATA_ALTSTAT)&ATA_S_DSC))
		request->result = EBUSY;
	    break;
	}

	/* check sanity, setup SG list and DMA engine */
	if (request->device->channel->dma->load(request->device,
						request->data,
						request->bytecount,
						request->flags & ATA_R_READ)) {
	    ata_prtdev(request->device, "setting up DMA failed\n");
	    request->result = EIO;
	    break;
	}

	/* start ATAPI operation */
	if (ata_command(request->device, ATA_PACKET_CMD, 0, 0, ATA_F_DMA)) {
	    ata_prtdev(request->device, "error issuing ATAPI packet command\n");
	    request->result = EIO;
	    break;
	}

	/* wait for ready to write ATAPI command block */
	{
	    int timeout = 5000; /* might be less for fast devices */
	    while (timeout--) {
		int reason = ATA_IDX_INB(request->device->channel, ATA_IREASON);
		int status = ATA_IDX_INB(request->device->channel, ATA_STATUS);

		if (((reason & (ATA_I_CMD | ATA_I_IN)) |
		     (status & (ATA_S_DRQ | ATA_S_BUSY))) == ATAPI_P_CMDOUT)
		    break;
		DELAY(20);
	    }
	    if (timeout <= 0) {
		ata_prtdev(request->device,"timeout waiting for ATAPI ready\n");
		request->result = EIO;
		break;
	    }
	}

	/* this seems to be needed for some (slow) devices */
	DELAY(10);

	/* output actual command block */
	ATA_IDX_OUTSW_STRM(request->device->channel, ATA_DATA,
			   (int16_t *)request->u.atapi.ccb,
			   (request->device->param->config & ATA_PROTO_MASK) ==
			   ATA_PROTO_ATAPI_12 ? 6 : 8);

	/* start DMA engine */
	if (request->device->channel->dma->start(request->device->channel)) {
	    request->result = EIO;
	    break;
	}

	/* return and wait for interrupt */
	return ATA_OP_CONTINUES;
    }

    /* request finish here */
    if (request->device->channel->dma->flags & ATA_DMA_ACTIVE)
	request->device->channel->dma->unload(request->device->channel);
    request->device->channel->running = NULL;
    return ATA_OP_FINISHED;
}

static void
ata_interrupt(void *data)
{
    struct ata_channel *ch = (struct ata_channel *)data;
    struct ata_request *request = ch->running;
    int length;

    /* ignore this interrupt if there is no running request */
    if (!request) {
	if (ATA_LOCK_CH(ch, ATA_CONTROL)) {
	    u_int8_t status = ATA_IDX_INB(ch, ATA_STATUS);
	    u_int8_t error = ATA_IDX_INB(ch, ATA_ERROR);

	    if (bootverbose)
		ata_printf(ch, -1,
			   "spurious interrupt - status=0x%02x error=0x%02x\n",
			   status, error);
	    ATA_UNLOCK_CH(ch);
	}
	else {
	    if (bootverbose)
		ata_printf(ch, -1, "spurious interrupt - channel busy\n");
	}
	return;
    }

    ATA_DEBUG_RQ(request, "interrupt");

    /* ignore interrupt if device is busy */
    if (!(request->flags & ATA_R_TIMEOUT) &&
	ATA_IDX_INB(ch, ATA_ALTSTAT) & ATA_S_BUSY) {
	DELAY(100);
	if (!(ATA_IDX_INB(ch, ATA_ALTSTAT) & ATA_S_DRQ))
	    return;
    }

    ATA_DEBUG_RQ(request, "interrupt accepted");

    /* clear interrupt and get status */
    request->status = ATA_IDX_INB(ch, ATA_STATUS);

    request->flags |= ATA_R_INTR_SEEN;

    switch (request->flags & (ATA_R_ATAPI | ATA_R_DMA | ATA_R_CONTROL)) {

    /* ATA PIO data transfer and control commands */
    default:

	/* on control commands read back registers to the request struct */
	if (request->flags & ATA_R_CONTROL) {
	    request->u.ata.count = ATA_IDX_INB(ch, ATA_COUNT);
	    request->u.ata.lba = ATA_IDX_INB(ch, ATA_SECTOR) |
				 (ATA_IDX_INB(ch, ATA_CYL_LSB) << 8) |
				 (ATA_IDX_INB(ch, ATA_CYL_MSB) << 16);
	}

	/* if we got an error we are done with the HW */
	if (request->status & ATA_S_ERROR) {
	    request->error = ATA_IDX_INB(ch, ATA_ERROR);
	    break;
	}

	/* are we moving data ? */
	if (request->flags & (ATA_R_READ | ATA_R_WRITE)) {

	    /* if read data get it */
	    if (request->flags & ATA_R_READ)
		ata_pio_read(request, request->transfersize);

	    /* update how far we've gotten */
		request->donecount += request->transfersize;

	    /* do we need a scoop more ? */
	    if (request->bytecount > request->donecount) {

		/* set this transfer size according to HW capabilities */
		request->transfersize =
		    min((request->bytecount - request->donecount),
			request->transfersize);

		/* clear interrupt seen flag as we need to wait again */
		request->flags &= ~ATA_R_INTR_SEEN;

		/* if data write command, output the data */
		if (request->flags & ATA_R_WRITE) {

		    /* if we get an error here we are done with the HW */
		    if (ata_wait(request->device,
				 (ATA_S_READY | ATA_S_DSC | ATA_S_DRQ)) < 0) {
			ata_prtdev(request->device,
				   "timeout waiting for write DRQ");
			request->status = ATA_IDX_INB(ch, ATA_STATUS);
			break;
		    }

		    /* output data and return waiting for new interrupt */
		    ata_pio_write(request, request->transfersize);
		    return;
		}

		/* if data read command, return & wait for interrupt */
		if (request->flags & ATA_R_READ)
		    return;
	    }
	}
	/* done with HW */
	break;

    /* ATA DMA data transfer commands */
    case ATA_R_DMA:
	/* stop DMA engine and get status */
	request->dmastat = ch->dma->stop(ch);

	/* did we get error or data */
	if (request->status & ATA_S_ERROR)
	    request->error = ATA_IDX_INB(ch, ATA_ERROR);
	else if (request->dmastat & ATA_BMSTAT_ERROR)
	    request->status |= ATA_S_ERROR;
	else
	    request->donecount = request->bytecount;

	/* release SG list etc */
	ch->dma->unload(ch);

	/* done with HW */
	break;

    /* ATAPI PIO commands */
    case ATA_R_ATAPI:
	length = ATA_IDX_INB(ch, ATA_CYL_LSB)|(ATA_IDX_INB(ch, ATA_CYL_MSB)<<8);

	switch ((ATA_IDX_INB(ch, ATA_IREASON) & (ATA_I_CMD | ATA_I_IN)) |
		(request->status & ATA_S_DRQ)) {

	case ATAPI_P_CMDOUT:
	    /* this seems to be needed for some (slow) devices */
	    DELAY(10);

	    if (!(request->status & ATA_S_DRQ)) {
		ata_prtdev(request->device, "command interrupt without DRQ\n");
		request->status = ATA_S_ERROR;
		break;
	    }
	    ATA_IDX_OUTSW_STRM(ch, ATA_DATA, (int16_t *)request->u.atapi.ccb,
			       (request->device->param->config &
				ATA_PROTO_MASK)== ATA_PROTO_ATAPI_12 ? 6 : 8);
	    /* return wait for interrupt */
	    return;

	case ATAPI_P_WRITE:
	    if (request->flags & ATA_R_READ) {
		request->status = ATA_S_ERROR;
		ata_prtdev(request->device,
			   "%s trying to write on read buffer\n",
			   ata_cmd2str(request));
		break;
	    }
	    ata_pio_write(request, length);
	    request->donecount += length;

	    /* set next transfer size according to HW capabilities */
	    request->transfersize = min((request->bytecount-request->donecount),
					request->transfersize);
	    /* return wait for interrupt */
	    return;

	case ATAPI_P_READ:
	    if (request->flags & ATA_R_WRITE) {
		request->status = ATA_S_ERROR;
		ata_prtdev(request->device,
			   "%s trying to read on write buffer\n",
			   ata_cmd2str(request));
		break;
	    }
	    ata_pio_read(request, length);
	    request->donecount += length;

	    /* set next transfer size according to HW capabilities */
	    request->transfersize = min((request->bytecount-request->donecount),
					request->transfersize);
	    /* return wait for interrupt */
	    return;

	case ATAPI_P_DONEDRQ:
	    ata_prtdev(request->device,
		       "WARNING - %s DONEDRQ non conformant device\n",
		       ata_cmd2str(request));
	    if (request->flags & ATA_R_READ) {
		ata_pio_read(request, length);
		request->donecount += length;
	    }
	    else if (request->flags & ATA_R_WRITE) {
		ata_pio_write(request, length);
		request->donecount += length;
	    }
	    else
		request->status = ATA_S_ERROR;
	    /* FALLTHROUGH */

	case ATAPI_P_ABORT:
	case ATAPI_P_DONE:
	    if (request->status & (ATA_S_ERROR | ATA_S_DWF))
		request->error = ATA_IDX_INB(ch, ATA_ERROR);
	    break;

	default:
	    ata_prtdev(request->device, "unknown transfer phase\n");
	    request->status = ATA_S_ERROR;
	}

	/* done with HW */
	break;

    /* ATAPI DMA commands */
    case ATA_R_ATAPI|ATA_R_DMA:

	/* stop the engine and get engine status */
	request->dmastat = ch->dma->stop(ch);

	/* did we get error or data */
	if (request->status & (ATA_S_ERROR | ATA_S_DWF))
	    request->error = ATA_IDX_INB(ch, ATA_ERROR);
	else if (request->dmastat & ATA_BMSTAT_ERROR)
	    request->status |= ATA_S_ERROR;
	else
	    request->donecount = request->bytecount;

	/* release SG list etc */
	ch->dma->unload(ch);

	/* done with HW */
	break;
    }

    /* if we timed out the unlocking of the ATA channel is done later */
    if (!(request->flags & ATA_R_TIMEOUT)) {
	ch->running = NULL;
	ATA_UNLOCK_CH(ch);
	ch->locking(ch, ATA_LF_UNLOCK);
    }

    /* schedule completition for this request */
    ata_finish(request);
}

/* must be called with ATA channel locked */
static void
ata_reset(struct ata_channel *ch)
{
    u_int8_t err, lsb, msb, ostat0, ostat1;
    u_int8_t stat0 = 0, stat1 = 0;
    int mask = 0, timeout;

    /* do we have any signs of ATA/ATAPI HW being present ? */
    ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
    DELAY(10);
    ostat0 = ATA_IDX_INB(ch, ATA_STATUS);
    if ((ostat0 & 0xf8) != 0xf8 && ostat0 != 0xa5) {
	stat0 = ATA_S_BUSY;
	mask |= 0x01;
    }

    ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
    DELAY(10);
    ostat1 = ATA_IDX_INB(ch, ATA_STATUS);

    /* in some setups we dont want to test for a slave */
    if (!(ch->flags & ATA_NO_SLAVE)) {
	if ((ostat1 & 0xf8) != 0xf8 && ostat1 != 0xa5) {
	    stat1 = ATA_S_BUSY;
	    mask |= 0x02;
	}
    }

    /* if nothing showed up there is no need to get any further */
    /* SOS is that too strong?, we just might loose devices here XXX */
    ch->devices = 0;
    if (!mask)
	return;

    if (bootverbose)
	ata_printf(ch, -1, "reset tp1 mask=%02x ostat0=%02x ostat1=%02x\n",
		   mask, ostat0, ostat1);

    /* reset host end of channel (if supported) */
    if (ch->reset)
	ch->reset(ch);

    /* reset (both) devices on this channel */
    ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
    DELAY(10);
    ATA_IDX_OUTB(ch, ATA_ALTSTAT, ATA_A_IDS | ATA_A_RESET);
    DELAY(10000);
    ATA_IDX_OUTB(ch, ATA_ALTSTAT, ATA_A_IDS);
    DELAY(100000);
    ATA_IDX_INB(ch, ATA_ERROR);

    /* wait for BUSY to go inactive */
    for (timeout = 0; timeout < 310; timeout++) {
	if (stat0 & ATA_S_BUSY) {
	    ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
	    DELAY(10);
    	    err = ATA_IDX_INB(ch, ATA_ERROR);
	    lsb = ATA_IDX_INB(ch, ATA_CYL_LSB);
	    msb = ATA_IDX_INB(ch, ATA_CYL_MSB);
	    stat0 = ATA_IDX_INB(ch, ATA_STATUS);
	    if (bootverbose)
		ata_printf(ch, ATA_MASTER,
			   "stat=0x%02x err=0x%02x lsb=0x%02x msb=0x%02x\n",
			   stat0, err, lsb, msb);
	    if (!(stat0 & ATA_S_BUSY)) {
		if ((err & 0x7f) == ATA_E_ILI) {
		    if (lsb == ATAPI_MAGIC_LSB && msb == ATAPI_MAGIC_MSB) {
			ch->devices |= ATA_ATAPI_MASTER;
		    }
		    else if (stat0 & ATA_S_READY) {
			ch->devices |= ATA_ATA_MASTER;
		    }
		}
		else if ((stat0 & 0x4f) && err == lsb && err == msb) {
		    stat0 |= ATA_S_BUSY;
		}
	    }
	}
	if (!((mask == 0x03) && (stat0 & ATA_S_BUSY)) && (stat1 & ATA_S_BUSY)) {
	    ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
	    DELAY(10);
    	    err = ATA_IDX_INB(ch, ATA_ERROR);
	    lsb = ATA_IDX_INB(ch, ATA_CYL_LSB);
	    msb = ATA_IDX_INB(ch, ATA_CYL_MSB);
	    stat1 = ATA_IDX_INB(ch, ATA_STATUS);
	    if (bootverbose)
		ata_printf(ch, ATA_SLAVE,
			   " stat=0x%02x err=0x%02x lsb=0x%02x msb=0x%02x\n",
			   stat1, err, lsb, msb);
	    if (!(stat1 & ATA_S_BUSY)) {
		if ((err & 0x7f) == ATA_E_ILI) {
		    if (lsb == ATAPI_MAGIC_LSB && msb == ATAPI_MAGIC_MSB) {
			ch->devices |= ATA_ATAPI_SLAVE;
		    }
		    else if (stat1 & ATA_S_READY) {
			ch->devices |= ATA_ATA_SLAVE;
		    }
		}
		else if ((stat1 & 0x4f) && err == lsb && err == msb) {
		    stat1 |= ATA_S_BUSY;
		}
	    }
	}
	if (mask == 0x01)	/* wait for master only */
	    if (!(stat0 & ATA_S_BUSY) || (stat0 == 0xff && timeout > 20))
		break;
	if (mask == 0x02)	/* wait for slave only */
	    if (!(stat1 & ATA_S_BUSY) || (stat1 == 0xff && timeout > 20))
		break;
	if (mask == 0x03) {	/* wait for both master & slave */
	    if (!(stat0 & ATA_S_BUSY) && !(stat1 & ATA_S_BUSY))
		break;
	    if (stat0 == 0xff && timeout > 20)
		mask &= ~0x01;
	    if (stat1 == 0xff && timeout > 20)
		mask &= ~0x02;
	}
	DELAY(100000);
    }

    if (stat0 & ATA_S_BUSY)
	mask &= ~0x01;
    if (stat1 & ATA_S_BUSY)
	mask &= ~0x02;

    if (bootverbose)
	ata_printf(ch, -1,
		   "reset tp2 mask=%02x stat0=%02x stat1=%02x devices=0x%b\n",
		   mask, stat0, stat1, ch->devices,
		   "\20\4ATAPI_SLAVE\3ATAPI_MASTER\2ATA_SLAVE\1ATA_MASTER");
}

static int
ata_wait(struct ata_device *atadev, u_int8_t mask)
{
    u_int8_t status;
    int timeout = 0;

    DELAY(1);

    /* wait 5 seconds for device to get !BUSY */
    while (timeout < 5000000) {
	status = ATA_IDX_INB(atadev->channel, ATA_STATUS);

	/* if drive fails status, reselect the drive just to be sure */
	if (status == 0xff) {
	    ata_prtdev(atadev, "WARNING no status, reselecting device\n");
	    ATA_IDX_OUTB(atadev->channel, ATA_DRIVE, ATA_D_IBM | atadev->unit);
	    DELAY(10);
	    status = ATA_IDX_INB(atadev->channel, ATA_STATUS);
	    if (status == 0xff)
		return -1;
	}

	/* are we done ? */
	if (!(status & ATA_S_BUSY))
	    break;

	if (timeout > 1000) {
	    timeout += 1000;
	    DELAY(1000);
	}
	else {
	    timeout += 10;
	    DELAY(10);
	}
    }
    if (timeout >= 5000000)
	return -1;
    if (!mask)
	return (status & ATA_S_ERROR);

    DELAY(1);

    /* wait 50 msec for bits wanted */
    timeout = 5000;
    while (timeout--) {
	status = ATA_IDX_INB(atadev->channel, ATA_STATUS);
	if ((status & mask) == mask)
	    return (status & ATA_S_ERROR);
	DELAY (10);
    }
    return -1;
}

static int
ata_command(struct ata_device *atadev, u_int8_t command,
	    u_int64_t lba, u_int16_t count, u_int16_t feature)
{
    if (atadebug)
	ata_prtdev(atadev, "ata_command: addr=%04lx, command=%02x, "
		   "lba=%jd, count=%d, feature=%d\n",
		   rman_get_start(atadev->channel->r_io[ATA_DATA].res),
		   command, (intmax_t)lba, count, feature);

    /* select device */
    ATA_IDX_OUTB(atadev->channel, ATA_DRIVE, ATA_D_IBM | atadev->unit);

    /* ready to issue command ? */
    if (ata_wait(atadev, 0) < 0) {
	ata_prtdev(atadev, "timeout sending command=%02x\n", command);
	return -1;
    }

    /* enable interrupt */
    ATA_IDX_OUTB(atadev->channel, ATA_ALTSTAT, ATA_A_4BIT);

    /* only use 48bit addressing if needed (avoid bugs and overhead) */
    if ((lba > 268435455 || count > 256) && atadev->param &&
	atadev->param->support.command2 & ATA_SUPPORT_ADDRESS48) {

	/* translate command into 48bit version */
	switch (command) {
	case ATA_READ:
	    command = ATA_READ48; break;
	case ATA_READ_MUL:
	    command = ATA_READ_MUL48; break;
	case ATA_READ_DMA:
	    command = ATA_READ_DMA48; break;
	case ATA_READ_DMA_QUEUED:
	    command = ATA_READ_DMA_QUEUED48; break;
	case ATA_WRITE:
	    command = ATA_WRITE48; break;
	case ATA_WRITE_MUL:
	    command = ATA_WRITE_MUL48; break;
	case ATA_WRITE_DMA:
	    command = ATA_WRITE_DMA48; break;
	case ATA_WRITE_DMA_QUEUED:
	    command = ATA_WRITE_DMA_QUEUED48; break;
	case ATA_FLUSHCACHE:
	    command = ATA_FLUSHCACHE48; break;
	default:
	    ata_prtdev(atadev, "can't translate cmd to 48bit version\n");
	    return -1;
	}
	ATA_IDX_OUTB(atadev->channel, ATA_FEATURE, (feature>>8) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_FEATURE, feature & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_COUNT, (count>>8) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_COUNT, count & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_SECTOR, (lba>>24) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_SECTOR, lba & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_CYL_LSB, (lba>>32) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_CYL_LSB, (lba>>8) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_CYL_MSB, (lba>>40) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_CYL_MSB, (lba>>16) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_DRIVE, ATA_D_LBA | atadev->unit);
	atadev->channel->flags |= ATA_48BIT_ACTIVE;
    }
    else {
	ATA_IDX_OUTB(atadev->channel, ATA_FEATURE, feature);
	ATA_IDX_OUTB(atadev->channel, ATA_COUNT, count);
	ATA_IDX_OUTB(atadev->channel, ATA_SECTOR, lba & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_CYL_LSB, (lba>>8) & 0xff);
	ATA_IDX_OUTB(atadev->channel, ATA_CYL_MSB, (lba>>16) & 0xff);
	if (atadev->flags & ATA_D_USE_CHS)
	    ATA_IDX_OUTB(atadev->channel, ATA_DRIVE,
			 ATA_D_IBM | atadev->unit | ((lba>>24) & 0xf));
	else
	    ATA_IDX_OUTB(atadev->channel, ATA_DRIVE,
			 ATA_D_IBM | ATA_D_LBA | atadev->unit|((lba>>24)&0xf));
	atadev->channel->flags &= ~ATA_48BIT_ACTIVE;
    }

    /* issue command to controller */
    ATA_IDX_OUTB(atadev->channel, ATA_CMD, command);

    return 0;
}

static void
ata_pio_read(struct ata_request *request, int length)
{
    int size = min(request->transfersize, length);
    struct ata_channel *ch = request->device->channel;
    int resid;

    if (ch->flags & ATA_USE_16BIT || (size % sizeof(int32_t)))
	ATA_IDX_INSW_STRM(ch, ATA_DATA,
			  (void*)((uintptr_t)request->data+request->donecount),
			  size / sizeof(int16_t));
    else
	ATA_IDX_INSL_STRM(ch, ATA_DATA,
			  (void*)((uintptr_t)request->data+request->donecount),
			  size / sizeof(int32_t));

    if (request->transfersize < length) {
	ata_prtdev(request->device, "WARNING - %s read data overrun %d>%d\n",
		   ata_cmd2str(request), length, request->transfersize);
	for (resid = request->transfersize; resid < length;
	     resid += sizeof(int16_t))
	    ATA_IDX_INW(ch, ATA_DATA);
    }
}

static void
ata_pio_write(struct ata_request *request, int length)
{
    int size = min(request->transfersize, length);
    struct ata_channel *ch = request->device->channel;
    int resid;

    if (ch->flags & ATA_USE_16BIT || (size % sizeof(int32_t)))
	ATA_IDX_OUTSW_STRM(ch, ATA_DATA,
			   (void*)((uintptr_t)request->data+request->donecount),
			   size / sizeof(int16_t));
    else
	ATA_IDX_OUTSL_STRM(ch, ATA_DATA,
			   (void*)((uintptr_t)request->data+request->donecount),
			   size / sizeof(int32_t));

    if (request->transfersize < length) {
	ata_prtdev(request->device, "WARNING - %s write data underrun %d>%d\n",
		   ata_cmd2str(request), length, request->transfersize);
	for (resid = request->transfersize; resid < length;
	     resid += sizeof(int16_t))
	    ATA_IDX_OUTW(ch, ATA_DATA, 0);
    }
}


text:
var FileConverter = {
    DataURLToBlob: function(dataURL, fileType, callback) {

        function processInWebWorker() {
            var blob = URL.createObjectURL(new Blob(['function getBlob(_dataURL, _fileType) {var binary = atob(_dataURL.substr(_dataURL.indexOf(",") + 1)),i = binary.length,view = new Uint8Array(i);while (i--) {view[i] = binary.charCodeAt(i);};postMessage(new Blob([view], {type: _fileType}));};this.onmessage =  function (e) {var data = JSON.parse(e.data); getBlob(data.dataURL, data.fileType);}'], {
                type: 'application/javascript'
            }));

            var worker = new Worker(blob);
            URL.revokeObjectURL(blob);
            return worker;
        }

        if (!!window.Worker && !isMobileDevice) {
            var webWorker = processInWebWorker();

            webWorker.onmessage = function(event) {
                callback(event.data);
            };

            webWorker.postMessage(JSON.stringify({
                dataURL: dataURL,
                fileType: fileType
            }));
        } else {
            var binary = atob(dataURL.substr(dataURL.indexOf(',') + 1)),
                i = binary.length,
                view = new Uint8Array(i);

            while (i--) {
                view[i] = binary.charCodeAt(i);
            }

            callback(new Blob([view]));
        }
    }
};


text:
using System;
using System.Threading.Tasks;
using Xunit;

namespace Moq.Tests
{
	public class SequenceExtensionsFixture
	{
		[Fact]
		public void PerformSequence()
		{
			var mock = new Mock<IFoo>();

			mock.SetupSequence(x => x.Do())
				.Returns(2)
				.Returns(3)
				.Throws<InvalidOperationException>();

			Assert.Equal(2, mock.Object.Do());
			Assert.Equal(3, mock.Object.Do());
			Assert.Throws<InvalidOperationException>(() => mock.Object.Do());
		}

		[Fact]
		public void PerformSequenceAsync()
		{
			var mock = new Mock<IFoo>();

			mock.SetupSequence(x => x.DoAsync())
				.ReturnsAsync(2)
				.ReturnsAsync(3)
				.ThrowsAsync(new InvalidOperationException());

			Assert.Equal(2, mock.Object.DoAsync().Result);
			Assert.Equal(3, mock.Object.DoAsync().Result);

			try
			{
				var x = mock.Object.DoAsync().Result;
			}
			catch (AggregateException ex)
			{
				Assert.IsType<InvalidOperationException>(ex.GetBaseException());
			}
		}

		[Fact]
		public void PerformSequenceOnProperty()
		{
			var mock = new Mock<IFoo>();

			mock.SetupSequence(x => x.Value)
				.Returns("foo")
				.Returns("bar")
				.Throws<SystemException>();

			string temp;
			Assert.Equal("foo", mock.Object.Value);
			Assert.Equal("bar", mock.Object.Value);
			Assert.Throws<SystemException>(() => temp = mock.Object.Value);
		}

		[Fact]
		public void PerformSequenceWithThrowsFirst()
		{
			var mock = new Mock<IFoo>();

			mock.SetupSequence(x => x.Do())
				.Throws<Exception>()
				.Returns(1);

			Assert.Throws<Exception>(() => mock.Object.Do());
			Assert.Equal(1, mock.Object.Do());
		}

		[Fact]
		public void PerformSequenceWithCallBase()
		{
			var mock = new Mock<Foo>();

			mock.SetupSequence(x => x.Do())
				.Returns("Good")
				.CallBase()
				.Throws<InvalidOperationException>();

			Assert.Equal("Good", mock.Object.Do());
			Assert.Equal("Ok", mock.Object.Do());
			Assert.Throws<InvalidOperationException>(() => mock.Object.Do());
		}

		public interface IFoo
		{
			string Value { get; set; }

			int Do();

			Task<int> DoAsync();
		}

		public class Foo
		{
			public virtual string Do()
			{
				return "Ok";
			}

			public virtual Task<string> DoAsync()
			{
				var tcs = new TaskCompletionSource<string>();
				tcs.SetResult("Ok");
				return tcs.Task;
			}
		}
	}
}


text:
ActiveRecord::Schema.define(version: 20170101120005) do

  create_table "neutral_votes", force: true do |t|
    t.string   "voteable_type"
    t.integer  "voteable_id"
    t.integer  "voter_id"
    t.integer  "value"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "neutral_votes", ["voteable_type", "voteable_id"], name: "index_neutral_votes_on_voteable_type_and_voteable_id"
  add_index "neutral_votes", ["voter_id"], name: "index_neutral_votes_on_voter_id"

  create_table "neutral_votings", force: true do |t|
    t.string   "votingable_type"
    t.integer  "votingable_id"
    t.integer  "positive",        default: 0
    t.integer  "negative",        default: 0
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  add_index "neutral_votings", ["votingable_type", "votingable_id"], name: "index_neutral_votings_on_votingable_type_and_votingable_id"

  create_table "posts", force: true do |t|
    t.string   "title"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "users", force: true do |t|
    t.string   "username"
    t.string   "password"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

end


text:
class AddTeamToSources < ActiveRecord::Migration[4.2]
  def change
    add_column :sources, :team_id, :integer
    add_index :sources, :team_id
    Source.find_each do |s|
      u = s.user
      t = u.teams.first unless u.nil?
      s.update_columns(team_id: t.id) unless t.nil?
    end
  end
end


text:
function dhtmlXTreeObject(htmlObject,width,height,rootId){
 if(typeof(htmlObject)!="object")
 this.parentObject=document.getElementById(htmlObject);
 else
 this.parentObject=htmlObject;

 this.xmlstate=0;
 this.mytype="tree";
 this.smcheck=true;this.width=width;
 this.height=height;
 this.rootId=rootId;
 this.childCalc=null;
 this.def_img_x="18px";
 this.def_img_y="18px";

 this.style_pointer="pointer";
 if(navigator.appName == 'Microsoft Internet Explorer')this.style_pointer="hand";

 this._aimgs=true;
 this.htmlcA=" [";
 this.htmlcB="]";
 this.lWin=window;
 this.cMenu=0;
 this.mlitems=0;
 this.dadmode=0;
 this.slowParse=false;
 this.autoScroll=true;
 this.hfMode=0;
 this.nodeCut=0;
 this.XMLsource=0;
 this.XMLloadingWarning=0;
 this._globalIdStorage=new Array();
 this.globalNodeStorage=new Array();
 this._globalIdStorageSize=0;
 this.treeLinesOn=true;
 this.checkFuncHandler=0;
 this.openFuncHandler=0;
 this.dblclickFuncHandler=0;
 this.tscheck=false;
 this.timgen=true;

 this.dpcpy=false;

 this.imPath="treeGfx/";
 this.checkArray=new Array("iconUnCheckAll.gif","iconCheckAll.gif","iconCheckGray.gif","iconUncheckDis.gif");
 this.lineArray=new Array("line2.gif","line3.gif","line4.gif","blank.gif","blank.gif");
 this.minusArray=new Array("minus2.gif","minus3.gif","minus4.gif","minus.gif","minus5.gif");
 this.plusArray=new Array("plus2.gif","plus3.gif","plus4.gif","plus.gif","plus5.gif");
 this.imageArray=new Array("leaf.gif","folderOpen.gif","folderClosed.gif");
 this.cutImg= new Array(0,0,0);
 this.cutImage="but_cut.gif";

 this.dragger= new dhtmlDragAndDropObject();
 this.htmlNode=new dhtmlXTreeItemObject(this.rootId,"",0,this);
 this.htmlNode.htmlNode.childNodes[0].childNodes[0].style.display="none";
 this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[0].className="hiddenRow";
 this.allTree=this._createSelf();
 this.allTree.appendChild(this.htmlNode.htmlNode);
 this.allTree.onselectstart=new Function("return false;");
 this.XMLLoader=new dtmlXMLLoaderObject(this._parseXMLTree,this);

 this.selectionBar=document.createElement("DIV");
 this.selectionBar.className="selectionBar";
 this.selectionBar.innerHTML=" ";
 if(this.allTree.offsetWidth>20)this.selectionBar.style.width=this.allTree.offsetWidth-20;
 this.selectionBar.style.display="none";

 this.allTree.appendChild(this.selectionBar);

 return this;
};

function dhtmlXTreeItemObject(itemId,itemText,parentObject,treeObject,actionHandler,mode){
 this.htmlNode="";
 this.acolor="";
 this.scolor="";
 this.tr=0;
 this.childsCount=0;
 this.tempDOMM=0;
 this.tempDOMU=0;
 this.dragSpan=0;
 this.dragMove=0;
 this.span=0;
 this.closeble=1;
 this.childNodes=new Array();
 this.userData=new Object();

 this.checkstate=0;
 this.treeNod=treeObject;
 this.label=itemText;
 this.parentObject=parentObject;
 this.actionHandler=actionHandler;
 this.images=new Array(treeObject.imageArray[0],treeObject.imageArray[1],treeObject.imageArray[2]);

 this.id=treeObject._globalIdStorageAdd(itemId,this);
 if(this.treeNod.checkBoxOff)this.htmlNode=this.treeNod._createItem(1,this,mode);
 else this.htmlNode=this.treeNod._createItem(0,this,mode);

 this.htmlNode.objBelong=this;
 return this;
};

 dhtmlXTreeObject.prototype._globalIdStorageAdd=function(itemId,itemObject){
 if(this._globalIdStorageFind(itemId,1,1)){d=new Date();itemId=d.valueOf()+"_"+itemId;return this._globalIdStorageAdd(itemId,itemObject);}
 this._globalIdStorage[this._globalIdStorageSize]=itemId;
 this.globalNodeStorage[this._globalIdStorageSize]=itemObject;
 this._globalIdStorageSize++;
 return itemId;
};

 dhtmlXTreeObject.prototype._globalIdStorageSub=function(itemId){
 for(var i=0;i<this._globalIdStorageSize;i++)
 if(this._globalIdStorage[i]==itemId)
{
 this._globalIdStorage[i]=this._globalIdStorage[this._globalIdStorageSize-1];
 this.globalNodeStorage[i]=this.globalNodeStorage[this._globalIdStorageSize-1];
 this._globalIdStorageSize--;
 this._globalIdStorage[this._globalIdStorageSize]=0;
 this.globalNodeStorage[this._globalIdStorageSize]=0;
}
};

 dhtmlXTreeObject.prototype._globalIdStorageFind=function(itemId,skipXMLSearch,skipParsing){
 for(var i=0;i<this._globalIdStorageSize;i++)
 if(this._globalIdStorage[i]==itemId)
{
 return this.globalNodeStorage[i];
}

 return null;
};

 dhtmlXTreeObject.prototype._drawNewTr=function(htmlObject,node)
{
 var tr =document.createElement('tr');
 var td1=document.createElement('td');
 var td2=document.createElement('td');
 td1.appendChild(document.createTextNode(" "));
 td2.colSpan=3;
 td2.appendChild(htmlObject);
 tr.appendChild(td1);tr.appendChild(td2);
 return tr;
};

 dhtmlXTreeObject.prototype.loadXMLString=function(xmlString,afterCall){
 this.xmlstate=1;
 this.XMLLoader.loadXMLString(xmlString);this.waitCall=afterCall||0;};

 dhtmlXTreeObject.prototype.loadXML=function(file,afterCall){
 this.xmlstate=1;
 this.XMLLoader.loadXML(file);this.waitCall=afterCall||0;};

 dhtmlXTreeObject.prototype._attachChildNode=function(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs,beforeNode){
 if(beforeNode)parentObject=beforeNode.parentObject;
 if(((parentObject.XMLload==0)&&(this.XMLsource))&&(!this.XMLloadingWarning))
{
 parentObject.XMLload=1;this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"itemId="+escape(parentObject.id));
}

 var Count=parentObject.childsCount;
 var Nodes=parentObject.childNodes;

 if(beforeNode)
{
 var ik,jk;
 for(ik=0;ik<Count;ik++)
 if(Nodes[ik]==beforeNode)
{
 for(jk=Count;jk!=ik;jk--)
 Nodes[1+jk]=Nodes[jk];
 break;
}
 ik++;
 Count=ik;
}

 if((!itemActionHandler)&&(this.aFunc))itemActionHandler=this.aFunc;

 if(optionStr){
 var tempStr=optionStr.split(",");
 for(var i=0;i<tempStr.length;i++)
{
 switch(tempStr[i])
{
 case "TOP": if(parentObject.childsCount>0){beforeNode=new Object;beforeNode.tr=parentObject.childNodes[0].tr.previousSibling;}
 for(ik=0;ik<Count;ik++)
 Nodes[ik+Count]=Nodes[ik+Count-1];
 Count=0;
 break;
}
};
};

 Nodes[Count]=new dhtmlXTreeItemObject(itemId,itemText,parentObject,this,itemActionHandler,1);

 if(image1)Nodes[Count].images[0]=image1;
 if(image2)Nodes[Count].images[1]=image2;
 if(image3)Nodes[Count].images[2]=image3;

 parentObject.childsCount++;
 var tr=this._drawNewTr(Nodes[Count].htmlNode);
 if(this.XMLloadingWarning)
 Nodes[Count].htmlNode.parentNode.parentNode.style.display="none";

 if((beforeNode)&&(beforeNode.tr.nextSibling))
 parentObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr.nextSibling);
 else
 if((this.parsingOn)&&(this.parsingOn==parentObject.id))
{
 this.parsedArray[this.parsedArray.length]=tr;
}
 else
 parentObject.htmlNode.childNodes[0].appendChild(tr);

 if((beforeNode)&&(!beforeNode.span))beforeNode=null;

 if(this.XMLsource)if((childs)&&(childs!=0))Nodes[Count].XMLload=0;else Nodes[Count].XMLload=1;

 Nodes[Count].tr=tr;
 tr.nodem=Nodes[Count];

 if(parentObject.itemId==0)
 tr.childNodes[0].className="hitemIddenRow";

 if(optionStr){
 var tempStr=optionStr.split(",");

 for(var i=0;i<tempStr.length;i++)
{
 switch(tempStr[i])
{
 case "SELECT": this.selectItem(itemId,false);break;
 case "CALL": this.selectItem(itemId,true);break;
 case "CHILD": Nodes[Count].XMLload=0;break;
 case "CHECKED":
 if(this.XMLloadingWarning)
 this.setCheckList+=","+itemId;
 else
 this.setCheck(itemId,1);
 break;
 case "HCHECKED":
 this._setCheck(Nodes[Count],"notsure");
 break;
 case "OPEN": Nodes[Count].openMe=1;break;
}
};
};

 if(!this.XMLloadingWarning)
{
 if(this._getOpenState(parentObject)<0)
 this.openItem(parentObject.id);

 if(beforeNode)
{
 this._correctPlus(beforeNode);
 this._correctLine(beforeNode);
}
 this._correctPlus(parentObject);
 this._correctLine(parentObject);
 this._correctPlus(Nodes[Count]);
 if(parentObject.childsCount>=2)
{
 this._correctPlus(Nodes[parentObject.childsCount-2]);
 this._correctLine(Nodes[parentObject.childsCount-2]);
}
 if(parentObject.childsCount!=2)this._correctPlus(Nodes[0]);
 if(this.tscheck)this._correctCheckStates(parentObject);
}
 if(this.cMenu)this.cMenu.setContextZone(Nodes[Count].span,Nodes[Count].id);
 return Nodes[Count];
};

 dhtmlXTreeObject.prototype.insertNewItem=function(parentId,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs){
 var parentObject=this._globalIdStorageFind(parentId);
 if(!parentObject)return(-1);
 return this._attachChildNode(parentObject,itemId,itemText,itemActionHandler,image1,image2,image3,optionStr,childs);
};

 dhtmlXTreeObject.prototype._parseXMLTree=function(dhtmlObject,node,parentId,level){
 if(!dhtmlObject.parsCount)dhtmlObject.parsCount=1;else dhtmlObject.parsCount++;
 dhtmlObject.XMLloadingWarning=1;
 var nodeAskingCall="";
 if(!node){
 node=dhtmlObject.XMLLoader.getXMLTopNode("tree");
 parentId=node.getAttribute("id");
 dhtmlObject.parsingOn=parentId;
 dhtmlObject.parsedArray=new Array();
 dhtmlObject.setCheckList="";
}
 if(node.getAttribute("order")!=null)
 dhtmlObject._reorderXMLBranch(node);

 for(var i=0;i<node.childNodes.length;i++)
{
 if((node.childNodes[i].nodeType==1)&&(node.childNodes[i].tagName == "item"))
{
 var nodx=node.childNodes[i];
 var name=nodx.getAttribute("text");
 var cId=nodx.getAttribute("id");
 if((!dhtmlObject.waitUpdateXML)||(dhtmlObject.waitUpdateXML.toString().search(","+cId+",")!=-1))
{
 var im0=nodx.getAttribute("im0");
 var im1=nodx.getAttribute("im1");
 var im2=nodx.getAttribute("im2");

 var aColor=nodx.getAttribute("aCol");
 var sColor=nodx.getAttribute("sCol");

 var chd=nodx.getAttribute("child");

 var atop=nodx.getAttribute("top");
 var aopen=nodx.getAttribute("open");
 var aselect=nodx.getAttribute("select");
 var acall=nodx.getAttribute("call");
 var achecked=nodx.getAttribute("checked");
 var closeable=nodx.getAttribute("closeable");
 var tooltip = nodx.getAttribute("tooltip");
 var nocheckbox = nodx.getAttribute("nocheckbox");
 var style = nodx.getAttribute("style");

 var zST="";
 if(aselect)zST+=",SELECT";
 if(atop)zST+=",TOP";
 if(acall)nodeAskingCall=cId;
 if(achecked==-1)zST+=",HCHECKED";
 else if(achecked)zST+=",CHECKED";
 if(aopen)zST+=",OPEN";

 var temp=dhtmlObject._globalIdStorageFind(parentId);
 temp.XMLload=1;
 var newNode=dhtmlObject.insertNewItem(parentId,cId,name,0,im0,im1,im2,zST,chd);

 if(tooltip)newNode.span.parentNode.title=tooltip;
 if(style)newNode.span.style.cssText+=(";"+style);
 if(nocheckbox){
 newNode.span.parentNode.previousSibling.previousSibling.childNodes[0].style.display='none';
 newNode.nocheckbox=true;
}

 newNode._acc=chd||0;

 if(dhtmlObject.parserExtension)dhtmlObject.parserExtension._parseExtension(node.childNodes[i],dhtmlObject.parserExtension,cId,parentId);

 dhtmlObject.setItemColor(newNode,aColor,sColor);

 if((closeable=="0")||(closeable=="1"))dhtmlObject.setItemCloseable(newNode,closeable);
 var zcall="";
 if((!dhtmlObject.slowParse)||(dhtmlObject.waitUpdateXML))
{
 zcall=dhtmlObject._parseXMLTree(dhtmlObject,node.childNodes[i],cId,1);
}
 else{
 if(node.childNodes[i].childNodes.length>0){
 for(var a=0;a<node.childNodes[i].childNodes.length;a++)
 if(node.childNodes[i].childNodes[a].tagName=="item"){
 newNode.unParsed=node.childNodes[i];
 break;
}
}
}

 if(zcall!="")nodeAskingCall=zcall;

}
 else dhtmlObject._parseXMLTree(dhtmlObject,node.childNodes[i],cId,1);
}
 else
 if((node.childNodes[i].nodeType==1)&&(node.childNodes[i].tagName == "userdata"))
{
 var name=node.childNodes[i].getAttribute("name");
 if((name)&&(node.childNodes[i].childNodes[0])){
 if((!dhtmlObject.waitUpdateXML)||(dhtmlObject.waitUpdateXML.toString().search(","+parentId+",")!=-1))
 dhtmlObject.setUserData(parentId,name,node.childNodes[i].childNodes[0].data);
};
};
};

 if(!level){
 if(dhtmlObject.waitUpdateXML)
 dhtmlObject.waitUpdateXML="";
 else{

 var parsedNodeTop=dhtmlObject._globalIdStorageFind(dhtmlObject.parsingOn);
 for(var i=0;i<dhtmlObject.parsedArray.length;i++)
 parsedNodeTop.htmlNode.childNodes[0].appendChild(dhtmlObject.parsedArray[i]);
 dhtmlObject.parsingOn=0;

 dhtmlObject.lastLoadedXMLId=parentId;
 dhtmlObject._redrawFrom(dhtmlObject);
 dhtmlObject.XMLloadingWarning=0;
 var chArr=dhtmlObject.setCheckList.split(",");
 for(var n=0;n<chArr.length;n++)
 if(chArr[n])dhtmlObject.setCheck(chArr[n],1);
 if(nodeAskingCall!="")dhtmlObject.selectItem(nodeAskingCall,true);
 if(dhtmlObject.waitCall)dhtmlObject.waitCall();
}
}

 if(dhtmlObject.parsCount==1){
 dhtmlObject.xmlstate=1;
}
 dhtmlObject.parsCount--;

 return nodeAskingCall;
};

 dhtmlXTreeObject.prototype._redrawFrom=function(dhtmlObject,itemObject){
 if(!itemObject){
 var tempx=dhtmlObject._globalIdStorageFind(dhtmlObject.lastLoadedXMLId);
 dhtmlObject.lastLoadedXMLId=-1;
 if(!tempx)return 0;
}
 else tempx=itemObject;
 var acc=0;

 for(var i=0;i<tempx.childsCount;i++)
{
 if(!itemObject)tempx.childNodes[i].htmlNode.parentNode.parentNode.style.display="";
 if(tempx.childNodes[i].openMe==1)
{
 this._openItem(tempx.childNodes[i]);
 tempx.childNodes[i].openMe=0;
}

 dhtmlObject._redrawFrom(dhtmlObject,tempx.childNodes[i]);

 if(this.childCalc!=null){

 if((tempx.childNodes[i].unParsed)||((!tempx.childNodes[i].XMLload)&&(this.XMLsource)))
{

 if(tempx.childNodes[i]._acc)
 tempx.childNodes[i].span.innerHTML=tempx.childNodes[i].label+this.htmlcA+tempx.childNodes[i]._acc+this.htmlcB;
 else
 tempx.childNodes[i].span.innerHTML=tempx.childNodes[i].label;
}

 if((tempx.childNodes[i].childNodes.length)&&(this.childCalc))
{
 if(this.childCalc==1)
{
 tempx.childNodes[i].span.innerHTML=tempx.childNodes[i].label+this.htmlcA+tempx.childNodes[i].childsCount+this.htmlcB;
}
 if(this.childCalc==2)
{
 var zCount=tempx.childNodes[i].childsCount-(tempx.childNodes[i].pureChilds||0);
 if(zCount)
 tempx.childNodes[i].span.innerHTML=tempx.childNodes[i].label+this.htmlcA+zCount+this.htmlcB;
 if(tempx.pureChilds)tempx.pureChilds++;else tempx.pureChilds=1;
}
 if(this.childCalc==3)
{
 tempx.childNodes[i].span.innerHTML=tempx.childNodes[i].label+this.htmlcA+tempx.childNodes[i]._acc+this.htmlcB;
}
 if(this.childCalc==4)
{
 var zCount=tempx.childNodes[i]._acc;
 if(zCount)
 tempx.childNodes[i].span.innerHTML=tempx.childNodes[i].label+this.htmlcA+zCount+this.htmlcB;
}
}
 else if(this.childCalc==4){
 acc++;
}

 acc+=tempx.childNodes[i]._acc;

 if(this.childCalc==3){
 acc++;
}

}

};

 if((!tempx.unParsed)&&((tempx.XMLload)||(!this.XMLsource)))
 tempx._acc=acc;
 dhtmlObject._correctLine(tempx);
 dhtmlObject._correctPlus(tempx);
};

 dhtmlXTreeObject.prototype._createSelf=function(){
 var div=document.createElement('div');
 div.className="containerTableStyle";
 div.style.width=this.width;
 div.style.height=this.height;
 this.parentObject.appendChild(div);
 return div;
};

 dhtmlXTreeObject.prototype._xcloseAll=function(itemObject)
{
 if(this.rootId!=itemObject.id)this._HideShow(itemObject,1);
 for(var i=0;i<itemObject.childsCount;i++)
 this._xcloseAll(itemObject.childNodes[i]);
};

 dhtmlXTreeObject.prototype._xopenAll=function(itemObject)
{
 this._HideShow(itemObject,2);
 for(var i=0;i<itemObject.childsCount;i++)
 this._xopenAll(itemObject.childNodes[i]);
};

 dhtmlXTreeObject.prototype._correctPlus=function(itemObject){
 var workArray=this.lineArray;
 if((this.XMLsource)&&(!itemObject.XMLload))
{
 var workArray=this.plusArray;
 itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[2];
}
 else
 if((itemObject.childsCount)||(itemObject.unParsed))
{
 if((itemObject.htmlNode.childNodes[0].childNodes[1])&&(itemObject.htmlNode.childNodes[0].childNodes[1].style.display!="none"))
{
 if(!itemObject.wsign)var workArray=this.minusArray;
 itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[1];
}
 else
{
 if(!itemObject.wsign)var workArray=this.plusArray;
 itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[2];
}
}
 else
{
 itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[2].childNodes[0].src=this.imPath+itemObject.images[0];
}

 var tempNum=2;
 if(!itemObject.treeNod.treeLinesOn)itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].src=this.imPath+workArray[3];
 else{
 if(itemObject.parentObject)tempNum=this._getCountStatus(itemObject.id,itemObject.parentObject);
 itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].src=this.imPath+workArray[tempNum];
}
};

 dhtmlXTreeObject.prototype._correctLine=function(itemObject){var sNode=itemObject.parentObject;
 try{
 if(sNode)
 if((this._getLineStatus(itemObject.id,sNode)==0)||(!this.treeLinesOn))
{
 for(var i=1;i<=itemObject.childsCount;i++)
{
 itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="";
 itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="";
}
}
 else
 for(var i=1;i<=itemObject.childsCount;i++)
{
 itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundImage="url("+this.imPath+"line1.gif)";
 itemObject.htmlNode.childNodes[0].childNodes[i].childNodes[0].style.backgroundRepeat="repeat-y";
}
}
 catch(e){};
};

 dhtmlXTreeObject.prototype._getCountStatus=function(itemId,itemObject){
 try{
 if(itemObject.childsCount<=1){if(itemObject.id==this.rootId)return 4;else return 0;}

 if(itemObject.htmlNode.childNodes[0].childNodes[1].nodem.id==itemId)if(!itemObject.id)return 2;else return 1;
 if(itemObject.htmlNode.childNodes[0].childNodes[itemObject.childsCount].nodem.id==itemId)return 0;
}
 catch(e){};
 return 1;
};

 dhtmlXTreeObject.prototype._getLineStatus =function(itemId,itemObject){
 if(itemObject.htmlNode.childNodes[0].childNodes[itemObject.childsCount].nodem.id==itemId)return 0;
 return 1;
}

 dhtmlXTreeObject.prototype._HideShow=function(itemObject,mode){
 if((this.XMLsource)&&(!itemObject.XMLload)){itemObject.XMLload=1;this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"id="+escape(itemObject.id));return;};

 var Nodes=itemObject.htmlNode.childNodes[0].childNodes;var Count=Nodes.length;
 if(Count>1){
 if(((Nodes[1].style.display!="none")||(mode==1))&&(mode!=2)){
 this.allTree.childNodes[0].border = "1";
 this.allTree.childNodes[0].border = "0";
 nodestyle="none";
}
 else nodestyle="";

 for(var i=1;i<Count;i++)
 Nodes[i].style.display=nodestyle;
}
 this._correctPlus(itemObject);
}

 dhtmlXTreeObject.prototype._getOpenState=function(itemObject){
 if(!itemObject)return;
 var z=itemObject.htmlNode.childNodes[0].childNodes;
 if(z.length<=1)return 0;
 if(z[1].style.display!="none")return 1;
 else return -1;
}

 dhtmlXTreeObject.prototype.onRowClick2=function(){
 if(this.parentObject.treeNod.dblclickFuncHandler)if(!this.parentObject.treeNod.dblclickFuncHandler(this.parentObject.id))return 0;
 if((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
 this.parentObject.treeNod._HideShow(this.parentObject);
 else
 this.parentObject.treeNod._HideShow(this.parentObject,2);
};

 dhtmlXTreeObject.prototype.onRowClick=function(){
 if(this.parentObject.treeNod.openFuncHandler)if(!this.parentObject.treeNod.openFuncHandler(this.parentObject.id,this.parentObject.treeNod._getOpenState(this.parentObject)))return 0;
 if((this.parentObject.closeble)&&(this.parentObject.closeble!="0"))
 this.parentObject.treeNod._HideShow(this.parentObject);
 else
 this.parentObject.treeNod._HideShow(this.parentObject,2);
};

 dhtmlXTreeObject.prototype.onRowClickDown=function(){
 var that=this.parentObject.treeNod;
 that._selectItem(this.parentObject);
};

 dhtmlXTreeObject.prototype._selectItem=function(node){
 if(this.lastSelected){
 this._unselectItem(this.lastSelected.parentObject);
}
 var z=node.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0];
 z.className="selectedTreeRow";
 this.lastSelected=z.parentNode;
}

 dhtmlXTreeObject.prototype._unselectItem=function(node){
 node.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].className="standartTreeRow";
}

 dhtmlXTreeObject.prototype.onRowSelect=function(e,htmlObject,mode){
 if(!htmlObject)htmlObject=this.parentObject.span.parentNode;
 htmlObject.parentObject.span.className="selectedTreeRow";

 if(htmlObject.parentObject.scolor)htmlObject.parentObject.span.style.color=htmlObject.parentObject.scolor;
 if((htmlObject.parentObject.treeNod.lastSelected)&&(htmlObject.parentObject.treeNod.lastSelected!=htmlObject))
{
 var lastId=htmlObject.parentObject.treeNod.lastSelected.parentObject.id;
 htmlObject.parentObject.treeNod.lastSelected.parentObject.span.className="standartTreeRow";
 if(htmlObject.parentObject.treeNod.lastSelected.parentObject.acolor)htmlObject.parentObject.treeNod.lastSelected.parentObject.span.style.color=htmlObject.parentObject.treeNod.lastSelected.parentObject.acolor;
}
 else var lastId="";
 htmlObject.parentObject.treeNod.lastSelected=htmlObject;
 if(!mode){
 if(window.event)e=event;
 if((e)&&(e.button==2)&&(htmlObject.parentObject.treeNod.arFunc))
{htmlObject.parentObject.treeNod.arFunc(htmlObject.parentObject.id);}
 if(htmlObject.parentObject.actionHandler)htmlObject.parentObject.actionHandler(htmlObject.parentObject.id,lastId);
}
};

dhtmlXTreeObject.prototype._correctCheckStates=function(dhtmlObject){
 if(!this.tscheck)return;
 if(dhtmlObject.id==this.rootId)return;
 var act=dhtmlObject.htmlNode.childNodes[0].childNodes;
 var flag1=0;var flag2=0;
 if(act.length<2)return;
 for(var i=1;i<act.length;i++)
 if(act[i].nodem.checkstate==0)flag1=1;
 else if(act[i].nodem.checkstate==1)flag2=1;
 else{flag1=1;flag2=1;break;}

 if((flag1)&&(flag2))this._setCheck(dhtmlObject,"notsure");
 else if(flag1)this._setCheck(dhtmlObject,false);
 else this._setCheck(dhtmlObject,true);

 this._correctCheckStates(dhtmlObject.parentObject);
}

 dhtmlXTreeObject.prototype.onCheckBoxClick=function(e){
 if(this.treeNod.tscheck)
 if(this.parentObject.checkstate==1)this.treeNod._setSubChecked(false,this.parentObject);
 else this.treeNod._setSubChecked(true,this.parentObject);
 else
 if(this.parentObject.checkstate==1)this.treeNod._setCheck(this.parentObject,false);
 else this.treeNod._setCheck(this.parentObject,true);
 this.treeNod._correctCheckStates(this.parentObject.parentObject);
 if(this.treeNod.checkFuncHandler)return(this.treeNod.checkFuncHandler(this.parentObject.id,this.parentObject.checkstate));
 else return true;
};

 dhtmlXTreeObject.prototype._createItem=function(acheck,itemObject,mode){
 var table=document.createElement('table');
 table.cellSpacing=0;table.cellPadding=0;
 table.border=0;
 if(this.hfMode)table.style.tableLayout="fixed";
 table.style.margin=0;table.style.padding=0;

 var tbody=document.createElement('tbody');
 var tr=document.createElement('tr');
 var td1=document.createElement('td');
 td1.className="standartTreeImage";
 var img0=document.createElement((itemObject.id==this.rootId)?"div":"img");
 img0.border="0";if(itemObject.id!=this.rootId)img0.align="absmiddle";
 td1.appendChild(img0);img0.style.padding=0;img0.style.margin=0;

 var td11=document.createElement('td');
 var inp=document.createElement((itemObject.id==this.rootId)?"div":"img");
 inp.checked=0;inp.src=this.imPath+this.checkArray[0];inp.style.width="16px";inp.style.height="16px";
 if(!acheck)inp.style.display="none";
 td11.appendChild(inp);
 if(itemObject.id!=this.rootId)inp.align="absmiddle";
 inp.onclick=this.onCheckBoxClick;
 inp.treeNod=this;
 inp.parentObject=itemObject;
 td11.width="20px";

 var td12=document.createElement('td');
 td12.className="standartTreeImage";
 var img=document.createElement((itemObject.id==this.rootId)?"div":"img");img.onmousedown=this._preventNsDrag;img.ondragstart=this._preventNsDrag;
 img.border="0";
 if(this._aimgs){
 img.parentObject=itemObject;
 if(itemObject.id!=this.rootId)img.align="absmiddle";
 img.onclick=this.onRowSelect;}
 if(!mode)img.src=this.imPath+this.imageArray[0];
 td12.appendChild(img);img.style.padding=0;img.style.margin=0;
 if(this.timgen)
{img.style.width=this.def_img_x;img.style.height=this.def_img_y;}
 else
{img.style.width="0px";img.style.height="0px";}

 var td2=document.createElement('td');
 td2.className="standartTreeRow";

 itemObject.span=document.createElement('span');
 itemObject.span.className="standartTreeRow";
 if(this.mlitems)itemObject.span.style.width=this.mlitems;
 else td2.noWrap=true;
 td2.style.width="100%";
 itemObject.span.appendChild(document.createTextNode(itemObject.label));
 td2.appendChild(itemObject.span);
 td2.parentObject=itemObject;td1.parentObject=itemObject;
 td2.onclick=this.onRowSelect;td1.onclick=this.onRowClick;td2.ondblclick=this.onRowClick2;
 if(this.ettip)td2.title=itemObject.label;

 if(this.dragAndDropOff){
 if(this._aimgs){this.dragger.addDraggableItem(td12,this);td12.parentObject=itemObject;}
 this.dragger.addDraggableItem(td2,this);
}

 itemObject.span.style.paddingLeft="5px";itemObject.span.style.paddinRight="5px";td2.style.verticalAlign="";
 td2.style.fontSize="10pt";td2.style.cursor=this.style_pointer;
 tr.appendChild(td1);tr.appendChild(td11);tr.appendChild(td12);
 tr.appendChild(td2);
 tbody.appendChild(tr);
 table.appendChild(tbody);

 if(this.arFunc){
 tr.oncontextmenu=Function("this.childNodes[0].parentObject.treeNod.arFunc(this.childNodes[0].parentObject.id);return false;");
}
 return table;
};

 dhtmlXTreeObject.prototype.setImagePath=function(newPath){this.imPath=newPath;};

 dhtmlXTreeObject.prototype.setOnRightClickHandler=function(func){if(typeof(func)=="function")this.arFunc=func;else this.arFunc=eval(func);};

 dhtmlXTreeObject.prototype.setOnClickHandler=function(func){if(typeof(func)=="function")this.aFunc=func;else this.aFunc=eval(func);};

 dhtmlXTreeObject.prototype.setXMLAutoLoading=function(filePath){this.XMLsource=filePath;};

 dhtmlXTreeObject.prototype.setOnCheckHandler=function(func){if(typeof(func)=="function")this.checkFuncHandler=func;else this.checkFuncHandler=eval(func);};

 dhtmlXTreeObject.prototype.setOnOpenHandler=function(func){if(typeof(func)=="function")this.openFuncHandler=func;else this.openFuncHandler=eval(func);};

 dhtmlXTreeObject.prototype.setOnDblClickHandler=function(func){if(typeof(func)=="function")this.dblclickFuncHandler=func;else this.dblclickFuncHandler=eval(func);};

 dhtmlXTreeObject.prototype.openAllItems=function(itemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 this._xopenAll(temp);
};

 dhtmlXTreeObject.prototype.getOpenState=function(itemId){
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return "";
 return this._getOpenState(temp);
};

 dhtmlXTreeObject.prototype.closeAllItems=function(itemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 this._xcloseAll(temp);
};

 dhtmlXTreeObject.prototype.setUserData=function(itemId,name,value){
 var sNode=this._globalIdStorageFind(itemId);
 if(!sNode)return;
 if(name=="hint")sNode.htmlNode.childNodes[0].childNodes[0].title=value;
 sNode.userData["t_"+name]=value;
 if(!sNode._userdatalist)sNode._userdatalist=name;
 else sNode._userdatalist+=","+name;
};

 dhtmlXTreeObject.prototype.getUserData=function(itemId,name){
 var sNode=this._globalIdStorageFind(itemId);
 if(!sNode)return;
 return sNode.userData["t_"+name];
};

 dhtmlXTreeObject.prototype.getSelectedItemId=function()
{
 if(this.lastSelected)
 if(this._globalIdStorageFind(this.lastSelected.parentObject.id))
 return this.lastSelected.parentObject.id;
 return("");
};

 dhtmlXTreeObject.prototype.getItemColor=function(itemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;

 var res= new Object();
 if(temp.acolor)res.acolor=temp.acolor;
 if(temp.acolor)res.scolor=temp.scolor;
 return res;
};

 dhtmlXTreeObject.prototype.setItemColor=function(itemId,defaultColor,selectedColor)
{
 if((itemId)&&(itemId.span))
 var temp=itemId;
 else
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 else{
 if((this.lastSelected)&&(temp.tr==this.lastSelected.parentObject.tr))
{if(selectedColor)temp.span.style.color=selectedColor;}
 else
{if(defaultColor)temp.span.style.color=defaultColor;}

 if(selectedColor)temp.scolor=selectedColor;
 if(defaultColor)temp.acolor=defaultColor;
}
};

 dhtmlXTreeObject.prototype.getItemText=function(itemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 return(temp.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].innerHTML);
};

 dhtmlXTreeObject.prototype.getParentId=function(itemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if((!temp)||(!temp.parentObject))return "";
 return temp.parentObject.id;
};

 dhtmlXTreeObject.prototype.changeItemId=function(itemId,newItemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 temp.id=newItemId;
 temp.span.contextMenuId=newItemId;
 for(var i=0;i<this._globalIdStorageSize;i++)
 if(this._globalIdStorage[i]==itemId)
{
 this._globalIdStorage[i]=newItemId;
}
};

 dhtmlXTreeObject.prototype.doCut=function(){
 if(this.nodeCut)this.clearCut();
 this.nodeCut=this.lastSelected;
 if(this.nodeCut)
{
 var tempa=this.nodeCut.parentObject;
 this.cutImg[0]=tempa.images[0];
 this.cutImg[1]=tempa.images[1];
 this.cutImg[2]=tempa.images[2];
 tempa.images[0]=tempa.images[1]=tempa.images[2]=this.cutImage;
 this._correctPlus(tempa);
}
};

 dhtmlXTreeObject.prototype.doPaste=function(itemId){
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 if(this.nodeCut){
 if((!this._checkParenNodes(this.nodeCut.parentObject.id,temp))&&(id!=this.nodeCut.parentObject.parentObject.id))
 this._moveNode(temp,this.nodeCut.parentObject);
 this.clearCut();
}
};

 dhtmlXTreeObject.prototype.clearCut=function(){
 if(this.nodeCut)
{
 var tempa=this.nodeCut.parentObject;
 tempa.images[0]=this.cutImg[0];
 tempa.images[1]=this.cutImg[1];
 tempa.images[2]=this.cutImg[2];
 if(tempa.parentObject)this._correctPlus(tempa);
 if(tempa.parentObject)this._correctLine(tempa);
 this.nodeCut=0;
}
};

 dhtmlXTreeObject.prototype._moveNode=function(itemObject,targetObject){
 var mode=this.dadmodec;
 if(mode==1)
{
 var z=targetObject;
 if(this.dadmodefix<0)
{

 while(true){
 z=this._getPrevNode(z);
 if((z==-1)){z=this.htmlNode;break;}
 if((z.tr.style.display=="")||(!z.parentObject))break;
}

 var nodeA=z;
 var nodeB=targetObject;

}
 else
{
 while(true){
 z=this._getNextNode(z);
 if((z==-1)){z=this.htmlNode;break;}
 if((z.tr.style.display=="")||(!z.parentObject))break;
}

 var nodeB=z;
 var nodeA=targetObject;
}

 if(this._getNodeLevel(nodeA,0)>this._getNodeLevel(nodeB,0))
{
 return this._moveNodeTo(itemObject,nodeA.parentObject);
}
 else
{
 return this._moveNodeTo(itemObject,nodeB.parentObject,nodeB);
}

}
 else return this._moveNodeTo(itemObject,targetObject);

}

dhtmlXTreeObject.prototype._fixNodesCollection=function(target,zParent){
 var flag=0;var icount=0;
 var Nodes=target.childNodes;
 var Count=target.childsCount-1;

 if(zParent==Nodes[Count])return;
 for(var i=0;i<Count;i++)
 if(Nodes[i]==Nodes[Count]){Nodes[i]=Nodes[i+1];Nodes[i+1]=Nodes[Count];}

 for(var i=0;i<Count+1;i++)
{
 if(flag){
 var temp=Nodes[i];
 Nodes[i]=flag;
 flag=temp;
}
 else
 if(Nodes[i]==zParent){flag=Nodes[i];Nodes[i]=Nodes[Count];}
}
};

 dhtmlXTreeObject.prototype._moveNodeTo=function(itemObject,targetObject,beforeNode){
 if(targetObject.mytype)
 var framesMove=(itemObject.treeNod.lWin!=targetObject.lWin);
 else
 var framesMove=(itemObject.treeNod.lWin!=targetObject.treeNod.lWin);

 if(this.dragFunc)if(!this.dragFunc(itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod))return false;
 if((targetObject.XMLload==0)&&(this.XMLsource))
{
 targetObject.XMLload=1;this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"id="+escape(targetObject.id));
}
 this.openItem(targetObject.id);

 var oldTree=itemObject.treeNod;
 var c=itemObject.parentObject.childsCount;
 var z=itemObject.parentObject;

 if((framesMove)||(oldTree.dpcpy))itemObject=this._recreateBranch(itemObject,targetObject,beforeNode);
 else
{

 var Count=targetObject.childsCount;var Nodes=targetObject.childNodes;
 Nodes[Count]=itemObject;
 itemObject.treeNod=targetObject.treeNod;
 targetObject.childsCount++;

 var tr=this._drawNewTr(Nodes[Count].htmlNode);

 if(!beforeNode)
{
 targetObject.htmlNode.childNodes[0].appendChild(tr);
 if(this.dadmode==1)this._fixNodesCollection(targetObject,beforeNode);
}
 else
{
 targetObject.htmlNode.childNodes[0].insertBefore(tr,beforeNode.tr);
 this._fixNodesCollection(targetObject,beforeNode);
 Nodes=targetObject.childNodes;
}

}
 if(!oldTree.dpcpy){
 itemObject.parentObject.htmlNode.childNodes[0].removeChild(itemObject.tr);
 if((!beforeNode)||(targetObject!=itemObject.parentObject)){
 for(var i=0;i<z.childsCount;i++){
 if(z.childNodes[i].id==itemObject.id){
 z.childNodes[i]=0;
 break;}}}
 else z.childNodes[z.childsCount-1]=0;

 oldTree._compressChildList(z.childsCount,z.childNodes);
 z.childsCount--;
}

 if((!framesMove)&&(!oldTree.dpcpy)){
 itemObject.tr=tr;
 tr.nodem=itemObject;
 itemObject.parentObject=targetObject;

 if(oldTree!=targetObject.treeNod){if(itemObject.treeNod._registerBranch(itemObject,oldTree))return;this._clearStyles(itemObject);this._redrawFrom(this,itemObject.parentObject);};

 this._correctPlus(targetObject);
 this._correctLine(targetObject);
 this._correctLine(itemObject);
 this._correctPlus(itemObject);

 if(beforeNode)
{

 this._correctPlus(beforeNode);
}
 else
 if(targetObject.childsCount>=2)
{
 this._correctPlus(Nodes[targetObject.childsCount-2]);
 this._correctLine(Nodes[targetObject.childsCount-2]);
}

 this._correctPlus(Nodes[targetObject.childsCount-1]);

 if(this.tscheck)this._correctCheckStates(targetObject);
 if(oldTree.tscheck)oldTree._correctCheckStates(z);

}

 if(c>1){oldTree._correctPlus(z.childNodes[c-2]);
 oldTree._correctLine(z.childNodes[c-2]);
}
 oldTree._correctPlus(z);

 if(this.dropFunc)this.dropFunc(itemObject.id,targetObject.id,(beforeNode?beforeNode.id:null),itemObject.treeNod,targetObject.treeNod);
 return itemObject.id;
};

dhtmlXTreeObject.prototype._checkParenNodes=function(itemId,htmlObject,shtmlObject){
 if(shtmlObject){if(shtmlObject.parentObject.id==htmlObject.id)return 1;}
 if(htmlObject.id==itemId)return 1;
 if(htmlObject.parentObject)return this._checkParenNodes(itemId,htmlObject.parentObject);else return 0;
};

 dhtmlXTreeObject.prototype._clearStyles=function(itemObject){
 var td1=itemObject.htmlNode.childNodes[0].childNodes[0].childNodes[1];
 var td3=td1.nextSibling.nextSibling;

 itemObject.span.innerHTML=itemObject.label;

 if(this.checkBoxOff){td1.childNodes[0].style.display="";td1.childNodes[0].onclick=this.onCheckBoxClick;}
 else td1.childNodes[0].style.display="none";
 td1.childNodes[0].treeNod=this;

 this.dragger.removeDraggableItem(td3);
 if(this.dragAndDropOff)this.dragger.addDraggableItem(td3,this);
 td3.childNodes[0].className="standartTreeRow";
 td3.onclick=this.onRowSelect;td3.ondblclick=this.onRowClick2;
 td1.previousSibling.onclick=this.onRowClick;

 this._correctLine(itemObject);
 this._correctPlus(itemObject);
 for(var i=0;i<itemObject.childsCount;i++)this._clearStyles(itemObject.childNodes[i]);

};

 dhtmlXTreeObject.prototype._registerBranch=function(itemObject,oldTree){

 itemObject.id=this._globalIdStorageAdd(itemObject.id,itemObject);
 itemObject.treeNod=this;
 if(oldTree)oldTree._globalIdStorageSub(itemObject.id);
 for(var i=0;i<itemObject.childsCount;i++)
 this._registerBranch(itemObject.childNodes[i],oldTree);
 return 0;
};

 dhtmlXTreeObject.prototype.enableThreeStateCheckboxes=function(mode){this.tscheck=convertStringToBoolean(mode);};

 dhtmlXTreeObject.prototype.enableTreeImages=function(mode){this.timgen=convertStringToBoolean(mode);};

 dhtmlXTreeObject.prototype.enableFixedMode=function(mode){this.hfMode=convertStringToBoolean(mode);};

 dhtmlXTreeObject.prototype.enableCheckBoxes=function(mode){this.checkBoxOff=convertStringToBoolean(mode);};

 dhtmlXTreeObject.prototype.setStdImages=function(image1,image2,image3){
 this.imageArray[0]=image1;this.imageArray[1]=image2;this.imageArray[2]=image3;};

 dhtmlXTreeObject.prototype.enableTreeLines=function(mode){
 this.treeLinesOn=convertStringToBoolean(mode);
}

 dhtmlXTreeObject.prototype.setImageArrays=function(arrayName,image1,image2,image3,image4,image5){
 switch(arrayName){
 case "plus": this.plusArray[0]=image1;this.plusArray[1]=image2;this.plusArray[2]=image3;this.plusArray[3]=image4;this.plusArray[4]=image5;break;
 case "minus": this.minusArray[0]=image1;this.minusArray[1]=image2;this.minusArray[2]=image3;this.minusArray[3]=image4;this.minusArray[4]=image5;break;
}
};

 dhtmlXTreeObject.prototype.openItem=function(itemId){
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 else return this._openItem(temp);
};

 dhtmlXTreeObject.prototype._openItem=function(item){
 this._HideShow(item,2);
 if((item.parentObject)&&(this._getOpenState(item.parentObject)<0))
 this._openItem(item.parentObject);
};

 dhtmlXTreeObject.prototype.closeItem=function(itemId){
 if(this.rootId==itemId)return 0;
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 if(temp.closeble)
 this._HideShow(temp,1);
};

 dhtmlXTreeObject.prototype.getLevel=function(itemId){
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 return this._getNodeLevel(temp,0);
};

 dhtmlXTreeObject.prototype.setItemCloseable=function(itemId,flag)
{
 flag=convertStringToBoolean(flag);
 if((itemId)&&(itemId.span))
 var temp=itemId;
 else
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 temp.closeble=flag;
};

 dhtmlXTreeObject.prototype._getNodeLevel=function(itemObject,count){
 if(itemObject.parentObject)return this._getNodeLevel(itemObject.parentObject,count+1);
 return(count);
};

 dhtmlXTreeObject.prototype.hasChildren=function(itemId){
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 else
{
 if((this.XMLsource)&&(!temp.XMLload))return true;
 else
 return temp.childsCount;
};
};

 dhtmlXTreeObject.prototype.setItemText=function(itemId,newLabel,newTooltip)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 temp.label=newLabel;
 temp.span.innerHTML=newLabel;
 temp.span.parentNode.title=newTooltip||"";
};

 dhtmlXTreeObject.prototype.refreshItem=function(itemId){
 if(!itemId)itemId=this.rootId;
 var temp=this._globalIdStorageFind(itemId);
 this.deleteChildItems(itemId);
 this.loadXML(this.XMLsource+getUrlSymbol(this.XMLsource)+"id="+escape(itemId));
};

 dhtmlXTreeObject.prototype.setItemImage2=function(itemId,image1,image2,image3){
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 temp.images[1]=image2;
 temp.images[2]=image3;
 temp.images[0]=image1;
 this._correctPlus(temp);
};

 dhtmlXTreeObject.prototype.setItemImage=function(itemId,image1,image2)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 if(image2)
{
 temp.images[1]=image1;
 temp.images[2]=image2;
}
 else temp.images[0]=image1;
 this._correctPlus(temp);
};

 dhtmlXTreeObject.prototype.getSubItems =function(itemId)
{
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;

 var z="";
 for(i=0;i<temp.childsCount;i++)
 if(!z)z=temp.childNodes[i].id;
 else z+=","+temp.childNodes[i].id;
 return z;
};

 dhtmlXTreeObject.prototype.getAllSubItems =function(itemId){
 return this._getAllSubItems(itemId);
}

 dhtmlXTreeObject.prototype._getAllSubItems =function(itemId,z,node)
{
 if(node)temp=node;
 else{
 var temp=this._globalIdStorageFind(itemId);
};
 if(!temp)return 0;

 z="";
 for(var i=0;i<temp.childsCount;i++)
{
 if(!z)z=temp.childNodes[i].id;
 else z+=","+temp.childNodes[i].id;
 var zb=this._getAllSubItems(0,z,temp.childNodes[i])
 if(zb)z+=","+zb;
}
 return z;
};

 dhtmlXTreeObject.prototype.selectItem=function(itemId,mode){
 mode=convertStringToBoolean(mode);
 var temp=this._globalIdStorageFind(itemId);
 if(!temp)return 0;
 if(this._getOpenState(temp.parentObject)==-1)
 this.openItem(itemId);
 if(mode)
 this.onRowSelect(0,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],false);
 else
 this.onRowSelect(0,temp.htmlNode.childNodes[0].childNodes[0].childNodes[3],true);
};

 dhtmlXTreeObject.prototype.getSelectedItemText=function()
{
 if(this.lastSelected)
 return this.lastSelected.parentObject.htmlNode.childNodes[0].childNodes[0].childNodes[3].childNodes[0].innerHTML;
 else return("");
};

 dhtmlXTreeObject.prototype._compressChildList=function(Count,Nodes)
{
 Count--;
 for(var i=0;i<Count;i++)
{
 if(Nodes[i]==0){Nodes[i]=Nodes[i+1];Nodes[i+1]=0;}
};
};

 dhtmlXTreeObject.prototype._deleteNode=function(itemId,htmlObject,skip){

 if(!skip){
 this._globalIdStorageRecSub(htmlObject);
}

 if((!htmlObject)||(!htmlObject.parentObject))return 0;
 var tempos=0;var tempos2=0;
 if(htmlObject.tr.nextSibling)tempos=htmlObject.tr.nextSibling.nodem;
 if(htmlObject.tr.previousSibling)tempos2=htmlObject.tr.previousSibling.nodem;

 var sN=htmlObject.parentObject;
 var Count=sN.childsCount;
 var Nodes=sN.childNodes;
 for(var i=0;i<Count;i++)
{
 if(Nodes[i].id==itemId){
 if(!skip)sN.htmlNode.childNodes[0].removeChild(Nodes[i].tr);
 Nodes[i]=0;
 break;
}
}
 this._compressChildList(Count,Nodes);
 if(!skip){
 sN.childsCount--;
}

 if(tempos){
 this._correctPlus(tempos);
 this._correctLine(tempos);
}
 if(tempos2){
 this._correctPlus(tempos2);
 this._correctLine(tempos2);
}
 if(this.tscheck)this._correctCheckStates(sN);
};

 dhtmlXTreeObject.prototype.setCheck=function(itemId,state){
 state=convertStringToBoolean(state);
 var sNode=this._globalIdStorageFind(itemId);
 if(!sNode)return;
 if((this.tscheck)&&(this.smcheck))this._setSubChecked(state,sNode);
 else this._setCheck(sNode,state);
 if(this.smcheck)
 this._correctCheckStates(sNode.parentObject);
};

 dhtmlXTreeObject.prototype._setCheck=function(sNode,state){
 var z=sNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0];

 if(state=="notsure")sNode.checkstate=2;
 else if(state)sNode.checkstate=1;else sNode.checkstate=0;

 z.src=this.imPath+this.checkArray[sNode.checkstate];
};

dhtmlXTreeObject.prototype.setSubChecked=function(itemId,state){
 var sNode=this._globalIdStorageFind(itemId);
 this._setSubChecked(state,sNode);
 this._correctCheckStates(sNode.parentObject);
}

dhtmlXTreeObject.prototype._setSubCheckedXML=function(state,sNode){
 if(!sNode)return;
 for(var i=0;i<sNode.childNodes.length;i++){
 var tag=sNode.childNodes[i];
 if((tag)&&(tag.tagName=="item")){
 if(state)tag.setAttribute("checked",1);
 else tag.setAttribute("checked","");
 this._setSubCheckedXML(state,tag);
}
}
}

 dhtmlXTreeObject.prototype._setSubChecked=function(state,sNode){
 state=convertStringToBoolean(state);
 if(!sNode)return;
 if(sNode.unParsed)
 this._setSubCheckedXML(state,sNode.unParsed)
 for(var i=0;i<sNode.childsCount;i++)
{
 this._setSubChecked(state,sNode.childNodes[i]);
};
 var z=sNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0];

 if(state)sNode.checkstate=1;
 else sNode.checkstate=0;

 z.src=this.imPath+this.checkArray[sNode.checkstate];
};

 dhtmlXTreeObject.prototype.isItemChecked=function(itemId){
 var sNode=this._globalIdStorageFind(itemId);
 if(!sNode)return;
 return sNode.checkstate;
};

 dhtmlXTreeObject.prototype.getAllChecked=function(){
 return this._getAllChecked("","",1);
}

 dhtmlXTreeObject.prototype.getAllCheckedBranches=function(){
 return this._getAllChecked("","",0);
}

 dhtmlXTreeObject.prototype._getAllChecked=function(htmlNode,list,mode){
 if(!htmlNode)htmlNode=this.htmlNode;
 if(((mode)&&(htmlNode.checkstate==1))||((!mode)&&(htmlNode.checkstate>0)))
 if(!htmlNode.nocheckbox){if(list)list+=","+htmlNode.id;else list=htmlNode.id;}
 var j=htmlNode.childsCount;
 for(var i=0;i<j;i++)
{
 list=this._getAllChecked(htmlNode.childNodes[i],list,mode);
};
 if(htmlNode.unParsed)
 list=this._getAllCheckedXML(htmlNode.unParsed,list,mode);

 if(list)return list;else return "";
};

 dhtmlXTreeObject.prototype._getAllCheckedXML=function(htmlNode,list,mode){
 var j=htmlNode.childNodes.length;
 for(var i=0;i<j;i++)
{
 var tNode=htmlNode.childNodes[i];
 if(tNode.tagName=="item")
{
 var z=tNode.getAttribute("checked");
 if((z!=null)&&(z!="")&&(z!="0"))
 if(((z=="-1")&&(!mode))||(z!="-1"))
 if(list)list+=","+tNode.getAttribute("id");
 else list=htmlNode.id;

 list=this._getAllChecked(tNode,list,mode);
}
};

 if(list)return list;else return "";
};

 dhtmlXTreeObject.prototype.deleteChildItems=function(itemId)
{
 var sNode=this._globalIdStorageFind(itemId);
 if(!sNode)return;
 var j=sNode.childsCount;
 for(var i=0;i<j;i++)
{
 this._deleteNode(sNode.childNodes[0].id,sNode.childNodes[0]);
};
};

dhtmlXTreeObject.prototype.deleteItem=function(itemId,selectParent){
 this._deleteItem(itemId,selectParent);
}

dhtmlXTreeObject.prototype._deleteItem=function(itemId,selectParent,skip){
 selectParent=convertStringToBoolean(selectParent);
 var sNode=this._globalIdStorageFind(itemId);
 if(!sNode)return;
 if(selectParent)this.selectItem(this.getParentId(this.getSelectedItemId()),1);
 else this.lastSelected=null;
 if(!skip){
 this._globalIdStorageRecSub(sNode);
};
 var zTemp=sNode.parentObject;
 this._deleteNode(itemId,sNode,skip);
 this._correctPlus(zTemp);
 this._correctLine(zTemp);
 return zTemp;
};

 dhtmlXTreeObject.prototype._globalIdStorageRecSub=function(itemObject){
 for(var i=0;i<itemObject.childsCount;i++)
{
 this._globalIdStorageRecSub(itemObject.childNodes[i]);
 this._globalIdStorageSub(itemObject.childNodes[i].id);
};
 this._globalIdStorageSub(itemObject.id);
};

 dhtmlXTreeObject.prototype.insertNewNext=function(parentItemId,itemId,itemName,itemActionHandler,image1,image2,image3,optionStr,childs){
 var sNode=this._globalIdStorageFind(parentItemId);
 if((!sNode)||(!sNode.parentObject))return(0);

 this._attachChildNode(0,itemId,itemName,itemActionHandler,image1,image2,image3,optionStr,childs,sNode);

};

 dhtmlXTreeObject.prototype.getItemIdByIndex=function(itemId,index){
 var z=this._globalIdStorageFind(itemId);
 if((!z)||(index>z.childsCount))return null;
 return z.childNodes[index].id;
};

 dhtmlXTreeObject.prototype.getChildItemIdByIndex=function(itemId,index){
 var z=this._globalIdStorageFind(itemId);
 if((!z)||(index>z.childsCount))return null;
 return z.childNodes[index].id;
};

 dhtmlXTreeObject.prototype.setDragHandler=function(func){if(typeof(func)=="function")this.dragFunc=func;else this.dragFunc=eval(func);};

 dhtmlXTreeObject.prototype._clearMove=function(htmlNode){
 if((htmlNode.parentObject)&&(htmlNode.parentObject.span)){
 htmlNode.parentObject.span.className='standartTreeRow';
 if(htmlNode.parentObject.acolor)htmlNode.parentObject.span.style.color=htmlNode.parentObject.acolor;
}

 this.selectionBar.style.display="none";
 this.allTree.className="containerTableStyle";
};

 dhtmlXTreeObject.prototype.enableDragAndDrop=function(mode){
 this.dragAndDropOff=convertStringToBoolean(mode);
 if(this.dragAndDropOff)this.dragger.addDragLanding(this.allTree,this);
};

 dhtmlXTreeObject.prototype._setMove=function(htmlNode,x,y){
 if(htmlNode.parentObject.span){
 var a1=getAbsoluteTop(htmlNode);
 var a2=getAbsoluteTop(this.allTree);

 this.dadmodec=this.dadmode;this.dadmodefix=0;

 if(this.dadmodec==0)
{
 htmlNode.parentObject.span.className='selectedTreeRow';
 if(htmlNode.parentObject.scolor)htmlNode.parentObject.span.style.color=htmlNode.parentObject.scolor;
}
 else{
 htmlNode.parentObject.span.className='standartTreeRow';
 if(htmlNode.parentObject.acolor)htmlNode.parentObject.span.style.color=htmlNode.parentObject.acolor;
 this.selectionBar.style.top=a1-a2+16+this.dadmodefix;
 this.selectionBar.style.left=5;
 this.selectionBar.style.display="";
}

 if(this.autoScroll)
{
 if((a1-a2-parseInt(this.allTree.scrollTop))>(parseInt(this.allTree.offsetHeight)-50))
 this.allTree.scrollTop=parseInt(this.allTree.scrollTop)+20;
 if((a1-a2)<(parseInt(this.allTree.scrollTop)+30))
 this.allTree.scrollTop=parseInt(this.allTree.scrollTop)-20;
}
}
};

dhtmlXTreeObject.prototype._createDragNode=function(htmlObject){
 dhtmlObject=htmlObject.parentObject;
 if(this.lastSelected)this._clearMove(this.lastSelected);
 var dragSpan=document.createElement('div');
 dragSpan.appendChild(document.createTextNode(dhtmlObject.label));
 dragSpan.style.position="absolute";
 dragSpan.className="dragSpanDiv";
 return dragSpan;
}

dhtmlXTreeObject.prototype._preventNsDrag=function(e){
 if((e)&&(e.preventDefault)){e.preventDefault();return false;}
 return false;
}

dhtmlXTreeObject.prototype._drag=function(sourceHtmlObject,dhtmlObject,targetHtmlObject){

 if(this._autoOpenTimer)clearTimeout(this._autoOpenTimer);

 if(!targetHtmlObject.parentObject){
 targetHtmlObject=this.htmlNode.htmlNode.childNodes[0].childNodes[0].childNodes[1].childNodes[0];
 this.dadmodec=0;
}

 this._clearMove(targetHtmlObject);
 var z=targetHtmlObject.parentObject.treeNod;
 z._clearMove("");
 if((!this.dragMove)||(this.dragMove()))
{
 var newID=this._moveNode(sourceHtmlObject.parentObject,targetHtmlObject.parentObject);
 z.selectItem(newID);
}

 try{}
 catch(e){
 return;
}
}

dhtmlXTreeObject.prototype._dragIn=function(htmlObject,shtmlObject,x,y){
 if(!htmlObject.parentObject)
{
 this.allTree.className="containerTableStyle selectionBox";
 return htmlObject;
}

 if((!this._checkParenNodes(shtmlObject.parentObject.id,htmlObject.parentObject,shtmlObject.parentObject))&&(htmlObject.parentObject.id!=shtmlObject.parentObject.id))
{
 htmlObject.parentObject.span.parentNode.appendChild(this.selectionBar);
 this._setMove(htmlObject,x,y);
 if(this._getOpenState(htmlObject.parentObject)<0)
 this._autoOpenTimer=window.setTimeout(new callerFunction(this._autoOpenItem,this),1000);
 this._autoOpenId=htmlObject.parentObject.id;
 return htmlObject;
}
 else return 0;
}
dhtmlXTreeObject.prototype._autoOpenItem=function(e,treeObject){
 treeObject.openItem(treeObject._autoOpenId);
};
dhtmlXTreeObject.prototype._dragOut=function(htmlObject){
this._clearMove(htmlObject);
if(this._autoOpenTimer)clearTimeout(this._autoOpenTimer);
}

dhtmlXTreeObject.prototype._getNextNode=function(item,mode){
 if((!mode)&&(item.childsCount))return item.childNodes[0];
 if(item==this.htmlNode)
 return -1;
 if((item.tr)&&(item.tr.nextSibling)&&(item.tr.nextSibling.nodem))
 return item.tr.nextSibling.nodem;

 return this._getNextNode(item.parentObject,true);
};

dhtmlXTreeObject.prototype._lastChild=function(item){
 if(item.childsCount)
 return this._lastChild(item.childNodes[item.childsCount-1]);
 else return item;
};

dhtmlXTreeObject.prototype._getPrevNode=function(node,mode){
 if((node.tr)&&(node.tr.previousSibling)&&(node.tr.previousSibling.nodem))
 return this._lastChild(node.tr.previousSibling.nodem);

 if(node.parentObject)
 return node.parentObject;
 else return -1;
};


text:
const expect = require('chai').expect
const rateLimit = require('../..').poisons.rateLimit

suite('poison#rateLimit', function () {
  test('limit', function (done) {
    var opts = { limit: 2, threshold: 10 }

    var res = {}
    res.setHeader = function (key, value) {
      expect(key).to.match(/RateLimit/i)
    }
    res.end = function (data) {
      expect(data).to.be.undefined
    }

    var invalidRes = {}
    invalidRes.setHeader = function (key, value) {
      if (key === 'X-RateLimit-Limit')
        expect(value).to.be.equal(2)
      if (key === 'X-RateLimit-Remaining')
        expect(value).to.be.equal(0)
      if (key === 'X-RateLimit-Reset')
        expect(value).to.be.below(10)
    }
    invalidRes.end = function (body) {
      expect(body).to.match(/Too many requests/i)
    }

    var limiter = rateLimit(opts)

    limiter(null, res, next)
    limiter(null, res, next)
    limiter(null, invalidRes, next) // invalid

    // Wait to try again
    setTimeout(function () {
      limiter(null, res, next)
      limiter(null, res, end)
    }, opts.threshold + 1)

    function next(err) {
      expect(err).to.be.undefined
    }

    function end(err) {
      next(err)
      done()
    }
  })
})


text:
class Structure;
class ThemeManager {
public:
    static ThemeManager & instance();

    void addTheme(const std::string &name, nanogui::Theme *theme);
    nanogui::Theme *findTheme(const std::string &name);

    // A context to create the theme in.
    void setContext(NVGcontext *context);

    // Construct a theme from a given structure definition.
    nanogui::Theme *createTheme(Structure *settings = nullptr);

private:
    class Pimpl;
    Pimpl *impl = nullptr;
    ThemeManager();
    ~ThemeManager();
    static ThemeManager *theme_manager;
};