text:
var assert = require("assert");

var bus = require('../../dist/EventBus');
var jrpc = require('../../dist/JsonRpc');
var handler = require('../../dist/BackendCallHandler');
var sample = require('../extra/wsrpc_registry_classes').wsrpc_registry_classes;

handler.DEBUG = true;

var mockClient = {
    callCount: 0,
    jsonRpcMessage: null,
    send: function(data) {
        this.callCount ++;
        //console.log('MOCK SEND ' + '(' + this.callCount + '), data = ' + data);
        this.jsonRpcMessage = data;
    },
    result: function() {
        return JSON.parse(this.jsonRpcMessage).result;
    },
    error: function() {
        return JSON.parse(this.jsonRpcMessage).error;
    }
};

var mockServer = {
    clients: [mockClient, mockClient]
};

describe('BackendCallHandler execute tests', function () {

    var _handler = new handler.BackendCallHandler();

    _handler.singleton('compteur', sample.Compteur);
    _handler.singleton('chatroom', sample.Chatroom);
    _handler.stateless('dateutil', sample.DateUtil);

    describe('execute: on singleton', function () {
        it('call execute: increment on singleton object', function () {
            var registry = _handler.getRegistry('compteur');

            _handler.execute(mockClient, 'compteur', 'increment', null, 'INC');
            assert.equal(1, mockClient.result());

            _handler.execute(mockClient, 'compteur', 'increment', null, 'INC');
            assert.equal(2, mockClient.result());

            _handler.execute(mockClient, 'compteur', 'increment', null, 'INC');
            assert.equal(3, mockClient.result());

            var v = registry.invoke('compteur', 'increment', null);
            assert.equal(4, v);

            v = registry.invoke('compteur', 'increment', null);
            assert.equal(5, v);
        })
    });

    describe('execute: on stateless', function () {
        it('call execute: increment on stateless object', function () {
            var registry = _handler.getRegistry('dateutil');

            var h = registry.invoke('dateutil', 'getHour', null);

            _handler.execute(mockClient, 'dateutil', 'getHour', null, 'HOUR');
            assert.equal(h, mockClient.result());

            _handler.execute(mockClient, 'dateutil', 'getHour', null, 'HOUR');
            assert.equal(h, mockClient.result());

            _handler.execute(mockClient, 'dateutil', 'getHour', null, 'HOUR');
            assert.equal(h, mockClient.result());
        })
    });
});

describe('BackendCallHandler sendResponseToOrigin tests', function () {

    var _handler = new handler.BackendCallHandler();

    describe('sendResponseToOrigin', function () {
        it('send response json to the corresponding client', function () {
            mockClient.callCount = 0;
            _handler.broadcastExecute(mockServer, mockClient, 'compteur', 'increment', null, 'INC_1');

            assert.equal(2, mockClient.callCount);

            mockClient.callCount = 0;
            var message = '{"jsonrpc":"2.0","result":100,"id":"INC_1"}';
            var rpc = new jrpc.RPC(JSON.parse(message));
            var client = _handler.getClientResponseWithId(rpc.getId());
            _handler.sendResponseToOrigin(client, rpc.getId(), rpc.getResult());

            assert.equal(1, mockClient.callCount);
            assert.equal(100, mockClient.result());
            assert.equal(mockClient, _handler.getClientResponseWithId('INC_1'));
        })
    });
});

describe('BackendCallHandler sendErrorToOrigin tests', function () {

    var _handler = new handler.BackendCallHandler();

    describe('send error json to the corresponding client', function () {
        it('call sendErrorToOrigin', function () {
            mockClient.callCount = 0;
            _handler.broadcastExecute(mockServer, mockClient, 'compteur', 'incrementation', null, 'INC_2');
            assert.equal(2, mockClient.callCount);

            mockClient.callCount = 0;
            var message = '{"jsonrpc":"2.0","error":{"code":-32601,"message":"RPC client instance named null not found."},"id":"INC_2"}';
            var rpc = new jrpc.RPC(JSON.parse(message));
            var client = _handler.getClientResponseWithId(rpc.getId());
            _handler.sendErrorToOrigin(client, rpc.getId(), rpc.getCode(), rpc.getErrorMessage());

            assert.equal(1, mockClient.callCount);
            assert.equal(-32601, mockClient.error().code);
            assert.equal(mockClient, _handler.getClientResponseWithId('INC_2'));
        })
    });
});

describe('BackendCallHandler useResponse tests', function () {

    var _handler = new handler.BackendCallHandler();

    describe('fire response to eventBus', function () {
        it('call useResponse', function () {
            var done = false;
            var data = null;
            var eventBus = bus.EventBus.getSharedEventBus();
            eventBus.on('INC_3', function(x) {
                done = true;
                data = x;
            });

            _handler.useResponse('INC_3', { RESULT: 'DONE' });

            assert.equal(true, done);
            assert.equal('DONE', data.RESULT);
        })
    });
});


text:
package com.serotonin.bacnet4j.type.constructed;

import com.serotonin.bacnet4j.exception.BACnetErrorException;
import com.serotonin.bacnet4j.exception.BACnetException;
import com.serotonin.bacnet4j.type.AmbiguousValue;
import com.serotonin.bacnet4j.type.Encodable;
import com.serotonin.bacnet4j.type.enumerated.BinaryPV;
import com.serotonin.bacnet4j.type.enumerated.ErrorClass;
import com.serotonin.bacnet4j.type.enumerated.ErrorCode;
import com.serotonin.bacnet4j.type.primitive.Enumerated;
import com.serotonin.bacnet4j.type.primitive.Null;
import com.serotonin.bacnet4j.type.primitive.Real;
import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
import org.free.bacnet4j.util.ByteQueue;

public class PriorityValue extends BaseType {
    private static final long serialVersionUID = 213834169635261132L;
    private Null nullValue;
    private Real realValue;
    private BinaryPV binaryValue;
    private UnsignedInteger integerValue;
    private Encodable constructedValue;

    public PriorityValue(Null nullValue) {
        this.nullValue = nullValue;
    }

    public PriorityValue(Real realValue) {
        this.realValue = realValue;
    }

    public PriorityValue(BinaryPV binaryValue) {
        this.binaryValue = binaryValue;
    }

    public PriorityValue(UnsignedInteger integerValue) {
        this.integerValue = integerValue;
    }

    public PriorityValue(BaseType constructedValue) {
        this.constructedValue = constructedValue;
    }

    public Null getNullValue() {
        return nullValue;
    }

    public Real getRealValue() {
        return realValue;
    }

    public BinaryPV getBinaryValue() {
        return binaryValue;
    }

    public UnsignedInteger getIntegerValue() {
        return integerValue;
    }

    public Encodable getConstructedValue() {
        return constructedValue;
    }

    public boolean isNull() {
        return nullValue != null;
    }

    public Encodable getValue() {
        if (nullValue != null)
            return nullValue;
        if (realValue != null)
            return realValue;
        if (binaryValue != null)
            return binaryValue;
        if (integerValue != null)
            return integerValue;
        return constructedValue;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("PriorityValue(");
        if (nullValue != null)
            sb.append("nullValue=").append(nullValue);
        else if (realValue != null)
            sb.append("realValue=").append(realValue);
        else if (binaryValue != null)
            sb.append("binaryValue=").append(binaryValue);
        else if (integerValue != null)
            sb.append("integerValue=").append(integerValue);
        else if (constructedValue != null)
            sb.append("constructedValue=").append(constructedValue);
        sb.append(")");
        return sb.toString();
    }

    @Override
    public void write(ByteQueue queue) {
        if (nullValue != null)
            nullValue.write(queue);
        else if (realValue != null)
            realValue.write(queue);
        else if (binaryValue != null)
            binaryValue.write(queue);
        else if (integerValue != null)
            integerValue.write(queue);
        else
            constructedValue.write(queue, 0);
    }

    public PriorityValue(ByteQueue queue) throws BACnetException {
        // Sweet Jesus...
        int tag = (queue.peek(0) & 0xff);
        if ((tag & 8) == 8) {
            // A class tag, so this is a constructed value.
            constructedValue = new AmbiguousValue(queue, 0);
        }
        else {
            // A primitive value
            tag = tag >> 4;
            if (tag == Null.TYPE_ID)
                nullValue = new Null(queue);
            else if (tag == Real.TYPE_ID)
                realValue = new Real(queue);
            else if (tag == Enumerated.TYPE_ID)
                binaryValue = new BinaryPV(queue);
            else if (tag == UnsignedInteger.TYPE_ID)
                integerValue = new UnsignedInteger(queue);
            else
                throw new BACnetErrorException(ErrorClass.property, ErrorCode.invalidDataType,
                        "Unsupported primitive id: " + tag);
        }
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((binaryValue == null) ? 0 : binaryValue.hashCode());
        result = prime * result + ((constructedValue == null) ? 0 : constructedValue.hashCode());
        result = prime * result + ((integerValue == null) ? 0 : integerValue.hashCode());
        result = prime * result + ((nullValue == null) ? 0 : nullValue.hashCode());
        result = prime * result + ((realValue == null) ? 0 : realValue.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        PriorityValue other = (PriorityValue) obj;
        if (binaryValue == null) {
            if (other.binaryValue != null)
                return false;
        }
        else if (!binaryValue.equals(other.binaryValue))
            return false;
        if (constructedValue == null) {
            if (other.constructedValue != null)
                return false;
        }
        else if (!constructedValue.equals(other.constructedValue))
            return false;
        if (integerValue == null) {
            if (other.integerValue != null)
                return false;
        }
        else if (!integerValue.equals(other.integerValue))
            return false;
        if (nullValue == null) {
            if (other.nullValue != null)
                return false;
        }
        else if (!nullValue.equals(other.nullValue))
            return false;
        if (realValue == null) {
            if (other.realValue != null)
                return false;
        }
        else if (!realValue.equals(other.realValue))
            return false;
        return true;
    }
}

redpajama_set_name: RedPajamaGithub


text:
const fs = require('fs');
const path = require('path');

function deleteRefs(dir) {
	const files = fs.readdirSync(dir);
	for (let file of files) {
		const filePath = path.join(dir, file);
		const stat = fs.statSync(filePath);
		if (stat.isDirectory()) {
			deleteRefs(filePath);
		} else if (path.extname(file) === '.js') {
			const content = fs.readFileSync(filePath, 'utf8');
			const newContent = content.replace(/\/\/\# sourceMappingURL=[^]+.js.map/, '')
			if (content.length !== newContent.length) {
				console.log('remove sourceMappingURL in ' + filePath);
				fs.writeFileSync(filePath, newContent);
			}
		} else if (path.extname(file) === '.map') {
			fs.unlinkSync(filePath)
			console.log('remove ' + filePath);
		}
	}
}

let location = path.join(__dirname, '..', 'lib');
console.log('process ' + location);
deleteRefs(location);


text:
package fr.soprasteria.world.persistence;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

import fr.soprasteria.world.WorldGrille;
import fr.soprasteria.world.fabriques.FabriqueSimpleWorlds;

public class WorldFileMappersTest {

	@Test
	public void testWorldFileSerializerOK() throws IOException {
		File fileTest = new File("target/testWorldFileSerializerOK.jo");
		// Suppression du fichier s'il exist déjà pour avoir un context propre
		if(fileTest.exists())
			fileTest.delete();

		WorldGrille world = FabriqueSimpleWorlds.emptyWorld(4, 3, 1, 2);

		WorldFileSerializer serializer = new WorldFileSerializer();
		serializer.save(fileTest, world);
		assertTrue("Fichier sérialisé absent après sauvegarde.", fileTest.exists());
		WorldGrille loadWorld = serializer.load(fileTest);

		// Si tout est OK jusque là, on peut supprimer le fichier de test
		fileTest.delete();

		// Vérification du monde charger
		assertEquals("Nombre de colonnes différent entre le monde d'origine et celui chargé", world.getNbColonnes(), loadWorld.getNbColonnes());
		assertEquals("Nombre de lignes différent entre le monde d'origine et celui chargé", world.getNbLignes(), loadWorld.getNbLignes());
		for(int col = 0; col < world.getNbColonnes(); col++) {
			for(int li = 0; li < world.getNbLignes(); li++) {
				String expected = world.getCase(col, li).getClass().getName();
				String actual = loadWorld.getCase(col, li).getClass().getName();
				assertEquals("Case(li=" + li + ", col=" + col + ") de classe incorrecte.", expected, actual);
			}
		}
	}

}


text:
/**
 * Collection of scripts for mobile development
 *
 */

if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', function() {
    FastClick.attach(document.body);
  }, false);
}


text:
<?php

namespace BrainExe\Core\Authentication;

use BrainExe\Core\Annotations\Service;
use BrainExe\Core\Traits\IdGeneratorTrait;
use BrainExe\Core\Traits\RedisTrait;
use Generator;

/**
 * @Service
 */
class Token
{

    const USER_KEY  = 'tokens:user:%s';
    const TOKEN_KEY = 'tokens';

    use RedisTrait;
    use IdGeneratorTrait;

    /**
     * @param int $userId
     * @param string[] $roles
     * @param string $name
     * @return string
     */
    public function addToken(int $userId, array $roles = [], string $name = '') : string
    {
        $token = $this->generateRandomId(40);

        $redis = $this->getRedis()->pipeline();

        $redis->sadd(sprintf(self::USER_KEY, $userId), $token);
        $redis->hset(self::TOKEN_KEY, $token, json_encode([
            'userId' => $userId,
            'roles'  => $roles,
            'name'   => $name
        ]));

        $redis->execute();

        return $token;
    }

    /**
     * @param string $token
     * @return array
     */
    public function getToken(string $token)
    {
        return json_decode($this->getRedis()->hget(self::TOKEN_KEY, $token), true);
    }

    /**
     * @param int $userId
     * @return array[]|Generator
     */
    public function getTokensForUser(int $userId)
    {
        $redis     = $this->getRedis();
        $tokensIds = $redis->smembers(sprintf(self::USER_KEY, $userId));

        if (!empty($tokensIds)) {
            $tokens = $redis->hmget(self::TOKEN_KEY, $tokensIds);

            foreach ($tokens as $idx => $token) {
                yield $tokensIds[$idx] => json_decode($token, true);
            }
        }
    }

    /**
     * @param string $token
     * @param string|null $role
     * @return int|null
     */
    public function hasUserForRole(string $token, string $role = null) : ?int
    {
        $tokenData = $this->getToken($token);
        if (empty($tokenData)) {
            return null;
        }

        if ($role && !in_array($role, $tokenData['roles'], true)) {
            return null;
        }

        return $tokenData['userId'];
    }

    /**
     * @param string $token
     */
    public function revoke(string $token)
    {
        $tokenData = $this->getToken($token);
        if (!$tokenData) {
            return;
        }

        $userId = $tokenData['userId'];

        $redis = $this->getRedis()->pipeline();

        $redis->srem(sprintf(self::USER_KEY, $userId), $token);
        $redis->hdel(self::TOKEN_KEY, $token);

        $redis->execute();
    }
}


text:
export CNY_PDK          ?= /opt/convey/pdk2
export CNY_PDK_REV      ?= latest
export CNY_PDK_PLATFORM ?= wx2-vu7p

pers: export CNY_HT_AEUCNT = 8

# DO NOT MODIFY ITEMS BELOW THIS LINE
export HT_DIR ?= /usr/local/ht_releases/latest
include $(HT_DIR)/ht_lib/MakefileInclude.cnyht


text:
If you are new to Python, the CS521 facilitators recommend that you download [PyCharm](https://www.jetbrains.com/pycharm-edu/download) as your IDE (Integrated Development Environment), but you are welcome to use any other IDE that you are familiar with; for example [Anaconda](https://docs.continuum.io/anaconda/install#) is also a popular IDE.  We also support the IDLE interpreter that comes with the install from [python.org](https://www.python.org/downloads/).

This note explains how to set up Python and introduces you to pyCharm, the Python development environment we will be using throughout this course.

#### DOWNLOAD THE PYTHON INSTALLER

Download and install the latest version of python [[here]](https://www.python.org/downloads/) (3.6 at time of writing).

Download the free [PyCharm Edu IDE](https://www.jetbrains.com/pycharm-edu/download).  The initial download is about 160M, depending on which operating system you use with Mac, Windows and Linux all supported.

![pyCharm Download](https://github.com/StephenHarrington/CS521/raw/master/images/pycharm1.JPG "pyCharm Splash Screen")

Alternatively, you can use either the IDLE interpreter from [python.org](https://www.python.org/downloads/) or ["Anaconda" Python distribution](https://www.continuum.io/downloads).  The Anaconda install may take some time since it contains the base Python 3.5 version as well as some packages you will find useful.

** _Note.  CS521 uses Python 3.X (either 3.5 for pyCharm or 3.6 for IDLE), do not use Python 2.7 since all grading will assume Python 3.X_ **

##### Operating Systems:
Any of the popular IDEs (pyCharm, IDLE and Anaconda) will provide executable Windows installers.  Make sure to use the 32-bit **or** the 64-bit Windows versions, whichever is supported by your computer.  Microsoft provides instructions [here](https://support.microsoft.com/en-us/help/15056/windows-7-32-64-bit-faq) to determine whether you have a 32-bit or 64-bit setup. If you are running 32-bit Windows, be sure that you select the 32-bit version, and if you are running 64-bit Windows, you can download either version.

** _Note. pyCharm and IDLE defaults to the 32-bit version when being installed on Windows._ **

The Macintosh Operating System (OS X) only provides 64-bit installers and that is the default for most python IDEs.

IDEs for Linux Operating Systems provides both 32-bit and 64-bit versions.

#### INSTALLING pyCharm

To install pyCharm after downloading the graphical installer, double click the .exe (Windows) or .pkg (Mac) file and follow the instructions on the screen.

** _Note. pyCharm's Python distribution may default to Python 2.7.  Make sure to select Python 3.5_ **

![pyCharm python version](https://github.com/StephenHarrington/CS521/raw/master/images/pycharm4.JPG "python 3.5")

When installing python, a pop-up menu may ask whether or not to "Add pyCharm to my PATH environment variable", and "Register pyCharm as my default Python 3.5." We suggest accepting both options for the purposes of this class.

The installation should take take about 15 minutes.

#### STARTING THE CODE EDITOR

When you download and install the pyCharm distribution of Python, you are getting several tools related to Python development. One of the tools is the JetBrains PyCharm Edu editor, an integrated development environment useful for writing, running, and debugging code. From the windows start menu click on PyCharm:

![windows start menu](https://github.com/StephenHarrington/CS521/raw/master/images/start%20menu%20showing%20pythons.JPG "python IDEs")

#### PyCharm APPLICATION OVERVIEW

Opening PyCharm should present you with the following window (screenshots are from a Windows machine, but a similar window should appear for MAC OS and Linux). This window contains two commonly used options, among others:

1. Create a New Project that lets you create and edit existing Python source files
2. Introduction to Python, which guides you through a quick introduction to the Python programming language

![PyCharm](https://github.com/StephenHarrington/CS521/raw/master/images/pycharm5.JPG "PyCharm")

A useful feature of PyCharm is the Introduction to Python.  Clicking on that option brings up the window shown below.  Note that there is a warning message telling you that an interpreter must be configured for the program to execute.

![Intro](https://github.com/StephenHarrington/CS521/raw/master/images/pycharm6.JPG "Introduction to Python")

** _Note. When you first start PyCharm, you must associate an interpreter (python version) with the code._ **

Clicking on the link in the warning message brings up PyCharm's configuration settings.  On this machine, both Python 2.7 and Python 3.5 are available.  Make sure to configure using the Python 3.5 interpreter!

![Interpreter](https://github.com/StephenHarrington/CS521/raw/master/images/pycharm7.JPG "Interpreter")

You may want to start PyCharm and make sure the Python 3.5 interpreter is associated with your code files.

The Introduction to Python is a use tool to get familar with some of the basics of the python language as well as to familiarize yourself with the PyCharm IDE.

### Resources

If you want to go beyond with pycharm:
- [[Quick start]](https://www.jetbrains.com/pycharm-edu/quickstart/)

Have fun!

Stephen Harrington
January 15, 2017


text:
<?php

namespace PhpSpec\IO;

interface IO
{
    /**
     * @param string $message
     */
    public function write($message);

    /**
     * @return bool
     */
    public function isVerbose();
}


text:
package com.thinkbiganalytics.auth.rest;

import com.thinkbiganalytics.auth.jaas.AbstractLoginModule;
import com.thinkbiganalytics.rest.JerseyRestClient;
import com.thinkbiganalytics.security.rest.model.UserPrincipal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.login.AccountLockedException;
import javax.security.auth.login.AccountNotFoundException;
import javax.security.auth.login.CredentialException;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.spi.LoginModule;
import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;

/**
 * Authenticates users by querying an external REST API. This allows the UI module to get a user's groups from the Services module.
 */
public class KyloRestLoginModule extends AbstractLoginModule implements LoginModule {

    private static final Logger log = LoggerFactory.getLogger(KyloRestLoginModule.class);
    /**
     * Option for the URL of the REST API endpoint
     */
    static final String LOGIN_USER = "loginUser";
    /**
     * Option for the URL of the REST API endpoint
     */
    static final String LOGIN_PASSWORD = "loginPassword";

    /**
     * Option for REST client configuration
     */
    static final String REST_CLIENT_CONFIG = "restClientConfig";

    /**
     * REST API client configuration
     */
    private LoginJerseyClientConfig config;

    /**
     * Alternate username (such as service account) to use when making the REST call
     */
    private String loginUser = null;

    /**
     * The password to use when a loginUser property is set
     */
    private String loginPassword = null;

    @Override
    public void initialize(@Nonnull final Subject subject, @Nonnull final CallbackHandler callbackHandler, @Nonnull final Map<String, ?> sharedState, @Nonnull final Map<String, ?> options) {
        super.initialize(subject, callbackHandler, sharedState, options);

        try {
            config = (LoginJerseyClientConfig) options.get(REST_CLIENT_CONFIG);
            loginUser = (String) getOption(LOGIN_USER).orElse(null);
            loginPassword = loginUser == null ? null : (String) getOption(LOGIN_PASSWORD)
                .orElseThrow(() -> new IllegalArgumentException("A REST login password is required if a login username was provided"));
        } catch (RuntimeException e) {
            log.error("Unhandled exception during initialization", e);
            throw e;
        }
    }

    @Override
    protected boolean doLogin() throws Exception {
        // Get username and password
        final NameCallback nameCallback = new NameCallback("Username: ");
        final PasswordCallback passwordCallback = new PasswordCallback("Password: ", false);
        final String username;
        final String password;

        if (loginUser == null) {
            // Use user's own username and password to access the REST API if a loginUser was not provided.
            handle(nameCallback, passwordCallback);
            username = nameCallback.getName();
            password = new String(passwordCallback.getPassword());
        } else {
            // Using the loginUser to access API so only need the authenticating user's name.
            handle(nameCallback);
            username = loginUser;
            password = loginPassword;
        }

        final LoginJerseyClientConfig userConfig = new LoginJerseyClientConfig(config);
        userConfig.setUsername(username);
        userConfig.setPassword(password);

        final UserPrincipal user;
        try {
            user = retrieveUser(nameCallback.getName(), userConfig);
        } catch (final NotAuthorizedException e) {
            log.debug("Received unauthorized response from Login API for user: {}", username);
            throw new CredentialException("The username and password combination do not match.");
        } catch (final ProcessingException e) {
            log.error("Failed to process response from Login API for user: {}", username, e);
            throw new FailedLoginException("The login service is unavailable.");
        } catch (final WebApplicationException e) {
            log.error("Received unexpected response from Login API for user: {}", username, e);
            throw new FailedLoginException("The login service is unavailable.");
        }

        // Parse response
        if (user == null) {
            log.debug("Received null response from Login API for user: {}", username);
            throw new AccountNotFoundException("No account exists with the name: " + username);
        } else if (!user.isEnabled()) {
            log.debug("User from Login API is disabled: {}", username);
            throw new AccountLockedException("The account \"" + username + "\" is currently disabled");
        }

        addNewUserPrincipal(user.getSystemName());
        user.getGroups().forEach(this::addNewGroupPrincipal);
        return true;
    }

    private UserPrincipal retrieveUser(String user, final LoginJerseyClientConfig userConfig) {
        String endpoint = loginUser == null ? "/v1/about/me" : "/v1/security/users/" + user;
        return getClient(userConfig).get(endpoint, null, UserPrincipal.class);
    }

    @Override
    protected boolean doCommit() throws Exception {
        getSubject().getPrincipals().addAll(getAllPrincipals());
        return true;
    }

    @Override
    protected boolean doAbort() throws Exception {
        return doLogout();
    }

    @Override
    protected boolean doLogout() throws Exception {
        getSubject().getPrincipals().removeAll(getAllPrincipals());
        return true;
    }

    /**
     * Gets a Jersey client using the specified configuration.
     *
     * @param config the login configuration
     * @return the Jersey client
     */
    @Nonnull
    JerseyRestClient getClient(@Nonnull final LoginJerseyClientConfig config) {
        return new JerseyRestClient(config);
    }
}


text:
<?php

/* TwigBundle:Exception:error.atom.twig */
class __TwigTemplate_89fad3b023425b2315686c307900f10768caf1a0f47d2f2ac810531a4f7e0d98 extends Twig_Template
{
    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        $this->parent = false;

        $this->blocks = array(
        );
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        // line 1
        $this->env->loadTemplate("TwigBundle:Exception:error.xml.twig")->display($context);
    }

    public function getTemplateName()
    {
        return "TwigBundle:Exception:error.atom.twig";
    }

    public function getDebugInfo()
    {
        return array (  19 => 1,);
    }
}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Statistics of aux in UD_Nheengatu-CompLin</title>
    <link rel="root" href=""/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/jquery-ui-redmond.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style-vis.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/hint.css"/>

          home

          edit page
          issue tracker

          <gcse:search></gcse:search>

        This page pertains to UD version 2.

            It appears that you have Javascript disabled.
            Please consider enabling Javascript for this page to see the visualizations.

Treebank Statistics: UD_Nheengatu-CompLin: Relations: aux

This relation is universal.

53 nodes (2%) are attached to their parents as aux.

27 instances of aux (51%) are right-to-left (child precedes parent).
Average distance between parent and child is 1.24528301886792.

The following 1 pairs of parts of speech are connected with aux: <tt>VERB</tt>-<tt>AUX</tt> (53; 100% instances).

# visual-style 2	bgColor:blue
# visual-style 2	fgColor:white
# visual-style 1	bgColor:blue
# visual-style 1	fgColor:white
# visual-style 1 2 aux	color:blue
1	Ayuíri	yuíri	VERB	V	Number=Sing|Person=1|VerbForm=Fin	0	root	_	_
2	putari	putari	AUX	V	VerbForm=Inf	1	aux	_	_
3	se	se	PRON	PRON2	Case=Gen|Number=Sing|Person=1|Poss=Yes|PronType=Prs	4	nmod:poss	_	TokenRange=14:16
4	retama	tetama	NOUN	N	Number=Sing|Rel=Cont	1	obl	_	TokenRange=17:23
5	kití	kití	ADP	ADP	_	4	case	_	SpaceAfter=No|TokenRange=24:28
6	.	.	PUNCT	PUNCT	_	1	punct	_	SpaceAfter=No|TokenRange=28:29

© 2014–2021
            Universal Dependencies contributors.
            Site powered by Annodoc and brat
.


text:
// omnitureHelper.js
// version : 0.0.1
// author : Patrick Gidich
// license : MIT
// https://github.com/simnova/OmnitureHelper

/*jslint indent:2, nomen: true, browser:true, plusplus:true, todo:true */
(function ($, _) {
  "use strict";

  var s, //alias to local variable name
    _events,
    _commerceVariables, //eVar
    _insightVariables, //sProp
    reservedEventNames = [ //TODO:check for the usage of these
      "prodView", // productViews
      "scOpen", // Open / Initialize a new shopping cart
      "scAdd", // Add item(s) to the shopping cart
      "scRemove", // Remove item(s) from the shopping cart
      "scView", // View shopping cart
      "scCheckout", // Beginning of the checkout process
      "purchase" // Completion of a purchase (order)
    ],
    reservedSpropNames = [ //TODO:check for the usage of these
      "campaign",
      "state",
      "zip",
      "events",
      ""
    ];

  /**
  * OmnitureHelper - a microlibrary for omniture tagging.
  *
  * @class OmnitureHelper
  * @constructor
  * @param events {object} (id,name) array of all events that will be used.
  * @param commerceVariables {object} (id,name) array of all commerce variables that will be used.
  * @param insightVariables {object} (id,name) array of all insight variables that will be used.
  */
  function OmnitureHelper(events, commerceVariables, insightVariables) {
    _events = events;
    _commerceVariables = commerceVariables; //eVar
    _insightVariables = insightVariables; //sProp
    window.s = window.s || {};
    s = window.s;
    _ = window._ || {};
    $ = window.$ || {};
  }

  // Private Methods
  function findCommerceVariableId(commerceVariableName) {
    var id;
    try {
      id = _.find(_commerceVariables, function (variable) { return variable.name === commerceVariableName; }).id;
    } catch (e) {
      throw {
        name: "Invalid Argument Exception",
        message: "Parameter: 'commerceVariableName' with value :'" + commerceVariableName + "' not found in commerce variable array"
      };
    }
    return id;
  }

  function findInsightVariableId(insightVariableName) {
    var id;
    try {
      id = _.find(_insightVariables, function (variable) { return variable.name === insightVariableName; }).id;
    } catch (e) {
      throw {
        name: "Invalid Argument Exception",
        message: "Parameter: 'insightVariableName' with value :'" + insightVariableName + "' not found in insight variable array"
      };
    }
    return id;
  }

  function findEventId(eventName) {
    var id;
    try {
      id = _.find(_events, function (eventElement) { return eventElement.name === eventName; }).id;
    } catch (e) {
      throw {
        name: "Invalid Argument Exception",
        message: "Parameter: 'eventName' with value :'" + eventName + "' not found in event array"
      };
    }
    return id;
  }

  // Public Methods
  OmnitureHelper.prototype = {

    /**
    * Clears Variables, Page Name and Events. Useful to be used before setting values in a method
    *
    * @method clearVariablesAndEvents
    */
    clearVariablesAndEvents: function () {
      this.setPageName("");
      this.clearCommerceVariables();
      this.clearInsightVariables();
      this.clearEvents();
    },

    /**
    * Clears Every Commerce Variable.
    *
    * @method clearCommerceVariables
    */
    clearCommerceVariables: function () {
      var value,
        i;
      for (i = 1; i < 100; i++) {
        value = s["eVar" + i];
        if (value !== undefined) {
          s["eVar" + i] = "";
        }
      }
    },

    /**
    * Lists Every Commerce Variable with a Value.
    *
    * @method commerceVariablesWithValues
    */
    commerceVariablesWithValues: function () {
      var commerceVariableList = [],
        i,
        value;
      for (i = 1; i < 100; i++) {
        value = s["eVar" + i];
        // using jquery trim since older browsers don't have trim built in (ie8 etc)
        if (value !== undefined && $.trim(value) !== "") {
          commerceVariableList.push("eVar" + i);
        }
      }
      return commerceVariableList;
    },

    /**
    * Clears Every Insight Variable
    *
    * @method clearInsightVariables
    */
    clearInsightVariables: function () {
      var value,
        i;
      for (i = 1; i < 100; i++) {
        value = s["prop" + i];
        if (value !== undefined) {
          s["prop" + i] = "";
        }
      }
    },

    /**
    * Lists Every Insight Variable with a Value.
    *
    * @method insightVariablesWithValues
    */
    insightVariablesWithValues: function () {
      var commerceVariableList = [],
        i,
        value;
      for (i = 1; i < 100; i++) {
        value = s["prop" + i];
        // using jquery trim since older browsers don't have trim built in (ie8 etc)
        if (value !== undefined && $.trim(value) !== "") {
          commerceVariableList.push("prop" + i);
        }
      }
      return commerceVariableList;
    },

    /**
    * Set Page Name
    *
    * @method setPageName
    * @param pageName {string} The Name of the Page.
    */
    setPageName: function (pageName) {
      s.pageName = pageName; //max 100 bytes
    },

    /**
    * Set Page Url
    *
    * @method setPageUrl
    * @param url {string} The Url To Set.
    */
    setPageUrl: function (url) {
      s.pageURL = url;
    },

    /**
    * Set Channel
    *
    * @method setChannel
    * @param channelName {string} The Channel Name.
    */
    setChannel: function (channelName) {
      s.channel = channelName;
    },

    /**
    * Used only to designate a 404 Page Not Found Error Page.
    *
    * @method setErrorPage
    */
    setErrorPage: function () {
      s.pageType = "errorPage";
    },

    /**
    * Fire Event (s.events) adds another event to the list of events.
    *
    * @method fireEvent
    * @param eventName {string} The key of the event to be added
    */
    fireEvent: function (eventName) {
      //s.events = _;
      //return;
      var eventId = findEventId(eventName);
      if (s.events) { s.events += ",event" + eventId; } else { s.events = "event" + eventId; }
    },

    /**
    * Clear Events (s.events) removes all events.
    *
    * @method fireEvent
    */
    clearEvents: function () {
      s.events = "";
    },

    /**
    * Increment Commerce Variable (s.eVar)
    *
    * @method incrementCommerceCounterValue
    * @param variableName {string} The key associated with the eVar number that is to be incremented.
    */
    incrementCommerceCounterValue: function (eVarName) {
      var eVarId = findCommerceVariableId(eVarName);
      s["eVar" + eVarId] = isNaN(s["eVar" + eVarId]) ? 1 : s["eVar" + eVarId] + 1;
    },

    /**
    * Set Commerce Variable (s.eVar)
    *
    * @method setCommerceVariable
    * @param variableName {string} The key associated with the eVar number that is to be set.
    * @param value {string} The value that is to be recorded.
    */
    setCommerceVariable: function (variableName, value) {
      var variableId = findCommerceVariableId(variableName);
      s["eVar" + variableId] = value;
    },

    /**
    * Set Insight Variable (s.prop)
    *
    * @method setInsightVariable
    * @param variableName {string} The key associated with the prop number that is to be set.
    * @param value {string} The value that is to be recorded.
    */
    setInsightVariable: function (variableName, value) {
      var variableId = findInsightVariableId(variableName);
      s["prop" + variableId] = value;
    },

    /**
    * used to track evars / props with associated page info.
    *
    * @method trackVirtualPageView
    */
    trackVirtualPageView: function () {
      var fn = s.t;
      fn.call(window.s);
    },

    /**
    * used to track evars / props WITHOUT associated page info.
    *
    * @method saveValues
    * @param thisvar {object} this
    */
    saveValues: function (thisvar) {
      //make sure we handle null values
      s.linkTrackEvents = s.linkTrackEvents || "";
      s.linkTrackVars = s.linkTrackVars || "";
      s.events = s.events || "";

      var fn = s.tl,
        linkType = 'o', // Custom Link
        linkName = 'action',
        variableOverrides = null,
        doneAction = null, // we're not using
        //note all events and variables that have values
        activeCommerceVariables = this.commerceVariablesWithValues(), // evars
        activeInsightVariables = this.insightVariablesWithValues(), // props
        activeEvents = s.events.split(","), // events
        linkTrackEventArray = s.linkTrackEvents.split(","),
        linkTrackVarArray = s.linkTrackVars.split(",");

      // force omniture to save values we have set.
      // See #2 in link below:
      // http://blogs.adobe.com/digitalmarketing/analytics/top-five-javascript-implementation-gotchas/
      s.linkTrackEvents = _.chain(_.union(linkTrackEventArray, activeEvents)).uniq().without("").value().join();
      s.linkTrackVars = _.chain(_.union(linkTrackVarArray, activeCommerceVariables, activeInsightVariables, ["events"])).without("").value().join();

      //fn.call(window.s, thisvar, linkType, linkName, variableOverrides);
      fn.call(window.s, thisvar, linkType, linkName);
    },

    /**
    * used to track exit link.
    *
    * @method saveValues
    * @param thisvar {object} this
    * @param linkName {string} the url or some other decription of where the user is going..
    */
    saveExitLink: function (thisvar, linkName) {
      var fn = s.tl,
        linkType = 'e', // Exit Link
        variableOverrides = null,
        doneAction = null; // we're not using
      fn.call(window.s, thisvar, linkType, linkName, variableOverrides);
    }

  };

    // AMD / RequireJS
  if (window !== undefined
      && window.define !== undefined
      && window.define.amd !== undefined) {
    window.define(['jquery', 'lodash', 'omniture'], function ($, _) {
      return OmnitureHelper;
    });
  } else { // included directly via <script> tag
    window.OmnitureHelper = OmnitureHelper;
  }

}());


text:
<!DOCTYPE html>

{{text}}


text:
class wxIDropSource;
class WXDLLIMPEXP_FWD_CORE wxDataObject;
class WXDLLIMPEXP_FWD_CORE wxWindow;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------

// this macro may be used instead for wxDropSource ctor arguments: it will use
// the cursor 'name' from the resources under MSW, but will expand to
// something else under GTK. If you don't use it, you will have to use #ifdef
// in the application code.
#  define wxDROP_ICON(name)	   wxCursor(wxT(#name))
// ----------------------------------------------------------------------------
// wxDropSource is used to start the drag-&-drop operation on associated
// wxDataObject object. It's responsible for giving UI feedback while dragging.
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxDropSource : public wxDropSourceBase
{
public:
    // ctors: if you use default ctor you must call SetData() later!
    //
    // NB: the "wxWindow *win" parameter is unused and is here only for wxGTK
    //     compatibility, as well as both icon parameters
  wxDropSource(wxWindow* win = NULL, const wxCursor& cursorCopy = wxNullCursor, const wxCursor& cursorMove = wxNullCursor, const wxCursor& cursorStop = wxNullCursor);
  wxDropSource(wxDataObject& data, wxWindow* win = NULL, const wxCursor& cursorCopy = wxNullCursor, const wxCursor& cursorMove = wxNullCursor, const wxCursor& cursorStop = wxNullCursor);
  virtual ~wxDropSource();
    // do it (call this in response to a mouse button press, for example)
    // params: if bAllowMove is false, data can be only copied
  wxDragResult DoDragDrop(int flags = wxDrag_CopyOnly) override;
    // overridable: you may give some custom UI feedback during d&d operation
    // in this function (it's called on each mouse move, so it shouldn't be
    // too slow). Just return false if you want default feedback.
  bool GiveFeedback(wxDragResult effect) override;
protected:
  void Init();
private:
  wxIDropSource* m_pIDropSource;
  wxDECLARE_NO_COPY_CLASS(wxDropSource);
};
#endif


text:
package org.apache.accumulo.core.file.rfile;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.accumulo.core.data.ArrayByteSequence;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.PartialKey;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.file.rfile.RelativeKey.SkippR;
import org.apache.accumulo.core.util.MutableByteSequence;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class RelativeKeyTest {

  @Test
  public void testCommonPrefix() {
    // exact matches
    ArrayByteSequence exact = new ArrayByteSequence("abc");
    assertEquals(-1, RelativeKey.getCommonPrefix(exact, exact));
    assertEquals(-1, commonPrefixHelper("", ""));
    assertEquals(-1, commonPrefixHelper("a", "a"));
    assertEquals(-1, commonPrefixHelper("aa", "aa"));
    assertEquals(-1, commonPrefixHelper("aaa", "aaa"));
    assertEquals(-1, commonPrefixHelper("abab", "abab"));
    assertEquals(-1,
        commonPrefixHelper(new String("aaa"), new ArrayByteSequence("aaa").toString()));
    assertEquals(-1,
        commonPrefixHelper("abababababab".substring(3, 6), "ccababababcc".substring(3, 6)));

    // no common prefix
    assertEquals(0, commonPrefixHelper("", "a"));
    assertEquals(0, commonPrefixHelper("a", ""));
    assertEquals(0, commonPrefixHelper("a", "b"));
    assertEquals(0, commonPrefixHelper("aaaa", "bbbb"));

    // some common prefix
    assertEquals(1, commonPrefixHelper("a", "ab"));
    assertEquals(1, commonPrefixHelper("ab", "ac"));
    assertEquals(1, commonPrefixHelper("ab", "ac"));
    assertEquals(2, commonPrefixHelper("aa", "aaaa"));
    assertEquals(4, commonPrefixHelper("aaaaa", "aaaab"));
  }

  private int commonPrefixHelper(String a, String b) {
    return RelativeKey.getCommonPrefix(new ArrayByteSequence(a), new ArrayByteSequence(b));
  }

  @Test
  public void testReadWritePrefix() throws IOException {
    Key prevKey = new Key("row1", "columnfamily1", "columnqualifier1", "columnvisibility1", 1000);
    Key newKey = new Key("row2", "columnfamily2", "columnqualifier2", "columnvisibility2", 3000);
    RelativeKey expected = new RelativeKey(prevKey, newKey);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    expected.write(out);

    RelativeKey actual = new RelativeKey();
    actual.setPrevKey(prevKey);
    actual.readFields(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));

    assertEquals(expected.getKey(), actual.getKey());
  }

  private static ArrayList<Key> expectedKeys;
  private static ArrayList<Value> expectedValues;
  private static ArrayList<Integer> expectedPositions;
  private static ByteArrayOutputStream baos;

  @BeforeAll
  public static void initSource() throws IOException {
    int initialListSize = 10000;

    baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);

    expectedKeys = new ArrayList<>(initialListSize);
    expectedValues = new ArrayList<>(initialListSize);
    expectedPositions = new ArrayList<>(initialListSize);

    Key prev = null;
    int val = 0;
    for (int row = 0; row < 4; row++) {
      String rowS = RFileTest.formatString("r_", row);
      for (int cf = 0; cf < 4; cf++) {
        String cfS = RFileTest.formatString("cf_", cf);
        for (int cq = 0; cq < 4; cq++) {
          String cqS = RFileTest.formatString("cq_", cq);
          for (int cv = 'A'; cv < 'A' + 4; cv++) {
            String cvS = "" + (char) cv;
            for (int ts = 4; ts > 0; ts--) {
              Key k = RFileTest.newKey(rowS, cfS, cqS, cvS, ts);
              k.setDeleted(true);
              Value v = RFileTest.newValue("" + val);
              expectedPositions.add(out.size());
              new RelativeKey(prev, k).write(out);
              prev = k;
              v.write(out);
              expectedKeys.add(k);
              expectedValues.add(v);

              k = RFileTest.newKey(rowS, cfS, cqS, cvS, ts);
              v = RFileTest.newValue("" + val);
              expectedPositions.add(out.size());
              new RelativeKey(prev, k).write(out);
              prev = k;
              v.write(out);
              expectedKeys.add(k);
              expectedValues.add(v);

              val++;
            }
          }
        }
      }
    }
  }

  private DataInputStream in;

  @BeforeEach
  public void setupDataInputStream() {
    in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
    in.mark(0);
  }

  @Test
  public void testSeekBeforeEverything() throws IOException {
    Key seekKey = new Key();
    Key prevKey = new Key();
    Key currKey = null;
    MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0);

    RelativeKey.SkippR skippr =
        RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey, expectedKeys.size());
    assertEquals(1, skippr.skipped);
    assertEquals(new Key(), skippr.prevKey);
    assertEquals(expectedKeys.get(0), skippr.rk.getKey());
    assertEquals(expectedValues.get(0).toString(), value.toString());

    // ensure we can advance after fastskip
    skippr.rk.readFields(in);
    assertEquals(expectedKeys.get(1), skippr.rk.getKey());

    in.reset();

    seekKey = new Key("a", "b", "c", "d", 1);
    seekKey.setDeleted(true);
    skippr = RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey, expectedKeys.size());
    assertEquals(1, skippr.skipped);
    assertEquals(new Key(), skippr.prevKey);
    assertEquals(expectedKeys.get(0), skippr.rk.getKey());
    assertEquals(expectedValues.get(0).toString(), value.toString());

    skippr.rk.readFields(in);
    assertEquals(expectedKeys.get(1), skippr.rk.getKey());
  }

  @Test
  public void testSeekAfterEverythingWrongCount() {
    Key seekKey = new Key("s", "t", "u", "v", 1);
    Key prevKey = new Key();
    Key currKey = null;
    MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0);

    assertThrows(EOFException.class,
        () -> RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey, expectedKeys.size() + 1));
  }

  @Test
  public void testSeekAfterEverything() throws IOException {
    Key seekKey = new Key("s", "t", "u", "v", 1);
    Key prevKey = new Key();
    Key currKey = null;
    MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0);

    SkippR skippr = RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey, expectedKeys.size());
    assertEquals(expectedKeys.size(), skippr.skipped);
  }

  @Test
  public void testSeekMiddle() throws IOException {
    int seekIndex = expectedKeys.size() / 2;
    Key seekKey = expectedKeys.get(seekIndex);
    Key prevKey = new Key();
    Key currKey = null;
    MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0);

    RelativeKey.SkippR skippr =
        RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey, expectedKeys.size());

    assertEquals(seekIndex + 1, skippr.skipped);
    assertEquals(expectedKeys.get(seekIndex - 1), skippr.prevKey);
    assertEquals(expectedKeys.get(seekIndex), skippr.rk.getKey());
    assertEquals(expectedValues.get(seekIndex).toString(), value.toString());

    skippr.rk.readFields(in);
    assertEquals(expectedValues.get(seekIndex + 1).toString(), value.toString());

    // try fast skipping to a key that does not exist
    in.reset();
    Key fKey = expectedKeys.get(seekIndex).followingKey(PartialKey.ROW_COLFAM_COLQUAL);
    int i;
    for (i = seekIndex; expectedKeys.get(i).compareTo(fKey) < 0; i++) {}

    int left = expectedKeys.size();

    skippr =
        RelativeKey.fastSkip(in, expectedKeys.get(i), value, prevKey, currKey, expectedKeys.size());
    assertEquals(i + 1, skippr.skipped);
    left -= skippr.skipped;
    assertEquals(expectedKeys.get(i - 1), skippr.prevKey);
    assertEquals(expectedKeys.get(i), skippr.rk.getKey());
    assertEquals(expectedValues.get(i).toString(), value.toString());

    // try fast skipping to our current location
    skippr = RelativeKey.fastSkip(in, expectedKeys.get(i), value, expectedKeys.get(i - 1),
        expectedKeys.get(i), left);
    assertEquals(0, skippr.skipped);
    assertEquals(expectedKeys.get(i - 1), skippr.prevKey);
    assertEquals(expectedKeys.get(i), skippr.rk.getKey());
    assertEquals(expectedValues.get(i).toString(), value.toString());

    // try fast skipping 1 column family ahead from our current location, testing fastskip from
    // middle of block as opposed to stating at beginning of block
    fKey = expectedKeys.get(i).followingKey(PartialKey.ROW_COLFAM);
    int j;
    for (j = i; expectedKeys.get(j).compareTo(fKey) < 0; j++) {}
    skippr =
        RelativeKey.fastSkip(in, fKey, value, expectedKeys.get(i - 1), expectedKeys.get(i), left);
    assertEquals(j - i, skippr.skipped);
    assertEquals(expectedKeys.get(j - 1), skippr.prevKey);
    assertEquals(expectedKeys.get(j), skippr.rk.getKey());
    assertEquals(expectedValues.get(j).toString(), value.toString());

  }
}


text:
* j/k: next/previous item
* space:	next item or page
* Shift + space:	previous item or page
* n/p:	item scan down/up (list only)
* o: 	open item
* Shift + n/p:	next/previous subscription
* x:	expand folder
* Arrow keys to move around feeds, items and post
* Enter to select

## Application
* r:	refresh
* /:	move cursor to search box
* a:	add a subscription
* =:	increase magnification

## Filters
* 1:	go to all items
* 2:	go to unread items
* 3:	go to starred items

## Acting on items
* s:	star item
* v:	view original
* m:	mark item as read/unread
* <Shift> + a:	mark all as read


text:
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# LANGUAGE QuasiQuotes #-}

module Dhall.Docs.Store (getDocsHomeDirectory, makeHashForDirectory) where

import Dhall.Crypto (SHA256Digest (..))
import Path         (Abs, Dir, Path, Rel, (</>))
import Path.IO      (XdgDirectory (..))

import qualified Control.Monad          as Monad
import qualified Crypto.Hash.SHA256
import qualified Data.ByteString        as ByteString
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8  as ByteString.Char8
import qualified Data.List              as List
import qualified Path
import qualified Path.IO

{-| Fetches the dhall-docs home directory. If @XDG_DATA_HOME@ env var is
    defined, then @${XDG_DATA_HOME}/dhall-docs@ will be returned. Otherwise,
    "${HOME}/.local/share/dhall-docs"
-}
getDocsHomeDirectory :: IO (Path Abs Dir)
getDocsHomeDirectory = do
    dir <- Path.IO.getXdgDir Path.IO.XdgData $ Just $ [Path.reldir|dhall-docs|]
    Path.IO.ensureDir dir
    return dir

{-| Compute the hash for a directory. It takes into account the hierarchy
    structure of it and the contents of its files, but not the name of the
    actual files.

    This is done by computing the hash of each file and sorting them by its
    absolute file name, and computing the hash of the concatenation of all
    hashes.
-}
makeHashForDirectory :: Path Abs Dir -> IO SHA256Digest
makeHashForDirectory dir = do
    (dirs, files) <- Path.IO.listDirRecurRel dir

    let context0 = Crypto.Hash.SHA256.init

    let addDir context directory = do
            let nameBytes = ByteString.Char8.pack (Path.toFilePath directory)

            return $! Crypto.Hash.SHA256.update context nameBytes

    context1 <- Monad.foldM addDir context0 (List.sort dirs)

    let addFile context file = do
            let nameBytes = ByteString.Char8.pack (Path.toFilePath file)

            contentBytes <- ByteString.readFile (Path.toFilePath (dir </> file))

            return $! Crypto.Hash.SHA256.updates context [ nameBytes, contentBytes ]

    context2 <- Monad.foldM addFile context1 (List.sort files)

    return (SHA256Digest (Crypto.Hash.SHA256.finalize context2))


text:
"""
@package mi.dataset.driver.mflm.flort.test.test_driver
@file marine-integrations/mi/dataset/driver/mflm/flort/driver.py
@author Emily Hahn
@brief Test cases for mflm_flort driver

USAGE:
 Make tests verbose and provide stdout
   * From the IDK
       $ bin/dsa/test_driver
       $ bin/dsa/test_driver -i [-t testname]
       $ bin/dsa/test_driver -q [-t testname]
"""

__author__ = 'Emily Hahn'
__license__ = 'Apache 2.0'

import unittest
import os
import shutil

from nose.plugins.attrib import attr
from mock import Mock

from pyon.agent.agent import ResourceAgentState
from interface.objects import ResourceAgentErrorEvent
from interface.objects import ResourceAgentConnectionLostErrorEvent

from mi.core.log import get_logger ; log = get_logger()
from mi.core.instrument.instrument_driver import DriverEvent
from mi.idk.exceptions import SampleTimeout

from mi.idk.dataset.unit_test import DataSetTestCase
from mi.idk.dataset.unit_test import DataSetIntegrationTestCase
from mi.idk.dataset.unit_test import DataSetQualificationTestCase
from mi.dataset.dataset_driver import DataSourceConfigKey, DataSetDriverConfigKeys
from mi.dataset.dataset_driver import DriverParameter, DriverStateKey

from mi.dataset.driver.mflm.flort.driver import MflmFLORTDDataSetDriver, DataSourceKey
from mi.dataset.parser.flortd import FlortdParserDataParticle, \
                                     FlortdRecoveredParserDataParticle, DataParticleType
from mi.dataset.parser.sio_mule_common import StateKey

TELEM_DIR = '/tmp/dsatest1'
RECOV_DIR = '/tmp/dsatest2'

DataSetTestCase.initialize(
    driver_module='mi.dataset.driver.mflm.flort.driver',
    driver_class='MflmFLORTDDataSetDriver',
    agent_resource_id = '123xyz',
    agent_name = 'Agent007',
    agent_packet_config = MflmFLORTDDataSetDriver.stream_config(),
    startup_config = {
        DataSourceConfigKey.HARVESTER:
        {
            DataSourceKey.FLORT_DJ_SIO_TELEMETERED: {
                DataSetDriverConfigKeys.DIRECTORY: TELEM_DIR,
                DataSetDriverConfigKeys.PATTERN: 'node59p1.dat',
                DataSetDriverConfigKeys.FREQUENCY: 1,
                DataSetDriverConfigKeys.FILE_MOD_WAIT_TIME: 2,
            },
            DataSourceKey.FLORT_DJ_SIO_RECOVERED: {
                DataSetDriverConfigKeys.DIRECTORY: RECOV_DIR,
                DataSetDriverConfigKeys.PATTERN: 'FLO*.DAT',
                DataSetDriverConfigKeys.FREQUENCY: 1,
                DataSetDriverConfigKeys.FILE_MOD_WAIT_TIME: 2,
            },
        },
        DataSourceConfigKey.PARSER: {
            DataSourceKey.FLORT_DJ_SIO_TELEMETERED: {},
            DataSourceKey.FLORT_DJ_SIO_RECOVERED: {}
        }
    }
)

###############################################################################
#                            INTEGRATION TESTS                                #
# Device specific integration tests are for                                   #
# testing device specific capabilities                                        #
###############################################################################
@attr('INT', group='mi')
class IntegrationTest(DataSetIntegrationTestCase):

    def test_get(self):
        """
        Test that we can get data from files.  Verify that the driver
        sampling can be started and stopped
        """

        # Start sampling
        self.driver.start_sampling()

        self.clear_async_data()
        self.create_sample_data_set_dir("node59p1_step1.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_1.txt.result.yml',
                         count=1, timeout=10)

        # there is only one file we read from, this example 'appends' data to
        # the end of the node59p1.dat file, and the data from the new append
        # is returned (not including the original data from _step1)
        self.create_sample_data_set_dir("node59p1_step2.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_2.txt.result.yml',
                         count=1, timeout=10)

        # now 'appends' the rest of the data and just check if we get the right number
        self.create_sample_data_set_dir("node59p1_step4.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, count=4, timeout=10)

        # now check recovered data
        self.create_sample_data_set_dir("FLO_short.DAT", RECOV_DIR)
        self.assert_data(FlortdRecoveredParserDataParticle, 'flo_short.result.yml', count=6)

    def test_get_dash(self):
        """
        Test that we can get a particle containing a value that doesn't exist,
        which is marked with '--'
        """
        # Start sampling and watch for an exception
        self.driver.start_sampling()

        self.clear_async_data()
        self.create_sample_data_set_dir("node59p1_dash.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_dash.txt.result.yml',
                         count=2, timeout=10)

    def test_harvester_new_file_exception(self):
        """
        Test an exception raised after the driver is started during
        the file read.  Should call the exception callback.
        """
        self.clear_sample_data()

        harvester_config = self._driver_config()['startup_config'][DataSourceConfigKey.HARVESTER]

        # Start sampling and watch for an exceptions
        self.driver.start_sampling()

        # there are multiple harvester configs, test each one
        for key in harvester_config:
            if key is DataSourceKey.FLORT_DJ_SIO_TELEMETERED:
                # need to override since filename is the whole pattern, no replace with foo
                filename = harvester_config[key][DataSetDriverConfigKeys.PATTERN]
            else:
                filename = harvester_config[key][DataSetDriverConfigKeys.PATTERN].replace('*', 'foo')
            file_dir = harvester_config[key][DataSetDriverConfigKeys.DIRECTORY]
            self.assertIsNotNone(file_dir)

            # create the file so that it is unreadable
            self.create_sample_data_set_dir(filename, file_dir, mode=000, create=True, copy_metadata=False)

            self.assert_exception(IOError)
            # clear out exceptions so we know we get a new one next key
            self.clear_async_data()

    def test_stop_resume(self):
        """
        Pick a state that the driver could have previously stopped at and restart at that point
        """
        # create the telemetered file at the point the driver stopped at
        self.create_sample_data_set_dir("node59p1_step1.dat", TELEM_DIR, "node59p1.dat")
        # create the recovered file
        self.create_sample_data_set_dir("FLO_short.DAT", RECOV_DIR)
        driver_config = self._driver_config()['startup_config']
        fullfile = os.path.join(driver_config['harvester'][DataSourceKey.FLORT_DJ_SIO_TELEMETERED]['directory'],
                            driver_config['harvester'][DataSourceKey.FLORT_DJ_SIO_TELEMETERED]['pattern'])
        mod_time = os.path.getmtime(fullfile)

        # Create and store the new driver state
        self.memento = {
            DataSourceKey.FLORT_DJ_SIO_TELEMETERED: {
                "node59p1.dat": {
                    DriverStateKey.FILE_SIZE: 300,
                    DriverStateKey.FILE_CHECKSUM: 'a640fd577c65ed07ed67f1d2e73d34e2',
                    DriverStateKey.FILE_MOD_DATE: mod_time,
                    DriverStateKey.PARSER_STATE: {StateKey.IN_PROCESS_DATA: [],
                                                  StateKey.UNPROCESSED_DATA:[[0,69], [197,300]],
                                                  StateKey.FILE_SIZE: 300
                    }
                }
            },
            DataSourceKey.FLORT_DJ_SIO_RECOVERED: {
                "FLO_short.DAT": {
                    DriverStateKey.FILE_SIZE: 486,
                    DriverStateKey.FILE_CHECKSUM: '1be7f1e42f0cee76940266e2431c28e9',
                    DriverStateKey.FILE_MOD_DATE: 1406053279.197744,
                    DriverStateKey.INGESTED: False,
                    DriverStateKey.PARSER_STATE: {StateKey.IN_PROCESS_DATA: [[243,324,1,0], [324,405,1,0], [405,486,1,0]],
                                                  StateKey.UNPROCESSED_DATA: [[243,486]],
                                                  StateKey.FILE_SIZE: 486}
                }
            }
        }

        self.driver = self._get_driver_object(memento=self.memento)
        # create some data to parse
        self.clear_async_data()
        # now change the file so the harvester finds it and starts parsing where it left off
        self.create_sample_data_set_dir("node59p1_step2.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)

        self.driver.start_sampling()

        # verify telemetered data is produced
        self.assert_data(FlortdParserDataParticle, 'test_data_2.txt.result.yml',
                         count=1, timeout=10)

        # for recovered, expect the last 3 particles in the file
        self.assert_data(FlortdRecoveredParserDataParticle, 'flo_short_last_3.result.yml',
                         count=3, timeout=10)

    def test_back_fill(self):
        """
        Test a file that has had a section zeroed out and then added back in
        """
        self.driver.start_sampling()

        self.clear_async_data()

        # step 2 contains 2 blocks, start with this and get both since we used them
        # separately in other tests
        self.clear_async_data()
        self.create_sample_data_set_dir("node59p1_step2.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_1-2.txt.result.yml',
                         count=2, timeout=10)

        # This file has had a section of FL data replaced with 0s
        self.clear_async_data()
        self.create_sample_data_set_dir('node59p1_step3.dat', TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_3.txt.result.yml',
                         count=3, timeout=10)

        # Now fill in the zeroed section from step3
        self.clear_async_data()
        self.create_sample_data_set_dir('node59p1_step4.dat', TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_4.txt.result.yml',
                         count=1, timeout=10)

        # start over now, using step 4
        self.driver.stop_sampling()
        self.driver = self._get_driver_object(memento=None)
        self.driver.start_sampling()

        self.clear_async_data()
        self.create_sample_data_set_dir('node59p1_step4.dat', TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_1-4.txt.result.yml',
                         count=6, timeout=10)

    def test_all_good(self):
        """
        Test that a set of data with no bad data, where there is no remaining
        unprocessed data in between
        """
        self.driver.start_sampling()
        self.create_sample_data_set_dir("node59p1_all_good1.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_1-2.txt.result.yml',
                         count=2, timeout=10)

        # make sure we can build the next parser with the empty unprocessed data
        self.create_sample_data_set_dir("node59p1_all_good.dat", TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.assert_data(FlortdParserDataParticle, 'test_data_all_good.txt.result.yml',
                         count=1, timeout=10)

###############################################################################
#                            QUALIFICATION TESTS                              #
# Device specific qualification tests are for                                 #
# testing device specific capabilities                                        #
###############################################################################
@attr('QUAL', group='mi')
class QualificationTest(DataSetQualificationTestCase):

    def test_harvester_new_file_exception(self):
        """
        Test an exception raised after the driver is started during
        the file read.

        exception callback called.
        """
        harvester_config = self._driver_config()['startup_config'][DataSourceConfigKey.HARVESTER]
        for key in harvester_config:
            if key is DataSourceKey.FLORT_DJ_SIO_TELEMETERED:
                # need to override since filename is in pattern, don't replace with foo
                filename = harvester_config[key][DataSetDriverConfigKeys.PATTERN]
            else:
                filename = harvester_config[key][DataSetDriverConfigKeys.PATTERN].replace('*', 'foo')
            file_dir = harvester_config[key][DataSetDriverConfigKeys.DIRECTORY]

            self.assert_new_file_exception(filename, file_dir)
            # stop sampling so we can start again
            self.assert_stop_sampling()

            # stop and restart the agent so we can test the next key new file exception
            self.stop_dataset_agent_client()
            self.init_dataset_agent_client()

    def test_publish_path(self):
        """
        Setup an agent/driver/harvester/parser and verify that data is
        published out the agent
        """
        self.create_sample_data_set_dir('node59p1_step1.dat', TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.create_sample_data_set_dir('FLO_short.DAT', RECOV_DIR)

        self.assert_initialize()

        try:
            # Verify we get one telemetered sample
            result = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 1)
            log.info("result telem: %s", result)
            # Verify values
            self.assert_data_values(result, 'test_data_1.txt.result.yml')

            # Verify we get the 6 samples from the recovered file
            result = self.data_subscribers.get_samples(DataParticleType.SAMPLE_RECOVERED, 6)
            self.assert_data_values(result, 'flo_short.result.yml')

        except Exception as e:
            log.error("Exception trapped: %s", e)
            self.fail("Sample timeout.")

    def test_large_import(self):
        """
        Test importing a large number of samples from the telemetered and recovered files at once
        """
        self.create_sample_data_set_dir('node59p1_longer.dat', TELEM_DIR, "node59p1.dat", copy_metadata=False)
        self.create_sample_data_set_dir('FLO15908.DAT', RECOV_DIR)
        self.assert_initialize()

        # get the telemetered samples
        result1 = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 12, 30)
        # get the recovered samples
        result2 = self.data_subscribers.get_samples(DataParticleType.SAMPLE_RECOVERED, 96, 30)

    def test_stop_start_telem(self):
        """
        Test the agents ability to start data flowing, stop, then restart
        at the correct spot.
        """
        log.info("CONFIG: %s", self._agent_config())
        self.create_sample_data_set_dir('node59p1_step2.dat', TELEM_DIR, "node59p1.dat", copy_metadata=False)

        self.assert_initialize(final_state=ResourceAgentState.COMMAND)

        # Slow down processing to 1 per second to give us time to stop
        self.dataset_agent_client.set_resource({DriverParameter.RECORDS_PER_SECOND: 1})
        self.assert_start_sampling()

        # Verify we get one sample
        try:
            # Read the first file and verify the data
            result = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 2)
            log.debug("RESULT: %s", result)

            # Verify values
            self.assert_data_values(result, 'test_data_1-2.txt.result.yml')
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)

            self.create_sample_data_set_dir('node59p1_step4.dat', TELEM_DIR, "node59p1.dat",
                                            copy_metadata=False)
            # Now read the first records of the second file then stop
            result1 = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 2)
            log.debug("RESULT 1: %s", result1)
            self.assert_stop_sampling()
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)
            self.assert_sample_queue_size(DataParticleType.SAMPLE_RECOVERED, 0)

            # Restart sampling and ensure we get the last 2 records of the file
            self.assert_start_sampling()
            result2 = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 2)
            log.debug("RESULT 2: %s", result2)
            result = result1
            result.extend(result2)
            log.debug("RESULT: %s", result)
            self.assert_data_values(result, 'test_data_3-4.txt.result.yml')
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)
            self.assert_sample_queue_size(DataParticleType.SAMPLE_RECOVERED, 0)

        except SampleTimeout as e:
            log.error("Exception trapped: %s", e, exc_info=True)
            self.fail("Sample timeout.")

    def test_stop_start_recov(self):
        """
        Test the agents ability to start data flowing, stop, then restart
        at the correct spot.
        """
        log.info("CONFIG: %s", self._agent_config())
        self.create_sample_data_set_dir('FLO_short.DAT', RECOV_DIR)

        self.assert_initialize(final_state=ResourceAgentState.COMMAND)

        # Slow down processing to 1 per second to give us time to stop
        self.dataset_agent_client.set_resource({DriverParameter.RECORDS_PER_SECOND: 1})
        self.assert_start_sampling()

        try:
            # read the first records of the file then stop
            result = self.data_subscribers.get_samples(DataParticleType.SAMPLE_RECOVERED, 3)
            log.debug("RESULT 1: %s", result)
            self.assert_stop_sampling()

            # Restart sampling and ensure we get the last 3 records of the file
            self.assert_start_sampling()
            result2 = self.data_subscribers.get_samples(DataParticleType.SAMPLE_RECOVERED, 3)
            log.debug("RESULT 2: %s", result2)
            result.extend(result2)
            log.debug("RESULT: %s", result)
            self.assert_data_values(result, 'flo_short.result.yml')
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)
            self.assert_sample_queue_size(DataParticleType.SAMPLE_RECOVERED, 0)

        except SampleTimeout as e:
            log.error("Exception trapped: %s", e, exc_info=True)
            self.fail("Sample timeout.")

    def test_shutdown_restart_telem(self):
        """
        Test a full stop of the dataset agent, then restart the agent and
        confirm it restarts at the correct spot.
        """
        log.info("CONFIG: %s", self._agent_config())
        self.create_sample_data_set_dir('node59p1_step2.dat', TELEM_DIR, "node59p1.dat",
                                        copy_metadata=False)

        self.assert_initialize(final_state=ResourceAgentState.COMMAND)

        # Slow down processing to 1 per second to give us time to stop
        self.dataset_agent_client.set_resource({DriverParameter.RECORDS_PER_SECOND: 1})
        self.assert_start_sampling()

        # Verify we get one sample
        try:
            # Read the first file and verify the data
            result = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 2)
            log.debug("RESULT: %s", result)

            # Verify values
            self.assert_data_values(result, 'test_data_1-2.txt.result.yml')
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)

            self.create_sample_data_set_dir('node59p1_step4.dat', TELEM_DIR, "node59p1.dat",
                                            copy_metadata=False)
            # Now read the first records of the second file then stop
            result1 = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 2)
            log.debug("RESULT 1: %s", result1)
            self.assert_stop_sampling()
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)
            self.assert_sample_queue_size(DataParticleType.SAMPLE_RECOVERED, 0)

            # stop and re-start the agent
            self.stop_dataset_agent_client()
            self.init_dataset_agent_client()
            # re-initialize
            self.assert_initialize(final_state=ResourceAgentState.COMMAND)
            # Slow down processing to 1 per second to give us time to stop again
            self.dataset_agent_client.set_resource({DriverParameter.RECORDS_PER_SECOND: 1})
            # Restart sampling and ensure we get the last 4 records of the file
            self.assert_start_sampling()
            result2 = self.data_subscribers.get_samples(DataParticleType.SAMPLE, 2)
            log.debug("RESULT 2: %s", result2)
            result = result1
            result.extend(result2)
            log.debug("RESULT: %s", result)
            self.assert_data_values(result, 'test_data_3-4.txt.result.yml')
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)
            self.assert_sample_queue_size(DataParticleType.SAMPLE_RECOVERED, 0)

        except SampleTimeout as e:
            log.error("Exception trapped: %s", e, exc_info=True)
            self.fail("Sample timeout.")

    def test_shutdown_restart_recov(self):
        """
        Test the agents ability to start data flowing, stop, then restart
        at the correct spot.
        """
        log.info("CONFIG: %s", self._agent_config())
        self.create_sample_data_set_dir('FLO_short.DAT', RECOV_DIR)

        self.assert_initialize(final_state=ResourceAgentState.COMMAND)

        # Slow down processing to 1 per second to give us time to stop
        self.dataset_agent_client.set_resource({DriverParameter.RECORDS_PER_SECOND: 1})
        self.assert_start_sampling()

        try:
            # read the first records of the file then stop
            result = self.data_subscribers.get_samples(DataParticleType.SAMPLE_RECOVERED, 3)
            log.debug("RESULT 1: %s", result)
            self.assert_stop_sampling()

            # stop and re-start the agent
            self.stop_dataset_agent_client()
            self.init_dataset_agent_client()
            # re-initialize
            self.assert_initialize()

            # ensure we get the last 3 records of the file
            result2 = self.data_subscribers.get_samples(DataParticleType.SAMPLE_RECOVERED, 3)
            log.debug("RESULT 2: %s", result2)
            result.extend(result2)
            log.debug("RESULT: %s", result)
            self.assert_data_values(result, 'flo_short.result.yml')
            self.assert_sample_queue_size(DataParticleType.SAMPLE, 0)
            self.assert_sample_queue_size(DataParticleType.SAMPLE_RECOVERED, 0)

        except SampleTimeout as e:
            log.error("Exception trapped: %s", e, exc_info=True)
            self.fail("Sample timeout.")


text:
from restclients.canvas import Canvas

class ExternalToolsException(Exception):
    pass

class ExternalTools(Canvas):
    def get_external_tools_in_account(self, account_id, params={}):
        """
        Return external tools for the passed canvas account id.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.index
        """
        url = "/api/v1/accounts/%s/external_tools" % account_id

        external_tools = []
        for data in self._get_paged_resource(url, params=params):
            external_tools.append(self._external_tool_from_json(data))
        return external_tools

    def get_external_tools_in_account_by_sis_id(self, sis_id):
        """
        Return external tools for given account sis id.
        """
        return self.get_external_tools_in_account(self._sis_id(sis_id,
                                                               "account"))

    def get_external_tools_in_course(self, course_id, params={}):
        """
        Return external tools for the passed canvas course id.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.index
        """
        url = "/api/v1/courses/%s/external_tools" % course_id

        external_tools = []
        for data in self._get_paged_resource(url, params=params):
            external_tools.append(self._external_tool_from_json(data))
        return external_tools

    def get_external_tools_in_course_by_sis_id(self, sis_id):
        """
        Return external tools for given course sis id.
        """
        return self.get_external_tools_in_course(self._sis_id(sis_id,
                                                              "course"))

    def create_external_tool_in_course(self, course_id, json_data):
        return self._create_external_tool('courses', course_id, json_data)

    def create_external_tool_in_account(self, account_id, json_data):
        return self._create_external_tool('accounts', account_id, json_data)

    def _create_external_tool(self, context, context_id, json_data):
        """
        Create an external tool using the passed json_data.

        context is either 'courses' or 'accounts'.
        context_id is the Canvas course_id or account_id, depending on context.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.create
        """
        url = '/api/v1/%s/%s/external_tools' % (context, context_id)
        data = self._post_resource(url, body=json_data)
        return self._external_tool_from_json(data)

    def update_external_tool_in_course(self, course_id, external_tool_id,
                                       json_data):
        return self._update_external_tool('courses', course_id,
                                          external_tool_id, json_data)

    def update_external_tool_in_account(self, account_id, external_tool_id,
                                        json_data):
        return self._update_external_tool('accounts', account_id,
                                          external_tool_id, json_data)

    def _update_external_tool(self, context, context_id, external_tool_id,
                              json_data):
        """
        Update the external tool identified by external_tool_id with the passed
        json data.

        context is either 'courses' or 'accounts'.
        context_id is the course_id or account_id, depending on context

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.update
        """
        url = '/api/v1/%s/%s/external_tools/%s' % (context, context_id,
                                                   external_tool_id)
        data = self._put_resource(url, body=json_data)
        return self._external_tool_from_json(data)

    def delete_external_tool_in_course(self, course_id, external_tool_id):
        return self._delete_external_tool('courses', course_id,
                                          external_tool_id)

    def delete_external_tool_in_account(self, account_id, external_tool_id):
        return self._delete_external_tool('accounts', account_id,
                                          external_tool_id)

    def _delete_external_tool(self, context, context_id, external_tool_id):
        """
        Delete the external tool identified by external_tool_id.

        context is either 'courses' or 'accounts'.
        context_id is the course_id or account_id, depending on context

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.destroy
        """
        url = '/api/v1/%s/%s/external_tools/%s' % (context, context_id,
                                                   external_tool_id)
        response = self._delete_resource(url)
        return True

    def _external_tool_from_json(self, data):
        return data

    def _get_sessionless_launch_url(self, tool_id, context, context_id):
        """
        Get a sessionless launch url for an external tool.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.generate_sessionless_launch
        """
        url = "/api/v1/%ss/%s/external_tools/sessionless_launch" % (context, context_id)
        params = {
            "id": tool_id
        }

        return self._get_resource(url, params)

    def get_sessionless_launch_url_from_account(self, tool_id, account_id):
        """
        Get a sessionless launch url for an external tool.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.generate_sessionless_launch
        """
        return self._get_sessionless_launch_url(tool_id, "account", account_id)

    def get_sessionless_launch_url_from_account_sis_id(self, tool_id, account_sis_id):
        """
        Get a sessionless launch url for an external tool.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.generate_sessionless_launch
        """
        return self.get_sessionless_launch_url_from_account(
            tool_id, self._sis_id(account_sis_id, "account"))

    def get_sessionless_launch_url_from_course(self, tool_id, course_id):
        """
        Get a sessionless launch url for an external tool.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.generate_sessionless_launch
        """
        return self._get_sessionless_launch_url(tool_id, "course", course_id)

    def get_sessionless_launch_url_from_course_sis_id(self, tool_id, course_sis_id):
        """
        Get a sessionless launch url for an external tool.

        https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.generate_sessionless_launch
        """
        return self.get_sessionless_launch_url_from_course(
            tool_id, self._sis_id(course_sis_id, "course"))


text:
<?php $document=$document->row_array(); ?>
	<form class="form-horizontal formular" id="form_edit" method="post" action="<?php echo site_url($document['aksi_print']);?>" name="detailreport" target="_blank">

<?php echo $document['title_document']?>

	<?php
		if($document['attrib']!=NULL){?>
	<fieldset>
		<legend>Kondisi</legend>

			<?php $input=explode(',',$document['attrib']);
			for($a=0;$a<count($input);$a++){
				$this->load->view('report/category/'.$input[$a]);
                                echo "
";

			} ?>

	</fieldset><?php };?>

	<?php if($document['kolom']!=NULL){?>
	<fieldset>
		<legend>Kolom</legend>

			<input type="hidden" name="category" value="<?php echo $document['aksi_print']?>">
			<input type="hidden" name="idcategory" value="<?php echo $document['id']?>">
			<?php
					$kolom=unserialize($document['kolom']);
					foreach($kolom as $key=>$item){

							echo form_checkbox("kolom[$key]",'1','checked').' '.$item.'
';

					}
			?>

	</fieldset>
	<?php } ?>

			<input class="btn btn-primary" type="submit" name="print" value="Print Preview" style="margin-left:0px;">

</form>


text:
package com.azure.resourcemanager.apimanagement.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.resourcemanager.apimanagement.fluent.models.BackendContractInner;
import com.azure.resourcemanager.apimanagement.models.BackendContract;
import com.azure.resourcemanager.apimanagement.models.BackendCredentialsContract;
import com.azure.resourcemanager.apimanagement.models.BackendProperties;
import com.azure.resourcemanager.apimanagement.models.BackendProtocol;
import com.azure.resourcemanager.apimanagement.models.BackendProxyContract;
import com.azure.resourcemanager.apimanagement.models.BackendReconnectContract;
import com.azure.resourcemanager.apimanagement.models.BackendTlsProperties;
import com.azure.resourcemanager.apimanagement.models.BackendUpdateParameters;

public final class BackendContractImpl implements BackendContract, BackendContract.Definition, BackendContract.Update {
    private BackendContractInner innerObject;

    private final com.azure.resourcemanager.apimanagement.ApiManagementManager serviceManager;

    public String id() {
        return this.innerModel().id();
    }

    public String name() {
        return this.innerModel().name();
    }

    public String type() {
        return this.innerModel().type();
    }

    public String url() {
        return this.innerModel().url();
    }

    public BackendProtocol protocol() {
        return this.innerModel().protocol();
    }

    public String title() {
        return this.innerModel().title();
    }

    public String description() {
        return this.innerModel().description();
    }

    public String resourceId() {
        return this.innerModel().resourceId();
    }

    public BackendProperties properties() {
        return this.innerModel().properties();
    }

    public BackendCredentialsContract credentials() {
        return this.innerModel().credentials();
    }

    public BackendProxyContract proxy() {
        return this.innerModel().proxy();
    }

    public BackendTlsProperties tls() {
        return this.innerModel().tls();
    }

    public BackendContractInner innerModel() {
        return this.innerObject;
    }

    private com.azure.resourcemanager.apimanagement.ApiManagementManager manager() {
        return this.serviceManager;
    }

    private String resourceGroupName;

    private String serviceName;

    private String backendId;

    private String createIfMatch;

    private String updateIfMatch;

    private BackendUpdateParameters updateParameters;

    public BackendContractImpl withExistingService(String resourceGroupName, String serviceName) {
        this.resourceGroupName = resourceGroupName;
        this.serviceName = serviceName;
        return this;
    }

    public BackendContract create() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBackends()
                .createOrUpdateWithResponse(
                    resourceGroupName, serviceName, backendId, this.innerModel(), createIfMatch, Context.NONE)
                .getValue();
        return this;
    }

    public BackendContract create(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBackends()
                .createOrUpdateWithResponse(
                    resourceGroupName, serviceName, backendId, this.innerModel(), createIfMatch, context)
                .getValue();
        return this;
    }

    BackendContractImpl(String name, com.azure.resourcemanager.apimanagement.ApiManagementManager serviceManager) {
        this.innerObject = new BackendContractInner();
        this.serviceManager = serviceManager;
        this.backendId = name;
        this.createIfMatch = null;
    }

    public BackendContractImpl update() {
        this.updateIfMatch = null;
        this.updateParameters = new BackendUpdateParameters();
        return this;
    }

    public BackendContract apply() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBackends()
                .updateWithResponse(
                    resourceGroupName, serviceName, backendId, updateIfMatch, updateParameters, Context.NONE)
                .getValue();
        return this;
    }

    public BackendContract apply(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBackends()
                .updateWithResponse(resourceGroupName, serviceName, backendId, updateIfMatch, updateParameters, context)
                .getValue();
        return this;
    }

    BackendContractImpl(
        BackendContractInner innerObject, com.azure.resourcemanager.apimanagement.ApiManagementManager serviceManager) {
        this.innerObject = innerObject;
        this.serviceManager = serviceManager;
        this.resourceGroupName = Utils.getValueFromIdByName(innerObject.id(), "resourceGroups");
        this.serviceName = Utils.getValueFromIdByName(innerObject.id(), "service");
        this.backendId = Utils.getValueFromIdByName(innerObject.id(), "backends");
    }

    public BackendContract refresh() {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBackends()
                .getWithResponse(resourceGroupName, serviceName, backendId, Context.NONE)
                .getValue();
        return this;
    }

    public BackendContract refresh(Context context) {
        this.innerObject =
            serviceManager
                .serviceClient()
                .getBackends()
                .getWithResponse(resourceGroupName, serviceName, backendId, context)
                .getValue();
        return this;
    }

    public void reconnect() {
        serviceManager.backends().reconnect(resourceGroupName, serviceName, backendId);
    }

    public Response<Void> reconnectWithResponse(BackendReconnectContract parameters, Context context) {
        return serviceManager
            .backends()
            .reconnectWithResponse(resourceGroupName, serviceName, backendId, parameters, context);
    }

    public BackendContractImpl withUrl(String url) {
        if (isInCreateMode()) {
            this.innerModel().withUrl(url);
            return this;
        } else {
            this.updateParameters.withUrl(url);
            return this;
        }
    }

    public BackendContractImpl withProtocol(BackendProtocol protocol) {
        if (isInCreateMode()) {
            this.innerModel().withProtocol(protocol);
            return this;
        } else {
            this.updateParameters.withProtocol(protocol);
            return this;
        }
    }

    public BackendContractImpl withTitle(String title) {
        if (isInCreateMode()) {
            this.innerModel().withTitle(title);
            return this;
        } else {
            this.updateParameters.withTitle(title);
            return this;
        }
    }

    public BackendContractImpl withDescription(String description) {
        if (isInCreateMode()) {
            this.innerModel().withDescription(description);
            return this;
        } else {
            this.updateParameters.withDescription(description);
            return this;
        }
    }

    public BackendContractImpl withResourceId(String resourceId) {
        if (isInCreateMode()) {
            this.innerModel().withResourceId(resourceId);
            return this;
        } else {
            this.updateParameters.withResourceId(resourceId);
            return this;
        }
    }

    public BackendContractImpl withProperties(BackendProperties properties) {
        if (isInCreateMode()) {
            this.innerModel().withProperties(properties);
            return this;
        } else {
            this.updateParameters.withProperties(properties);
            return this;
        }
    }

    public BackendContractImpl withCredentials(BackendCredentialsContract credentials) {
        if (isInCreateMode()) {
            this.innerModel().withCredentials(credentials);
            return this;
        } else {
            this.updateParameters.withCredentials(credentials);
            return this;
        }
    }

    public BackendContractImpl withProxy(BackendProxyContract proxy) {
        if (isInCreateMode()) {
            this.innerModel().withProxy(proxy);
            return this;
        } else {
            this.updateParameters.withProxy(proxy);
            return this;
        }
    }

    public BackendContractImpl withTls(BackendTlsProperties tls) {
        if (isInCreateMode()) {
            this.innerModel().withTls(tls);
            return this;
        } else {
            this.updateParameters.withTls(tls);
            return this;
        }
    }

    public BackendContractImpl withIfMatch(String ifMatch) {
        if (isInCreateMode()) {
            this.createIfMatch = ifMatch;
            return this;
        } else {
            this.updateIfMatch = ifMatch;
            return this;
        }
    }

    private boolean isInCreateMode() {
        return this.innerModel().id() == null;
    }
}