text:
package org.keycloak.saml.processing.core.util;

import org.keycloak.saml.common.PicketLinkLogger;
import org.keycloak.saml.common.PicketLinkLoggerFactory;
import org.keycloak.saml.common.constants.JBossSAMLURIConstants;
import org.keycloak.saml.common.constants.WSTrustConstants;
import org.keycloak.saml.common.exceptions.ParsingException;
import org.keycloak.saml.common.exceptions.ProcessingException;
import org.keycloak.saml.common.util.Base64;
import org.keycloak.saml.common.util.DocumentUtil;
import org.keycloak.saml.common.util.StringUtil;
import org.keycloak.saml.common.util.SystemPropertiesUtil;
import org.keycloak.saml.common.util.TransformerUtil;
import org.keycloak.dom.xmlsec.w3.xmldsig.DSAKeyValueType;
import org.keycloak.dom.xmlsec.w3.xmldsig.KeyValueType;
import org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType;
import org.keycloak.dom.xmlsec.w3.xmldsig.SignatureType;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.dsig.CanonicalizationMethod;
import javax.xml.crypto.dsig.DigestMethod;
import javax.xml.crypto.dsig.Reference;
import javax.xml.crypto.dsig.SignatureMethod;
import javax.xml.crypto.dsig.SignedInfo;
import javax.xml.crypto.dsig.Transform;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureException;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.dom.DOMSignContext;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
import javax.xml.crypto.dsig.keyinfo.KeyValue;
import javax.xml.crypto.dsig.keyinfo.X509Data;
import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
import javax.xml.crypto.dsig.spec.TransformParameterSpec;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayInputStream;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.KeyException;
import java.security.KeyPair;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Utility for XML Signature Note: You can change the canonicalization method type by using the system property
 * "picketlink.xmlsig.canonicalization"
 *
 * @author Anil.Saldhana@redhat.com
 * @author alessio.soldano@jboss.com
 * @since Dec 15, 2008
 */
public class XMLSignatureUtil {

    private static final PicketLinkLogger logger = PicketLinkLoggerFactory.getLogger();

    // Set some system properties and Santuario providers. Run this block before any other class initialization.
    static {
        ProvidersUtil.ensure();
        SystemPropertiesUtil.ensure();
        String keyInfoProp = SecurityActions.getSystemProperty("picketlink.xmlsig.includeKeyInfo", null);
        if (StringUtil.isNotNull(keyInfoProp)) {
            includeKeyInfoInSignature = Boolean.parseBoolean(keyInfoProp);
        }
    }

    ;

    private static String canonicalizationMethodType = CanonicalizationMethod.EXCLUSIVE;

    private static XMLSignatureFactory fac = getXMLSignatureFactory();

    /**
     * By default, we include the keyinfo in the signature
     */
    private static boolean includeKeyInfoInSignature = true;

    private static XMLSignatureFactory getXMLSignatureFactory() {
        XMLSignatureFactory xsf = null;

        try {
            xsf = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig");
        } catch (NoSuchProviderException ex) {
            try {
                xsf = XMLSignatureFactory.getInstance("DOM");
            } catch (Exception err) {
                throw new RuntimeException(logger.couldNotCreateInstance("DOM", err));
            }
        }
        return xsf;
    }

    /**
     * Use this method to not include the KeyInfo in the signature
     *
     * @param includeKeyInfoInSignature
     *
     * @since v2.0.1
     */
    public static void setIncludeKeyInfoInSignature(boolean includeKeyInfoInSignature) {
        XMLSignatureUtil.includeKeyInfoInSignature = includeKeyInfoInSignature;
    }

    /**
     * Sign a node in a document
     *
     * @param doc
     * @param nodeToBeSigned
     * @param keyPair
     * @param digestMethod
     * @param signatureMethod
     * @param referenceURI
     *
     * @return
     *
     * @throws ParserConfigurationException
     * @throws XMLSignatureException
     * @throws MarshalException
     * @throws GeneralSecurityException
     */
    public static Document sign(Document doc, Node nodeToBeSigned, KeyPair keyPair, String digestMethod,
                                String signatureMethod, String referenceURI, X509Certificate x509Certificate,
                                String canonicalizationMethodType) throws ParserConfigurationException, GeneralSecurityException,
            MarshalException, XMLSignatureException {
        if (nodeToBeSigned == null)
            throw logger.nullArgumentError("Node to be signed");

        if (logger.isTraceEnabled()) {
            logger.trace("Document to be signed=" + DocumentUtil.asString(doc));
        }

        Node parentNode = nodeToBeSigned.getParentNode();

        // Let us create a new Document
        Document newDoc = DocumentUtil.createDocument();
        // Import the node
        Node signingNode = newDoc.importNode(nodeToBeSigned, true);
        newDoc.appendChild(signingNode);

        if (!referenceURI.isEmpty()) {
            propagateIDAttributeSetup(nodeToBeSigned, newDoc.getDocumentElement());
        }
        newDoc = sign(newDoc, keyPair, digestMethod, signatureMethod, referenceURI, x509Certificate, canonicalizationMethodType);

        // if the signed element is a SAMLv2.0 assertion we need to move the signature element to the position
        // specified in the schema (before the assertion subject element).
        if (nodeToBeSigned.getLocalName().equals("Assertion")
                && WSTrustConstants.SAML2_ASSERTION_NS.equals(nodeToBeSigned.getNamespaceURI())) {
            Node signatureNode = DocumentUtil.getElement(newDoc, new QName(WSTrustConstants.DSIG_NS, "Signature"));
            Node subjectNode = DocumentUtil.getElement(newDoc, new QName(WSTrustConstants.SAML2_ASSERTION_NS, "Subject"));
            if (signatureNode != null && subjectNode != null) {
                newDoc.getDocumentElement().removeChild(signatureNode);
                newDoc.getDocumentElement().insertBefore(signatureNode, subjectNode);
            }
        }

        // Now let us import this signed doc into the original document we got in the method call
        Node signedNode = doc.importNode(newDoc.getFirstChild(), true);

        if (!referenceURI.isEmpty()) {
            propagateIDAttributeSetup(newDoc.getDocumentElement(), (Element) signedNode);
        }

        parentNode.replaceChild(signedNode, nodeToBeSigned);
        // doc.getDocumentElement().replaceChild(signedNode, nodeToBeSigned);

        return doc;
    }

    /**
     * Sign only specified element (assumption is that it already has ID attribute set)
     *
     * @param elementToSign element to sign with set ID
     * @param nextSibling child of elementToSign, which will be used as next sibling of created signature
     * @param keyPair
     * @param digestMethod
     * @param signatureMethod
     * @param referenceURI
     *
     * @throws GeneralSecurityException
     * @throws MarshalException
     * @throws XMLSignatureException
     */
    public static void sign(Element elementToSign, Node nextSibling, KeyPair keyPair, String digestMethod,
                            String signatureMethod, String referenceURI, String canonicalizationMethodType)
            throws GeneralSecurityException, MarshalException, XMLSignatureException {
        sign(elementToSign, nextSibling, keyPair, digestMethod, signatureMethod, referenceURI, null, canonicalizationMethodType);
    }

    /**
     * Sign only specified element (assumption is that it already has ID attribute set)
     *
     * @param elementToSign element to sign with set ID
     * @param nextSibling child of elementToSign, which will be used as next sibling of created signature
     * @param keyPair
     * @param digestMethod
     * @param signatureMethod
     * @param referenceURI
     * @param x509Certificate {@link X509Certificate} to be placed in SignedInfo
     *
     * @throws GeneralSecurityException
     * @throws MarshalException
     * @throws XMLSignatureException
     * @since 2.5.0
     */
    public static void sign(Element elementToSign, Node nextSibling, KeyPair keyPair, String digestMethod,
                            String signatureMethod, String referenceURI, X509Certificate x509Certificate, String canonicalizationMethodType)
            throws GeneralSecurityException, MarshalException, XMLSignatureException {
        PrivateKey signingKey = keyPair.getPrivate();
        PublicKey publicKey = keyPair.getPublic();

        DOMSignContext dsc = new DOMSignContext(signingKey, elementToSign, nextSibling);

        signImpl(dsc, digestMethod, signatureMethod, referenceURI, publicKey, x509Certificate, canonicalizationMethodType);
    }

    /**
     * Setup the ID attribute into destElement depending on the isId flag of an attribute of
     * sourceNode.
     *
     * @param sourceNode
     */
    public static void propagateIDAttributeSetup(Node sourceNode, Element destElement) {
        NamedNodeMap nnm = sourceNode.getAttributes();
        for (int i = 0; i < nnm.getLength(); i++) {
            Attr attr = (Attr) nnm.item(i);
            if (attr.isId()) {
                destElement.setIdAttribute(attr.getName(), true);
                break;
            }
        }
    }

    /**
     * Sign the root element
     *
     * @param doc
     * @param digestMethod
     * @param signatureMethod
     * @param referenceURI
     *
     * @return
     *
     * @throws GeneralSecurityException
     * @throws XMLSignatureException
     * @throws MarshalException
     */
    public static Document sign(Document doc, KeyPair keyPair, String digestMethod, String signatureMethod, String referenceURI, String canonicalizationMethodType)
            throws GeneralSecurityException, MarshalException, XMLSignatureException {
        return sign(doc, keyPair, digestMethod, signatureMethod, referenceURI, null, canonicalizationMethodType);
    }

    /**
     * Sign the root element
     *
     * @param doc
     * @param digestMethod
     * @param signatureMethod
     * @param referenceURI
     *
     * @return
     *
     * @throws GeneralSecurityException
     * @throws XMLSignatureException
     * @throws MarshalException
     * @since 2.5.0
     */
    public static Document sign(Document doc, KeyPair keyPair, String digestMethod, String signatureMethod, String referenceURI,
                                X509Certificate x509Certificate, String canonicalizationMethodType)
            throws GeneralSecurityException, MarshalException, XMLSignatureException {
        logger.trace("Document to be signed=" + DocumentUtil.asString(doc));
        PrivateKey signingKey = keyPair.getPrivate();
        PublicKey publicKey = keyPair.getPublic();

        DOMSignContext dsc = new DOMSignContext(signingKey, doc.getDocumentElement());

        signImpl(dsc, digestMethod, signatureMethod, referenceURI, publicKey, x509Certificate, canonicalizationMethodType);

        return doc;
    }

    /**
     * Sign the root element
     *
     *
     * @return
     *
     * @throws GeneralSecurityException
     * @throws XMLSignatureException
     * @throws MarshalException
     */
    public static Document sign(SignatureUtilTransferObject dto, String canonicalizationMethodType) throws GeneralSecurityException, MarshalException,
            XMLSignatureException {
        Document doc = dto.getDocumentToBeSigned();
        KeyPair keyPair = dto.getKeyPair();
        Node nextSibling = dto.getNextSibling();
        String digestMethod = dto.getDigestMethod();
        String referenceURI = dto.getReferenceURI();
        String signatureMethod = dto.getSignatureMethod();

        logger.trace("Document to be signed=" + DocumentUtil.asString(doc));

        PrivateKey signingKey = keyPair.getPrivate();
        PublicKey publicKey = keyPair.getPublic();

        DOMSignContext dsc = new DOMSignContext(signingKey, doc.getDocumentElement(), nextSibling);

        signImpl(dsc, digestMethod, signatureMethod, referenceURI, publicKey, dto.getX509Certificate(), canonicalizationMethodType);

        return doc;
    }

    /**
     * Validate a signed document with the given public key
     *
     * @param signedDoc
     * @param publicKey
     *
     * @return
     *
     * @throws MarshalException
     * @throws XMLSignatureException
     */
    @SuppressWarnings("unchecked")
    public static boolean validate(Document signedDoc, Key publicKey) throws MarshalException, XMLSignatureException {
        if (signedDoc == null)
            throw logger.nullArgumentError("Signed Document");

        propagateIDAttributeSetup(signedDoc.getDocumentElement(), signedDoc.getDocumentElement());

        NodeList nl = signedDoc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature");

        if (nl == null || nl.getLength() == 0) {
            throw logger.nullValueError("Cannot find Signature element");
        }

        if (publicKey == null)
            throw logger.nullValueError("Public Key");

        for (int i = 0; i < nl.getLength(); i++) {
            DOMValidateContext valContext = new DOMValidateContext(publicKey, nl.item(i));
            XMLSignature signature = fac.unmarshalXMLSignature(valContext);

            boolean coreValidity = signature.validate(valContext);

            if (!coreValidity) {
                if (logger.isTraceEnabled()) {
                    boolean sv = signature.getSignatureValue().validate(valContext);
                    logger.trace("Signature validation status: " + sv);

                    List<Reference> references = signature.getSignedInfo().getReferences();
                    for (Reference ref : references) {
                        logger.trace("[Ref id=" + ref.getId() + ":uri=" + ref.getURI() + "]validity status:" + ref.validate(valContext));
                    }
                }

                return false;
            }
        }

        return true;
    }

    /**
     * Marshall a SignatureType to output stream
     *
     * @param signature
     * @param os
     *
     * @throws SAXException
     * @throws JAXBException
     */
    public static void marshall(SignatureType signature, OutputStream os) throws JAXBException, SAXException {
        throw logger.notImplementedYet("NYI");
        /*
         * JAXBElement<SignatureType> jsig = objectFactory.createSignature(signature); Marshaller marshaller =
         * JAXBUtil.getValidatingMarshaller(pkgName, schemaLocation); marshaller.marshal(jsig, os);
         */
    }

    /**
     * Marshall the signed document to an output stream
     *
     * @param signedDocument
     * @param os
     *
     * @throws TransformerException
     */
    public static void marshall(Document signedDocument, OutputStream os) throws TransformerException {
        TransformerFactory tf = TransformerUtil.getTransformerFactory();
        Transformer trans = tf.newTransformer();
        trans.transform(DocumentUtil.getXMLSource(signedDocument), new StreamResult(os));
    }

    /**
     * Given the X509Certificate in the keyinfo element, get a {@link X509Certificate}
     *
     * @param certificateString
     *
     * @return
     *
     * @throws org.keycloak.saml.common.exceptions.ProcessingException
     */
    public static X509Certificate getX509CertificateFromKeyInfoString(String certificateString) throws ProcessingException {
        X509Certificate cert = null;
        StringBuilder builder = new StringBuilder();
        builder.append("-----BEGIN CERTIFICATE-----\n").append(certificateString).append("\n-----END CERTIFICATE-----");

        String derFormattedString = builder.toString();

        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream bais = new ByteArrayInputStream(derFormattedString.getBytes());

            while (bais.available() > 0) {
                cert = (X509Certificate) cf.generateCertificate(bais);
            }
        } catch (java.security.cert.CertificateException e) {
            throw logger.processingError(e);
        }
        return cert;
    }

    /**
     * Given a dsig:DSAKeyValue element, return {@link DSAKeyValueType}
     *
     * @param element
     *
     * @return
     *
     * @throws ProcessingException
     */
    public static DSAKeyValueType getDSAKeyValue(Element element) throws ParsingException {
        DSAKeyValueType dsa = new DSAKeyValueType();
        NodeList nl = element.getChildNodes();
        int length = nl.getLength();

        for (int i = 0; i < length; i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                Element childElement = (Element) node;
                String tag = childElement.getLocalName();

                byte[] text = childElement.getTextContent().getBytes();

                if (WSTrustConstants.XMLDSig.P.equals(tag)) {
                    dsa.setP(text);
                } else if (WSTrustConstants.XMLDSig.Q.equals(tag)) {
                    dsa.setQ(text);
                } else if (WSTrustConstants.XMLDSig.G.equals(tag)) {
                    dsa.setG(text);
                } else if (WSTrustConstants.XMLDSig.Y.equals(tag)) {
                    dsa.setY(text);
                } else if (WSTrustConstants.XMLDSig.SEED.equals(tag)) {
                    dsa.setSeed(text);
                } else if (WSTrustConstants.XMLDSig.PGEN_COUNTER.equals(tag)) {
                    dsa.setPgenCounter(text);
                }
            }
        }

        return dsa;
    }

    /**
     * Given a dsig:DSAKeyValue element, return {@link DSAKeyValueType}
     *
     * @param element
     *
     * @return
     *
     * @throws ProcessingException
     */
    public static RSAKeyValueType getRSAKeyValue(Element element) throws ParsingException {
        RSAKeyValueType rsa = new RSAKeyValueType();
        NodeList nl = element.getChildNodes();
        int length = nl.getLength();

        for (int i = 0; i < length; i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                Element childElement = (Element) node;
                String tag = childElement.getLocalName();

                byte[] text = childElement.getTextContent().getBytes();

                if (WSTrustConstants.XMLDSig.MODULUS.equals(tag)) {
                    rsa.setModulus(text);
                } else if (WSTrustConstants.XMLDSig.EXPONENT.equals(tag)) {
                    rsa.setExponent(text);
                }
            }
        }

        return rsa;
    }

    /**
     *

     * Creates a {@code KeyValueType} that wraps the specified public key. This method supports DSA and RSA keys.
     *

     *
     * @param key the {@code PublicKey} that will be represented as a {@code KeyValueType}.
     *
     * @return the constructed {@code KeyValueType} or {@code null} if the specified key is neither a DSA nor a RSA
     *         key.
     */
    public static KeyValueType createKeyValue(PublicKey key) {
        if (key instanceof RSAPublicKey) {
            RSAPublicKey pubKey = (RSAPublicKey) key;
            byte[] modulus = pubKey.getModulus().toByteArray();
            byte[] exponent = pubKey.getPublicExponent().toByteArray();

            RSAKeyValueType rsaKeyValue = new RSAKeyValueType();
            rsaKeyValue.setModulus(Base64.encodeBytes(modulus).getBytes());
            rsaKeyValue.setExponent(Base64.encodeBytes(exponent).getBytes());
            return rsaKeyValue;
        } else if (key instanceof DSAPublicKey) {
            DSAPublicKey pubKey = (DSAPublicKey) key;
            byte[] P = pubKey.getParams().getP().toByteArray();
            byte[] Q = pubKey.getParams().getQ().toByteArray();
            byte[] G = pubKey.getParams().getG().toByteArray();
            byte[] Y = pubKey.getY().toByteArray();

            DSAKeyValueType dsaKeyValue = new DSAKeyValueType();
            dsaKeyValue.setP(Base64.encodeBytes(P).getBytes());
            dsaKeyValue.setQ(Base64.encodeBytes(Q).getBytes());
            dsaKeyValue.setG(Base64.encodeBytes(G).getBytes());
            dsaKeyValue.setY(Base64.encodeBytes(Y).getBytes());
            return dsaKeyValue;
        }
        throw logger.unsupportedType(key.toString());
    }

    private static void signImpl(DOMSignContext dsc, String digestMethod, String signatureMethod, String referenceURI, PublicKey publicKey,
                                 X509Certificate x509Certificate, String canonicalizationMethodType)
            throws GeneralSecurityException, MarshalException, XMLSignatureException {
        dsc.setDefaultNamespacePrefix("dsig");

        DigestMethod digestMethodObj = fac.newDigestMethod(digestMethod, null);
        Transform transform1 = fac.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null);
        Transform transform2 = fac.newTransform("http://www.w3.org/2001/10/xml-exc-c14n#", (TransformParameterSpec) null);

        List<Transform> transformList = new ArrayList<Transform>();
        transformList.add(transform1);
        transformList.add(transform2);

        Reference ref = fac.newReference(referenceURI, digestMethodObj, transformList, null, null);

        CanonicalizationMethod canonicalizationMethod = fac.newCanonicalizationMethod(canonicalizationMethodType,
                (C14NMethodParameterSpec) null);

        List<Reference> referenceList = Collections.singletonList(ref);
        SignatureMethod signatureMethodObj = fac.newSignatureMethod(signatureMethod, null);
        SignedInfo si = fac.newSignedInfo(canonicalizationMethod, signatureMethodObj, referenceList);

        KeyInfo ki = null;
        if (includeKeyInfoInSignature) {
            ki = createKeyInfo(publicKey, x509Certificate);
        }
        XMLSignature signature = fac.newXMLSignature(si, ki);

        signature.sign(dsc);
    }

    private static KeyInfo createKeyInfo(PublicKey publicKey, X509Certificate x509Certificate) throws KeyException {
        KeyInfoFactory keyInfoFactory = fac.getKeyInfoFactory();
        KeyInfo keyInfo = null;
        KeyValue keyValue = null;
        //Just with public key
        if (publicKey != null) {
            keyValue = keyInfoFactory.newKeyValue(publicKey);
            keyInfo = keyInfoFactory.newKeyInfo(Collections.singletonList(keyValue));
        }
        if (x509Certificate != null) {
            List x509list = new ArrayList();

            x509list.add(x509Certificate);
            X509Data x509Data = keyInfoFactory.newX509Data(x509list);
            List items = new ArrayList();

            items.add(x509Data);
            if (keyValue != null) {
                items.add(keyValue);
            }
            keyInfo = keyInfoFactory.newKeyInfo(items);
        }
        return keyInfo;
    }
}


text:
<?php

namespace backend\controllers;

use backend\utilities\SubModelController;
use common\models\subject\Person;
use Yii;
use yii\filters\AccessControl;

/**
 * PhoneController implements the CRUD actions for Phone model.
 */
class PhoneController extends SubModelController
{
    public $modelClass = 'common\models\Phone';
    public $relationName = 'person';

	/**
	 * Access control etc.
	 * @return array
	 */
	public function behaviors()
	{
		return [
			'access' => [
				'class' => AccessControl::className(),
				'rules' => [
					[
						'roles' => ['@'],
						'allow' => true
					]
				]
			]
		];
	}

	/**
	 * @inheritdoc
	 */
	public function init() {
		parent::init();
		/** @var Person $person */
		$person = Person::findOne(Yii::$app->request->get('relation_id'));
		$this->returnUrlParams = [
			'person/update',
			'id' => $person->id,
			'relation_id' => $person->subject_id
		];
	}
}

redpajama_set_name: RedPajamaGithub


text:
The file `proper_names.txt` contains a newline-delimited file which contains all of the words in the TLG which are likely proper names (persons, places, etc.). The value of this list is that, since everything is a noun, it may be used as a default POS tagger for these unusual words. The file `build_proper_names_list.py` shows how this file was made. `proper_names.txt` contains 144,051 unique.

Important note: This list probably contains some words that are not proper nouns. Its needs to be edited by a human to remove accidental inclusions.

# License
Copyright (c) 2014 Kyle P. Johnson, under the MIT License. See 'LICENSE' for details.


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>Introduction — CIVET documentation</title>

    <link rel="stylesheet" href="_static/agogo.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />

    <link rel="top" title="CIVET documentation" href="index.html" />
    <link rel="next" title="Installing CIVET" href="installing.html" />
    <link rel="prev" title="Welcome" href="index.html" />

CIVET beta-0.9.1 documentation

          previous |
          next

Introduction¶

This is the documentation for
CIVET [1]—Contentious Incident Variable Entry Template—customizable
data entry system. CIVET was developed by the NSF-sponsored project
titled "A Method for Leveraging Public Information Sources for Social
Science Research" which is creating tools to improve the efficiency of
data generation in the social sciences. The project had an initial focus
on coding event data in the domain of contentious politics, but we
expect that these tools will be relevant in a number of data-generation
domains.

The core objective of CIVET is to provide a reasonably simple—yes,
simple—set of commands that will allow a user to set up a web-based
coding environment without the need to master the likes of HTML, CSS and
Javascript. As currently implemented, the system is a rather ugly
prototype; it will also be evolving as we add additional elements.
Nonetheless, the system should now be useable for coding.

CIVET is implemented in the widely-used and well documented
Python-based Django system [2] which is widely available on various
cloud platforms: a rather extended list of "Django-friendly" hosting
services can be found at

https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts

The complete CIVET code is licensed as open source under the MIT
license and provided on GitHub at https://github.com/civet-software .

CIVET currently has two modes:

Coding form template:

This is a template-based for setting up a web-based coding form
which implements several of the common HTML data entry formats and
exports the resulting data as a tab-delimited text file. This is
fully functional and should be useable for small projects.

Text annotation/extraction:

This uses CIVET "workspaces" which combine related texts, their
metadata, and the coding form. Workspaces allow for manual and
automated text annotation, then the ability to extract various types
of information into the fields of a coding form.

Program Navigation Placeholders¶

CIVET is still under development and not all of the options have
been fully implemented. If you see a page with a message of the form

The option [something] has yet to be implemented. Use the back arrow in your browser to return to the previous screen.

you have encountered one of those options: as noted, just use the "Back"
option in your browser to return to the previous screen. These are primarily
in the "Workspace Management" papge.

Status of the Program: 31 August 2015¶

The NSF funding for the project ended on this date. At this point, all of
the documented features of the program should be working except as
noted above. However, we are just beginning the process of
operational field testing and it is likely—which is to say, inevitable—
that some additional bugs will be found, hence this is still considered
"Beta-0.9" rather than "1.0." We currently have two field tests underway,
and are hoping to get some additional ones going, and will be posting
bug fixes to GitHub promptly as these appear and are resolved.

At present, we have not developed any software for generating the
workspace files, though we expect to have at least a couple programs
available in the next few months. The problem here is that identifying
the various metadata and components in a set of texts is highly
specific to the text source, and to date we’ve not found general
solutions for this. As noted in the final chapter of this document,
over the next year or so we will be seeking additional funding for
tool development for these "front-end" tasks, though given the very
slow pace of the public funding cycle, this is unlikely to occur until
late in 2016 at the earliest. In the meantime, we will be leveraging
tools developed in existing projects and, of course, would very
much appreciate the contribution of any ancillary tools that the user
community develops, particularly for common sources such as Lexis-Nexis,
Factiva, ProQuest, LDC Gigaword, and various news feeds and social
media.

Status of the Program: August 2016¶

Over the past year, CIVET has been used in two projects, though both with
my assistance in generating the YAML files and with some additional
customization, much of which has been incorporated into the general
system.

To my knowledge, however—and if you know of some project using this,
please let me know—it has not been used for the originally intended
purpose of providing a platform which would allow someone with relatively
limited programming knowledge to create a web-based form. I suspect this
is due to one or more of the following factors:

The process of getting Django installed, while thoroughly documented,
apparently can require some experimentation and tweaking. That
said, one of the projects decided to install Django on laptops
used by the coders rather than through a server: this
allowed the coders to work anywhere.

When using workspaces, which allow access to the most sophisticated
parts of the system, the texts must be converted to the YAML
format, a task for which I’ve yet to see a general solution and
almost certainly requires Python, perl or Java programming skills

Realistically, there are only a small number of new projects starting in any given
year which are sufficiently large that existing tools such as
spreadsheets or Google Forms are inadequate. And many of those,
of course, will have resources to directly develop customized
pages rather than working within the constraints of CIVET

So, this is essentially just an open-source version of a codebase that
I can customize to generate coding forms. Which I’m realizing is
probably pretty much what about 95% of open-source projects are, though
that still gives the client a whole lot more knowledge and power than
they have with a proprietary system, even if they never change a line
of code. Whatever.

Some random observations from those two deployments:

Additional customization of the code has gone quite smoothly, even
allowing for the inevitable decay of my comprehension of the
system. Granted, even when I’ve forgotten the details of the code
I’m still working with my programming idioms, but it does seem like as a
base, this is quite solid. The same can be said for the YAML
workspace format.

Neither of the two installations made any use of the manual
annotation, and in the second, the NEVER_ANNOTATE option was
added to bypass this entirely: annotation is either handled
automatically using vocabulary files, or directly putting the
HTML into the YAML files.

More generally, though completely expected, the deployment have
generated a number of interesting ideas for new features that
did not emerge in the abstract design phase. I’ve also left
in some custom code—commented-out or otherwise deactivated—
that could be used for examples of further possible extensions.

On two occasions over the past year there were changes to
Django that required minor changes—one or two lines of code—
to CIVET in order to keep it running. Unsurprisingly, we have
also found that Django is more likely to be fully compatible
with up-to-date hardware
and operating systems: in particular, one project ran into some
issues running it on some old copies of Windows. Once again, this is
less of a turn-key system than I’d hoped.

Documentation¶

Documentation is maintained using the Sphinx system, which provides both an
on-line version and a reasonably-well-formatted PDF version. There
are links to both of these compiled versions on the home page; the .rst source texts for the documentation are in the
directory djcivet_site/docs. That directory contains a Sphinx Makefile so revisions can be compiled using the standard
command make html latexpdf.

The on-line documentation currently resides at the site http://civet.parusanalytics.com/civetdocs/; [3] a PDF version can
be downloaded by clicking the Download PDF link on the home page. [4]

Footnotes

<colgroup><col class="label" /><col /></colgroup>

[1]	http://en.wikipedia.org/wiki/CIVET

<colgroup><col class="label" /><col /></colgroup>

[2]	An earlier prototype was implemented in the Flask framework: see
Appendix 4

<colgroup><col class="label" /><col /></colgroup>

[3]	This is a bug, not a feature: there is presumably a way of accessing these at djcivet_site/docs/_build/html/, or
somewhere else within the djcivet_site/ directory
in a manner that has them correctly rendered, but I haven’t figured it out yet. Fixes are welcome.

<colgroup><col class="label" /><col /></colgroup>

[4]	This is handled in views.download_pdfdocs(): it first looks for the PDF version of the documentation in
docs/_build/latex/civetdoc.pdf, which is where the most current version is likely to be located when the
documentation was produced using the make latexpdf command in the docs/ directory. If that isn’t present,
it checks the /static/ directory: this can be used in deployments in order to avoid uploading  docs/. If neither
is available, it gets the copy posted at http://civet.parusanalytics.com/, which may or may not correspond exactly to the
version being used depending on what modifications have been made. The command make movepdf will copy civetdoc.pdf from
_build/latex to /static/

Table Of Contents

Introduction

Program Navigation Placeholders

Status of the Program: 31 August 2015

Status of the Program: August 2016

Documentation

Installing CIVET

Authentication

Home Page Options

CIVET Coding Form Templates

CIVET Workspaces

Annotation and Editing Collections

Coding and Text Extraction

Preferences

Projected Features

Appendix 1: Sample Template File

Appendix 2: Input Format

Appendix 3: Supporting Files and Source Code Settings

Appendix 4: Installing in AWS-EB and Docker

Search

            <form class="search" action="search.html" method="get">
                <input type="text" name="q" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
            </form>

                Enter search terms or a module, class or function name.

            previous |
            next

              Show Source

      Last updated on 2016-08-22.
      Created using Sphinx 1.3.1.


text:
package com.example.bugrap;

import java.io.Serializable;

import com.example.bugrap.data.LoginManager;
import com.vaadin.data.Property;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

/**
 * The login page.
 *
 * @author bogdan
 */
@SuppressWarnings("serial")
public class LoginPage extends Panel implements View {

	/*
	 * The username.
	 */
	private Property<String> username;

	/*
	 * The password.
	 */
	private Property<String> password;

	/*
	 * The login delegate.
	 */
	private LoginDelegate loginDelegate;

	/*
	 * The username field.
	 */
	private TextField usernameField;

	/**
	 * Create the login page.
	 * @param loginDelegate	manage what happen during and after login.
	 */
	public LoginPage(LoginDelegate loginDelegate) {
		this.loginDelegate = loginDelegate;

		username = new ObjectProperty<String>(DEFAULT_USERNAME);
		password = new ObjectProperty<String>(DEFAULT_PASSWORD);

		usernameField = new TextField(username);
		usernameField.setCaption("Username");

		PasswordField passwordField = new PasswordField(password);
		passwordField.setCaption("Password");

		Button loginButton = new Button("Login");
		loginButton.setClickShortcut(KeyCode.ENTER);
		loginButton.addClickListener(new LoginButtonListener());

		VerticalLayout vLayout = new VerticalLayout();
		vLayout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
		vLayout.setSpacing(true);

		vLayout.addComponent(usernameField);
		vLayout.addComponent(passwordField);
		vLayout.addComponent(loginButton);

		VerticalLayout layout = new VerticalLayout();
		layout.setSizeFull();
		layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

		Label topLabel = new Label(" ", ContentMode.HTML);
		topLabel.setSizeFull();
		Label bottomLabel = new Label(" ", ContentMode.HTML);
		bottomLabel.setSizeFull();

		layout.addComponent(topLabel);
		layout.addComponent(vLayout);
		layout.addComponent(bottomLabel);

		layout.setComponentAlignment(topLabel, Alignment.TOP_CENTER);
		layout.setComponentAlignment(bottomLabel, Alignment.BOTTOM_CENTER);

		setContent(layout);

	}

	/*
	 * Click listener for the login button.
	 */
	private class LoginButtonListener implements ClickListener {

		/* (non-Javadoc)
		 * @see com.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.ClickEvent)
		 */
		@Override
		public void buttonClick(ClickEvent event) {

			if (LoginManager.getManager().login(username.getValue(), password.getValue())) {
				loginDelegate.showContent();
			} else {
				Notification.show("Login failed!");
			}
		}
	}

	/* (non-Javadoc)
	 * @see com.vaadin.navigator.View#enter(com.vaadin.navigator.ViewChangeListener.ViewChangeEvent)
	 */
	@Override
	public void enter(ViewChangeEvent event) {
		username.setValue(DEFAULT_USERNAME);
		password.setValue(DEFAULT_PASSWORD);

		usernameField.focus();
	}

	/*
	 * Test defaults.
	 */
	private static final String DEFAULT_USERNAME = "manager";
	private static final String DEFAULT_PASSWORD = "manager";

	/**
	 * Delegate content creation and other stuff.
	 *
	 * @author bogdan
	 */
	public interface LoginDelegate extends Serializable {

		/**
		 * Show the app content.
		 */
		void showContent();

	}

}


text:
from .preemptable_state_machine import PreemptableStateMachine  # noqa: F401
from .operatable_state_machine import OperatableStateMachine  # noqa: F401
from .lockable_state_machine import LockableStateMachine  # noqa: F401
from .ros_state_machine import RosStateMachine  # noqa: F401
from .state_machine import StateMachine  # noqa: F401

from .concurrency_container import ConcurrencyContainer  # noqa: F401
from .priority_container import PriorityContainer  # noqa: F401

from .state import State  # noqa: F401
from .ros_state import RosState  # noqa: F401
from .manually_transitionable_state import ManuallyTransitionableState  # noqa: F401
from .lockable_state import LockableState  # noqa: F401
from .preemptable_state import PreemptableState  # noqa: F401
from .operatable_state import OperatableState  # noqa: F401
from .event_state import EventState  # noqa: F401

from .user_data import UserData  # noqa: F401


text:
<?php

namespace Waldo\OpenIdConnect\EnduserBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

/**
 * LostAccountFormType
 *
 * @author valérian Girard <valerian.girard@educagri.fr>
 */
class LostAccountFormType extends AbstractType
{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
                ->add('username', 'text', array(
                    'label' => 'label.email_or_username',
                    'required' => false
                    ))
                ->add('search', 'submit', array('label' => 'label.Search'))
                ->add('cancel', 'submit', array('label' => 'label.Cancel'))
            ;
    }

    public function getName()
    {
        return 'oic_lost_account';
    }

}


text:
/**
 * @author Evgeniya G. Maenkova
 * @version $Revision$
 */
package org.apache.harmony.awt.text;

import java.awt.Insets;

import javax.swing.BoundedRangeModel;

public interface TextFieldKit {
    int getHorizontalAlignment();
    BoundedRangeModel getHorizontalVisibility();
    boolean echoCharIsSet();
    char getEchoChar();
    Insets getInsets();
}


text:
<?php

namespace Oro\Component\ChainProcessor;

/**
 * Provides an interface that should be implemented by classes that is used to check
 * whether a processor should be executed in the current execution context.
 */
interface ApplicableCheckerInterface
{
    public const APPLICABLE     = 1;
    public const ABSTAIN        = 0;
    public const NOT_APPLICABLE = -1;

    /**
     * Checks whether a processor can be executed in the given context.
     *
     * This method must return one of the following constants:
     * APPLICABLE, ABSTAIN, or NOT_APPLICABLE.
     *
     * @param ContextInterface $context
     * @param array            $processorAttributes
     *
     * @return int Either APPLICABLE, ABSTAIN, or NOT_APPLICABLE
     */
    public function isApplicable(ContextInterface $context, array $processorAttributes);
}


text:
```
tart-train desc_a3c_atari_BreakoutV0.py -d 0
tart-demo desc_a3c_atari_BreakoutV0.py -d 0 [-w xxx.snapshot.pkl] [-e last]
```

This reproduction of A3C is based on ppwwyyxx's reproduction in his TensorPack framework.
Credit to : https://github.com/ppwwyyxx/tensorpack/tree/master/examples/A3C-Gym

## Basic A3C-Continous on Box2D environment: `desc_a3cc_box2d_LunarLanderContinuousV2.py`

This model does not follows the original settings in DeepMind's paper, which use:
1. LSTM model.
2. Episode-as-a-batch update.
3. Gaussian distribution.

In this model, we included several tricks for the training:
1. Truncated Laplacian distribution for policy.
2. Positive advantage only update.

Details can be found in the code.

## Cross-Entropy Method for OpenAI-Gym

This implementation provides a Tensorflow-based CEM optimizer. For memory saving concearn, the optimizer actually does
all optimization on CPU (e.g. storing all parameters and evolve the population using numpy). The most critical
advantage over a pure numpy-based CEM is that you can now use Tensorflow operators to build your neural network.

Note that all optimization-related stuff is done on CPU. So typically you should just use CPU as device.

```
tart-train desc_cem_classic_CartPoleV0 -d cpu
tart-demo desc_cem_classic_CartPoleV0 -d cpu [-w xxx.snapshot.pkl] [-e last]
```

## Evolution Strategies as black-box optimizer for OpenAI-Gym

Simple serial reproduction of Evolution Strategy: [1703.03864] Evolution Strategies as a Scalable Alternative to
Reinforcement Learning (https://arxiv.org/abs/1703.03864).

Similar to CEM optimizer, the ESOptimizer works on CPU, but you can still use Tensorflow to build your network.

Note that the implementation is *NOT* scalable, it does actually serial data collection (not distributed). You should
only this code for simple tests. For the official distributed implementation: refer to
https://github.com/openai/evolution-strategies-starter

```
tart-train desc_es_classic_CartPoleV0 -d cpu
tart-demo desc_es_classic_CartPoleV0 -d cpu [-w xxx.snapshot.pkl] [-e last]
```

## Trust-Region Policy Optimization and Generalized Advantage Estimation

Parallel (multi-threading only) implementation for TRPO and GAE:
[1502.05477] Trust Region Policy Optimization (https://arxiv.org/abs/1502.05477);
[1506.02438] High-Dimensional Continuous Control Using Generalized Advantage Estimation (https://arxiv.org/abs/1506.02438).

```
tart-train desc_trpo_gae_roboschool_HopperV1.py -d cpu
tart-demo desc_trpo_gae_roboschool_HopperV1.py -d cpu [-w xxx.snapshot.pkl] [-e last]
```

Thank you authors of the following repos and blogs:
- https://github.com/kvfrans/parallel-trpo
- https://github.com/steveKapturowski/tensorflow-rl
- http://kvfrans.com/speeding-up-trpo-through-parallelization-and-parameter-adaptation

## Proximal Policy Optimization

Reproduction of PPO: [1707.06347]Proximal Policy Optimization Algorithms (https://arxiv.org/abs/1707.06347)

Working in progress.


text:
@interface Calendar360Cell : UITableViewCell

+(Calendar360Cell*) initNibCell;
@property (nonatomic, strong) NSDictionary *dicData;
-(void) loadDataToCellWithData : (NSDictionary*) dicData withOption : (int) smgSelect ;
@property (weak, nonatomic) IBOutlet UILabel *lbTitle;

@property (weak, nonatomic) IBOutlet UILabel *lbTime;

@property (weak, nonatomic) IBOutlet UILabel *lbAddress;

@end


text:
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.keyboard_accessory.sheet_tabs;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import static org.chromium.chrome.browser.keyboard_accessory.ManualFillingMetricsRecorder.getHistogramForType;
import static org.chromium.chrome.browser.keyboard_accessory.sheet_tabs.AccessorySheetTabMetricsRecorder.UMA_KEYBOARD_ACCESSORY_SHEET_SUGGESTIONS;
import static org.chromium.chrome.browser.keyboard_accessory.sheet_tabs.AccessorySheetTabModel.AccessorySheetDataPiece.Type.CREDIT_CARD_INFO;
import static org.chromium.chrome.browser.keyboard_accessory.sheet_tabs.AccessorySheetTabModel.AccessorySheetDataPiece.Type.TITLE;
import static org.chromium.chrome.browser.keyboard_accessory.sheet_tabs.AccessorySheetTabModel.AccessorySheetDataPiece.getType;

import android.graphics.drawable.Drawable;

import androidx.recyclerview.widget.RecyclerView;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordHistogramJni;
import org.chromium.base.metrics.test.ShadowRecordHistogram;
import org.chromium.base.task.test.CustomShadowAsyncTask;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.JniMocker;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.keyboard_accessory.AccessoryTabType;
import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData;
import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData.AccessorySheetData;
import org.chromium.chrome.browser.keyboard_accessory.data.KeyboardAccessoryData.UserInfo;
import org.chromium.chrome.browser.keyboard_accessory.data.PropertyProvider;
import org.chromium.chrome.browser.keyboard_accessory.data.UserInfoField;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.ui.modelutil.ListObservable;

/**
 * Controller tests for the credit card accessory sheet.
 */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE,
        shadows = {CustomShadowAsyncTask.class, ShadowRecordHistogram.class})
@Features.EnableFeatures(ChromeFeatureList.AUTOFILL_KEYBOARD_ACCESSORY)
public class CreditCardAccessorySheetControllerTest {
    @Rule
    public JniMocker mocker = new JniMocker();
    @Rule
    public TestRule mFeaturesProcessorRule = new Features.JUnitProcessor();
    @Mock
    private RecyclerView mMockView;
    @Mock
    private ListObservable.ListObserver<Void> mMockItemListObserver;
    @Mock
    private RecordHistogram.Natives mMockRecordHistogramNatives;

    private CreditCardAccessorySheetCoordinator mCoordinator;
    private AccessorySheetTabModel mSheetDataPieces;

    @Before
    public void setUp() {
        ShadowRecordHistogram.reset();
        MockitoAnnotations.initMocks(this);
        mocker.mock(RecordHistogramJni.TEST_HOOKS, mMockRecordHistogramNatives);
        AccessorySheetTabCoordinator.IconProvider.setIconForTesting(mock(Drawable.class));
        mCoordinator =
                new CreditCardAccessorySheetCoordinator(RuntimeEnvironment.application, null);
        assertNotNull(mCoordinator);
        mSheetDataPieces = mCoordinator.getSheetDataPiecesForTesting();
    }

    @Test
    public void testCreatesValidTab() {
        KeyboardAccessoryData.Tab tab = mCoordinator.getTab();
        assertNotNull(tab);
        assertNotNull(tab.getIcon());
        assertNotNull(tab.getListener());
    }

    @Test
    public void testSetsViewAdapterOnTabCreation() {
        when(mMockView.getParent()).thenReturn(mMockView);
        KeyboardAccessoryData.Tab tab = mCoordinator.getTab();
        assertNotNull(tab);
        assertNotNull(tab.getListener());
        tab.getListener().onTabCreated(mMockView);
        verify(mMockView).setAdapter(any());
    }

    @Test
    public void testModelNotifiesAboutTabDataChangedByProvider() {
        final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();

        mSheetDataPieces.addObserver(mMockItemListObserver);
        mCoordinator.registerDataProvider(testProvider);

        // If the coordinator receives a set of initial items, the model should report an insertion.
        testProvider.notifyObservers(
                new AccessorySheetData(AccessoryTabType.CREDIT_CARDS, "Payments", ""));
        verify(mMockItemListObserver).onItemRangeInserted(mSheetDataPieces, 0, 1);
        assertThat(mSheetDataPieces.size(), is(1));

        // If the coordinator receives a new set of items, the model should report a change.
        testProvider.notifyObservers(
                new AccessorySheetData(AccessoryTabType.CREDIT_CARDS, "Other Payments", ""));
        verify(mMockItemListObserver).onItemRangeChanged(mSheetDataPieces, 0, 1, null);
        assertThat(mSheetDataPieces.size(), is(1));

        // If the coordinator receives an empty set of items, the model should report a deletion.
        testProvider.notifyObservers(null);
        verify(mMockItemListObserver).onItemRangeRemoved(mSheetDataPieces, 0, 1);
        assertThat(mSheetDataPieces.size(), is(0));

        // There should be no notification if no item are reported repeatedly.
        testProvider.notifyObservers(null);
        verifyNoMoreInteractions(mMockItemListObserver);
    }

    @Test
    public void testSplitsTabDataToList() {
        final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();
        final AccessorySheetData testData =
                new AccessorySheetData(AccessoryTabType.CREDIT_CARDS, "Payments", "");
        testData.getUserInfoList().add(new UserInfo("", false));
        testData.getUserInfoList().get(0).addField(
                new UserInfoField("Todd", "Todd", "", false, field -> {}));
        testData.getUserInfoList().get(0).addField(
                new UserInfoField("**** 9219", "**** 9219", "", true, field -> {}));

        mCoordinator.registerDataProvider(testProvider);
        testProvider.notifyObservers(testData);

        assertThat(mSheetDataPieces.size(), is(1));
        assertThat(getType(mSheetDataPieces.get(0)), is(CREDIT_CARD_INFO));
        assertThat(mSheetDataPieces.get(0).getDataPiece(), is(testData.getUserInfoList().get(0)));
    }

    @Test
    public void testUsesTitleElementForEmptyState() {
        final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();
        final AccessorySheetData testData =
                new AccessorySheetData(AccessoryTabType.CREDIT_CARDS, "Payments", "");
        mCoordinator.registerDataProvider(testProvider);

        testProvider.notifyObservers(testData);

        assertThat(mSheetDataPieces.size(), is(1));
        assertThat(getType(mSheetDataPieces.get(0)), is(TITLE));
        assertThat(mSheetDataPieces.get(0).getDataPiece(), is(equalTo("Payments")));

        // As soon UserInfo is available, discard the title.
        testData.getUserInfoList().add(new UserInfo("", false));
        testData.getUserInfoList().get(0).addField(
                new UserInfoField("Todd", "Todd", "", false, field -> {}));
        testData.getUserInfoList().get(0).addField(
                new UserInfoField("**** 9219", "**** 9219", "", true, field -> {}));
        testProvider.notifyObservers(testData);

        assertThat(mSheetDataPieces.size(), is(1));
        assertThat(getType(mSheetDataPieces.get(0)), is(CREDIT_CARD_INFO));
    }

    @Test
    public void testRecordsNoSuggestionsImpressionsWithoutInteractiveElements() {
        final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();
        mCoordinator.registerDataProvider(testProvider);
        assertThat(RecordHistogram.getHistogramTotalCountForTesting(
                           UMA_KEYBOARD_ACCESSORY_SHEET_SUGGESTIONS),
                is(0));
        assertThat(getSuggestionsImpressions(AccessoryTabType.CREDIT_CARDS, 0), is(0));
        assertThat(getSuggestionsImpressions(AccessoryTabType.ALL, 0), is(0));

        // If the tab is shown without interactive item, log "0" samples.
        AccessorySheetData accessorySheetData =
                new AccessorySheetData(AccessoryTabType.CREDIT_CARDS, "Payments", "");
        testProvider.notifyObservers(accessorySheetData);
        mCoordinator.onTabShown();

        assertThat(getSuggestionsImpressions(AccessoryTabType.CREDIT_CARDS, 0), is(1));
        assertThat(getSuggestionsImpressions(AccessoryTabType.ALL, 0), is(1));
    }

    @Test
    public void testRecordsSelectableSuggestionsImpressionsWhenShown() {
        final PropertyProvider<AccessorySheetData> testProvider = new PropertyProvider<>();
        mCoordinator.registerDataProvider(testProvider);
        assertThat(RecordHistogram.getHistogramTotalCountForTesting(
                           UMA_KEYBOARD_ACCESSORY_SHEET_SUGGESTIONS),
                is(0));
        assertThat(getSuggestionsImpressions(AccessoryTabType.CREDIT_CARDS, 1), is(0));
        assertThat(getSuggestionsImpressions(AccessoryTabType.ALL, 1), is(0));

        // Add only two interactive items - the third one should not be recorded.
        AccessorySheetData accessorySheetData =
                new AccessorySheetData(AccessoryTabType.CREDIT_CARDS, "Payments", "");
        accessorySheetData.getUserInfoList().add(new UserInfo("", false));
        accessorySheetData.getUserInfoList().get(0).addField(
                new UserInfoField("Todd Tester", "Todd Tester", "0", false, result -> {}));
        accessorySheetData.getUserInfoList().get(0).addField(
                new UserInfoField("**** 9219", "Card for Todd Tester", "1", false, result -> {}));
        accessorySheetData.getUserInfoList().get(0).addField(
                new UserInfoField("Unselectable", "Unselectable", "-1", false, null));
        testProvider.notifyObservers(accessorySheetData);
        mCoordinator.onTabShown();

        assertThat(getSuggestionsImpressions(AccessoryTabType.CREDIT_CARDS, 2), is(1));
        assertThat(getSuggestionsImpressions(AccessoryTabType.ALL, 2), is(1));
    }

    private int getSuggestionsImpressions(@AccessoryTabType int type, int sample) {
        return RecordHistogram.getHistogramValueCountForTesting(
                getHistogramForType(UMA_KEYBOARD_ACCESSORY_SHEET_SUGGESTIONS, type), sample);
    }
}


text:
import graphviz as gv

class Config:
    '''Configuration object contains settings

    Settings:
    - Config.graphviz: bool
        When True will generate and output a generation.gv/generation.gv.pdf file
        that contains a graph of all the generation.

    - Config.graphviz_digraph
        The graphviz.Digraph object actually to be used if Config.graphviz is True
    '''
    def __init__(self, graphviz=False):
        self.graphviz = graphviz
        self.graphviz_digraph = gv.Digraph(format='svg', comment='Generation Instances') if graphviz else None

CONFIG = Config(graphviz=True)


text:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _2019111501CsAreaOfCircle
{
    public partial class frmLogin : Form
    {
        int counter = 0;

        public frmLogin()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            String sUname = "";
            String sPass = "";

            frmArea varFrmArea = new frmArea();

            sUname = txtUname.Text.ToString();
            sPass = txtPass.Text.ToString();

            if (sUname == "aung" && sPass == "1234")
            {
                varFrmArea.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Wrong Uname or Pass", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPass.Text = "";
                txtUname.Text = "";
                txtUname.Focus();
                counter++;
                if (counter >= 3)
                {
                    Application.Exit();
                }
            }
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {

        }
    }
}


text:
"""

Documentation Viewer Extension
Version: 0.2

Author: Roger D. Serwy
        roger.serwy@gmail.com

Date: 2009-05-29
Date: 2011-12-26 - modified to work with IdleX and Python 3

It provides "Documentation Viewer" under "Help"

Add these lines to config-extensions.def

Parts of this code is based on a patch submitted to the
Python Software Foundation under to Apache 2 License, per
a contributor agreement.
See http://bugs.python.org/issue964437 for the patch

"""
config_extension_def = """
[DocViewer]
enable=1
enable_editor=1
enable_shell=1
calltip=1

[DocViewer_cfgBindings]
docviewer-window=

"""

# TODO:
#   - sanitize command input box

from idlelib.configHandler import idleConf
import idlelib.IOBinding as IOBinding
from idlelib.EditorWindow import EditorWindow
from idlelib.OutputWindow import OutputWindow
from idlelib.Delegator import Delegator
from idlelib.HyperParser import HyperParser
import idlelib.WindowList as WindowList
import idlelib.SearchDialog as SearchDialog
import time
import sys
if sys.version < '3':
    from Tkinter import *
else:
    from tkinter import *

def get_cfg(cfg, type="bool", default=True):
    return idleConf.GetOption("extensions", "DocViewer",
                         cfg, type=type, default=default)

def set_cfg(cfg, b):
    return idleConf.SetOption("extensions", "DocViewer",
                      cfg,'%s' % b)

class DocViewer:

    menudefs = [
        ('help', [None,
               ('Documentation Viewer', '<<docviewer-window>>'),
       ]),]

    def __init__(self, editwin):
        self.editwin = editwin
        self.top = editwin.top
        text = self.editwin.text
        text.bind("<<docviewer-calltip>>", self.calltip_event)
        text.event_add("<<docviewer-calltip>>", "<KeyRelease-parenleft>")
        text.bind("<<docviewer-window>>", self.do_calltip)
        self.docWindow = docWindow

    def do_calltip(self, event=None):
        docWindow.show(self.editwin)
        self.calltip_event()

    def calltip_event(self, event=None):
        window = self.docWindow.window
        if window is None:
            return

        if not window.update_calltip.get():
            # don't process calltip event
            return

        # get calltip
        # code borrows from CallTips.py::open_calltip
        evalfuncs = False
        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets('(')
        if not sur_paren:
            return
        hp.set_index(sur_paren[0])
        name = hp.get_expression()
        if not name or (not evalfuncs and name.find('(') != -1):
            return

        w = window
        w.entry.delete("0", "end")
        w.entry.insert("insert", name)
        w.get_doc()

    def show_docviewer(self, event=None):
        # create a window with two text boxes and a label
        self.docWindow.show(self.editwin)

class DocDelegator(Delegator):
    """ Prevent modifications to the text widget that displays the documentation.
        Text may only be inserted if the .enabled value is True.
    """

    def insert(self, index, chars, tags=None):
        try:
            self.entry.insert('insert', chars)
            self.entry.focus()
        except Exception as err:
            print(' Internal DocDelegator Error:', err)

    def delete(self, index1, index2=None):
        pass

class DocWindowHandler(object):
    """ For handling a singleton instance of the DocViewer"""
    def __init__(self):
        self.window = None
        WindowList.registry.register_callback(self.check_close)
    def show(self, editwin, near=None):
        if self.window is None:
            shell = editwin.flist.open_shell()
            interp = shell.interp
            win = DocumentationWindow(flist=editwin.flist,
                                      interp=interp,
                                      editwin=shell)
            self.window = win
            win.top.bind('<Destroy>', self.destroy, '+')
            self.nearwindow(editwin.top)

    def nearwindow(self, near):
        w = self.window.top
        w.withdraw()
        geom = (near.winfo_rootx() + 10, near.winfo_rooty() + 10)
        w.geometry('=+%d+%d' % geom)
        w.deiconify()
        w.lift()

    def check_close(self, event=None):
        """ callback function to make sure the DocumentationWindow is
            not the last instance. If so, then close it.
        """
        if self.window is None:
            return

        d = WindowList.registry.dict
        t = str(self.window.top)
        if len(d) == 1:
            if t in d:
                self.window.close()
            else:
                #Strange situation. DocViewer is open, but not it the dict.
                #This should not happen.
                pass

    def destroy(self, event=None):
        self.window = None

docWindow = DocWindowHandler()

class DocumentationWindow(EditorWindow):
    """ Create an editor window for the purpose of displaying documentation """

    def __init__(self, flist=None, interp=None, editwin=None):
        EditorWindow.__init__(self, flist)
        self.interp = interp
        self.editwin = editwin

        # TODO: figure out better way to eliminate menu bar
        m = Menu(self.root)
        self.top.config(menu=m)

        root = self.top

        self.doc_frame = doc_frame = Frame(root)
        # make first line
        f_top = Frame(doc_frame)
        label = Label(f_top, text='Help on:')

        self.entry = entry = Entry(f_top)
        entry.bind('<Return>', self.get_doc)

        self.update_calltip = IntVar(root)
        check = Checkbutton(f_top, text='Update from Calltip',
                               variable=self.update_calltip)
        check.var = self.update_calltip
        if get_cfg('calltip'):
            check.select()

        f_top.pack(side='top', fill=X, padx=5)
        label.pack(side='left')
        entry.pack(side='left', fill=X, expand=True, padx=5, ipadx=5)
        check.pack(side='right')

        # make command buttons
        f_cmd = Frame(doc_frame)
        f_cmd.pack(side='top', fill=X, padx=3)

        self.button_showdoc = Button(f_cmd, text='Show Doc String',
                               default='active',
                               command=self.get_doc)

        self.button_showhelp = Button(f_cmd, text='Show help()',
                                   command=self.get_help)

        button_search = Button(f_cmd, text='Search Text',
                                  command=self.search)
        button_close = Button(f_cmd, text='Close',
                                 command=self.close)

        button_close.pack(side='right')
        self.button_showdoc.pack(side='left')
        self.button_showhelp.pack(side='left')
        button_search.pack(side='left')

        doc_frame.pack(side=TOP, before=self.text_frame, fill=X)

        # change focused widget to entry box
        self.entry.focus_set()
        self.top.focused_widget = self.entry

        # remove unneeded stuff
        self.per.removefilter(self.undo)
        self._rmcolorizer()
        #self.status_bar.pack_forget()

        # add a delegator to prevent editing of text widget
        self.doc_del = DocDelegator()
        self.doc_del.entry = self.entry

        self.per.insertfilter(self.doc_del)

        self.text._insert = self.doc_del.delegate.insert
        self.text._delete = self.doc_del.delegate.delete
        self.text.configure(wrap='none')

        keySetName = idleConf.CurrentKeys()
        find_bindings = idleConf.GetKeyBinding(keySetName, '<<find>>')
        for key_event in find_bindings:
            #self.entry.event_add('<<find>>', key_event)
            self.entry.bind(key_event, lambda e: self.text.event_generate('<<find>>'))

    def get_standard_extension_names(self):
        # Only load SearchBar if needed
        ret = []
        #a = idleConf.GetExtensions(editor_only=True)
        #if 'SearchBar' in a:
        #    ret.append('SearchBar')
        return ret

    def search(self, event=None):
        self.text.focus_set()
        self.text.update_idletasks()
        self.text.event_generate('<<find>>')
        self.text.update_idletasks()
        return "break"

    def get_help(self, event=None):
        #self.button_showhelp.configure(default='active')
        #self.button_showdoc.configure(default='disabled')
        b = self.entry.get().strip()
        if not b:
            return

        cmd = """if 1:
                    try:
                        help(%s)
                    except:
                        print("'%s' not found")""" % (b,b)

        self.process_request(cmd)

    def get_doc(self, event=None):
        #self.button_showhelp.configure(default='disabled')
        #self.button_showdoc.configure(default='active')

        b = self.entry.get().strip()
        if not b:
            return

        cmd = """if 1:
                try:
                    if hasattr(%s, '__doc__'):
                        print(%s.__doc__)
                    else:
                        print("%s doesn't have a doc string")
                except:
                    print("'%s' not found in the shell's namespace.")""" % ((b,)*4)

        cmd2 = """if 1:
                print "====Displaying %s.__doc__"
                print
                try:
                    if hasattr(%s, '__doc__'):
                        print(%s.__doc__)
                    else:
                        print("%s doesn't have a doc string")
                except:
                    print("'%s' not found in the shell's namespace.")
                print()
                print()
                print("====Displaying help(%s)")
                print()

                try:
                    help(%s)
                except:
                    print("'%s' not found in the shell's namespace.") """ % ((b,)*8)

        self.process_request(cmd)

    def process_request(self, cmd=None):

        if cmd is None:
            return

        try:
            test = compile(cmd, '', 'exec')
        except Exception as err:
            t = 'Unable to process your request.\nIs your given object in the namespace?'
            self.text._delete('1.0', 'end')
            self.text._insert('1.0', t)
            return

        interp = self.interp
        editwin = self.editwin

        self.count = 0

        if editwin.executing:
            self.text._insert(1.0, "The shell currently is executing a command.\n" \
                              "Please try again when the shell is done executing.\n")
            return

        editwin.text.mark_set("iomark2", "iomark")
        self.text._delete("1.0", "end")

        # redirect output from PyShell to DocViewer
        def insert_bridge(self, index, chars, tags=None):
            #self.count += 1
            #if self.count < 50:
            self.text.insert(index, chars, tags)

        __insert = editwin.text.insert
        editwin.text.insert = insert_bridge

        def mywrite(s, tags=()):
            if tags in ('stdout', 'stderr'):
                # send to me
                self.text._insert('insert', s,tags)

        __write = editwin.write
        editwin.write = mywrite

        interp.runcommand(cmd)

        # go into a loop, until help has arrived :)
        while editwin.executing:
            editwin.text.update_idletasks()
            time.sleep(0.05)

        # restore output to PyShell
        editwin.text.insert = __insert
        editwin.write = __write

        editwin.text.mark_set("iomark", "iomark2")

    def close(self):
        set_cfg('calltip', self.update_calltip.get())
        # remove all references
        if 0:
            self.doc_frame.destroy()
            self.editwin = None
            self.interp = None
            self.text._delete = None
            self.text._insert = None
            self.per.removefilter(self.doc_del)
            self.undo = None
            self.doc_del = None
        #EditorWindow.close(self)
        self._close()
        self.top.destroy()
        #print 'refcount: ', sys.getrefcount(DocViewer.WINDOW)
        DocViewer.WINDOW = None

    def short_title(self):
        return "IDLE Documentation Viewer"


text:
title:  Co odpowiesz?
date:   20/03/2022
---

**Przeczytaj Flp 4:6-7**

Czasem do przetrwania w szkole przydatny jest kamuflaż – nie wychylać się, nie wyróżniać, nie dawać powodów, by zauważono, że jesteś inny. Wtedy łatwiej uniknąć krytyki, czy wyśmiania. Niestety, bohater wiary - chrześcijanin z prawdziwego zdarzenia - jest osobą dość widoczną. Nie da się być nieoficjalnym, niezauważalnym uczniem Jezusa. Czy da się więc być "kimś" w towarzystwie naszych znajomych, będąc jednocześnie prawdziwym, bezkompromisowym uczniem Jezusa? Jak myślisz? Spróbuj też znaleźć przykłady sytuacji, w których chrześcijańska postawa może spotkać się z wyśmianiem, lub uznaniem ze strony znajomych.


text:
using EmbeddedAuthorizationServer.Provider;
using Microsoft.Owin;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.OAuth;
using Owin;
using System;

[assembly: OwinStartup(typeof(EmbeddedAuthorizationServer.Startup))]

namespace EmbeddedAuthorizationServer
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // token generation
            var serverOptions = new OAuthAuthorizationServerOptions
            {
                // for demo purposes
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(8),
                Provider = new SimpleAuthorizationServerProvider(),
                AuthenticationMode = AuthenticationMode.Active,
                AuthenticationType = "Bearer"
            };
#if Debug
            System.Diagnostics.Debugger.Launch();
#endif
            app.UseOAuthAuthorizationServer(serverOptions); // Adds OAuth2 Authorization Server capabilities to an OWIN web application.
            /*
            This middleware performs the request processing for the Authorize and Token endpoints defined by the OAuth2 specification.
            See also http://tools.ietf.org/html/rfc6749
            */
            // token consumption
            var bearerOptions = new OAuthBearerAuthenticationOptions();
            app.UseOAuthBearerAuthentication(bearerOptions); // Adds Bearer token processing to an OWIN application pipeline.
            /*
            This middleware understands appropriately formatted and
            secured tokens which appear in the request header. If the Options.AuthenticationMode is Active, the claims within the
            bearer token are added to the current request's IPrincipal User.
            See also http://tools.ietf.org/html/rfc6749
            */
            app.UseWebApi(WebApiConfig.Register()); // add WebAPI endpoint processing to OWIN pipeline
        }
    }
}

/*
? serverOptions
{Microsoft.Owin.Security.OAuth.OAuthAuthorizationServerOptions}
    AccessTokenExpireTimeSpan: {08:00:00}
    AccessTokenFormat: null
    AccessTokenProvider: null
    AllowInsecureHttp: true
    ApplicationCanDisplayErrors: false
    AuthenticationMode: Active
    AuthenticationType: "Bearer"
    AuthorizationCodeExpireTimeSpan: {00:05:00}
    AuthorizationCodeFormat: null
    AuthorizationCodeProvider: null
    AuthorizeEndpointPath: {}
    Description: {Microsoft.Owin.Security.AuthenticationDescription}
    Provider: {EmbeddedAuthorizationServer.Provider.SimpleAuthorizationServerProvider}
    RefreshTokenFormat: null
    RefreshTokenProvider: null
    SystemClock: {Microsoft.Owin.Infrastructure.SystemClock}
    TokenEndpointPath: {/token}
? bearerOptions
{Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationOptions}
    AccessTokenFormat: null
    AccessTokenProvider: null
    AuthenticationMode: Active
    AuthenticationType: "Bearer"
    Description: {Microsoft.Owin.Security.AuthenticationDescription}
    Provider: null
    Realm: null
    SystemClock: {Microsoft.Owin.Infrastructure.SystemClock}

  */


text:
<?php

namespace Black\Component\Page\Infrastructure\CQRS\Command;

use Black\Component\Page\Domain\Model\WebPage;
use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command;

/**
 * Class RemoveWebPageCommand
 *
 * @author  Alexandre 'pocky' Balmes <alexandre@lablackroom.com>
 * @license http://opensource.org/licenses/mit-license.php MIT
 */
final class RemoveWebPageCommand implements Command
{
    /**
     * @var
     */
    private $webPage;

    /**
     * @param WebPage $webPage
     */
    public function __construct(WebPage $webPage)
    {
        $this->webPage = $webPage;
    }

    /**
     * @return mixed
     */
    public function getWebPage()
    {
        return $this->webPage;
    }
}


text: Laravel Notification


text:
package workflow

import (
	"encoding/json"
	"fmt"
	"path"
	"strings"
	"sync"
	"time"

	log "github.com/golang/glog"
	"golang.org/x/net/context"

	workflowpb "github.com/youtube/vitess/go/vt/proto/workflow"
)

// This file contains the necessary object definitions and interfaces
// to expose a workflow display to the vtctld webapp.
//
// Most constants and variable names should match the Node object described in
// web/vtctld2/src/app/workflows/node.ts as it is exposed as JSON to
// the Angular 2 web app.

// NodeDisplay constants need to match node.ts.Display.
type NodeDisplay int

const (
	// NodeDisplayUnknown is an unknown value and should never be set.
	NodeDisplayUnknown NodeDisplay = 0

	// NodeDisplayIndeterminate is a progress bar that doesn't have
	// a current value, but just shows movement.
	NodeDisplayIndeterminate NodeDisplay = 1

	// NodeDisplayDeterminate is a progress bar driven by the
	// Progress field.
	NodeDisplayDeterminate NodeDisplay = 2

	// NodeDisplayNone shows no progress bar or status.
	NodeDisplayNone NodeDisplay = 3
)

// ActionState constants need to match node.ts.ActionState.
type ActionState int

const (
	// ActionStateUnknown is an unknown value and should never be set.
	ActionStateUnknown ActionState = 0

	// ActionStateEnabled is for when the action is enabled.
	ActionStateEnabled ActionState = 1

	// ActionStateDisabled is for when the action is disabled.
	ActionStateDisabled ActionState = 2
)

// ActionStyle constants need to match node.ts.ActionStyle.
type ActionStyle int

const (
	// ActionStyleUnknown is an unknown value and should never be set.
	ActionStyleUnknown ActionStyle = 0

	// ActionStyleNormal will just trigger the action.
	ActionStyleNormal ActionStyle = 1

	// ActionStyleWarning will display a warning dialog to confirm
	// action with Action.Message.
	ActionStyleWarning ActionStyle = 2

	// ActionStyleWaiting highlights to the user that the process
	// is waiting on the execution of the action.
	ActionStyleWaiting ActionStyle = 3

	// ActionStyleTriggered is a state where the button is greyed
	// out and cannot be pressed.
	ActionStyleTriggered ActionStyle = 4
)

// ActionListener is an interface for receiving notifications about actions triggered
// from workflow UI.
type ActionListener interface {
	// Action is called when the user requests an action on a node.
	// 'path' is the node's Path value and 'name' is the invoked action's name.
	Action(ctx context.Context, path, name string) error
}

// Node is the UI representation of a Workflow toplevel object, or of
// a Workflow task. It is just meant to be a tree, and the various
// Workflow implementations can expose a tree of Nodes that represent
// what they are doing.
//
// Actions are meant to be buttons, that will trigger the Action
// callback of a workflow.
//
// In order for the web UIs to be notified when changing this
// structure, any change to this Node has to be done inside a Modify()
// function.
//
// It should match the Node object described in
// web/vtctld2/src/app/workflows/node.ts as it is exposed as JSON to
// the Angular 2 web app.
type Node struct {
	// nodeManager is the NodeManager handling this Node.
	// It is set by AddRootNode, and propagated by AddChild.
	// Any change to this node must take the Manager's lock.
	nodeManager *NodeManager

	// Listener will be notified about actions invoked on this node.
	Listener ActionListener `json:"-"`

	// Next are all the attributes that are exported to node.ts.
	// Note that even though Path is publicly accessible it should be
	// changed only by Node and NodeManager, otherwise things can break.
	// It's public only to be exportable to json. Similarly PathName (which
	// is the last component of path) on top-level node should be populated
	// only by NodeManager. For non-top-level children it can be changed
	// at any time, Path will be adjusted correspondingly when the parent
	// node's BroadcastChanges() is called.

	Name            string                   `json:"name"`
	PathName        string                   `json:"pathName"`
	Path            string                   `json:"path"`
	Children        []*Node                  `json:"children,omitempty"`
	LastChanged     int64                    `json:"lastChanged"`
	Progress        int                      `json:"progress"`
	ProgressMessage string                   `json:"progressMsg"`
	State           workflowpb.WorkflowState `json:"state"`
	Display         NodeDisplay              `json:"display,omitempty"`
	Message         string                   `json:"message"`
	Log             string                   `json:"log"`
	Disabled        bool                     `json:"disabled"`
	Actions         []*Action                `json:"actions"`
}

// Action must match node.ts Action.
type Action struct {
	Name    string      `json:"name"`
	State   ActionState `json:"state,omitempty"`
	Style   ActionStyle `json:"style,omitempty"`
	Message string      `json:"message"`
}

// Update is the data structure we send on the websocket or on the
// long-polling HTTP connection to the clients.
type Update struct {
	// Redirect is set to the URL to go to if we are not the
	// master.  It is only set in the initial response, and if set
	// then no other field in this structure is set.
	Redirect string `json:"redirect,omitempty"`

	// Index is the watcher index. It is only set in the initial
	// tree.
	Index int `json:"index,omitempty"`

	// Nodes is a list of nodes to update.
	Nodes []*Node `json:"nodes,omitempty"`

	// Deletes is a list of toplevel paths to delete.
	Deletes []string `json:"deletes,omitempty"`

	// FullUpdate is set to true if this is a full refresh of the data.
	FullUpdate bool `json:"fullUpdate,omitempty"`
}

// NewNode is a helper function to create new UI Node struct.
func NewNode() *Node {
	return &Node{
		Children: []*Node{},
		Actions:  []*Action{},
	}
}

// BroadcastChanges sends the new contents of the node to the watchers.
func (n *Node) BroadcastChanges(updateChildren bool) error {
	n.nodeManager.mu.Lock()
	defer n.nodeManager.mu.Unlock()
	return n.nodeManager.updateNodeAndBroadcastLocked(n, updateChildren)
}

// deepCopyFrom copies contents of otherNode into this node. Contents of Actions
// is copied into new Action objects, so that changes in otherNode are not
// immediately visible in this node. When copyChildren is false the contents of
// Children in this node is preserved fully even if it doesn't match the contents
// of otherNode. When copyChildren is true then contents of Children is copied
// into new Node objects similar to contents of Actions.
// Method returns error if children in otherNode have non-unique values of
// PathName, i.e. it's impossible to create unique values of Path for them.
func (n *Node) deepCopyFrom(otherNode *Node, copyChildren bool) error {
	oldChildren := n.Children
	*n = *otherNode
	n.Children = oldChildren

	n.Actions = []*Action{}
	for _, otherAction := range otherNode.Actions {
		action := &Action{}
		*action = *otherAction
		n.Actions = append(n.Actions, action)
	}

	if !copyChildren {
		return nil
	}
	n.Children = []*Node{}
	childNamesSet := make(map[string]bool)
	for _, otherChild := range otherNode.Children {
		if _, ok := childNamesSet[otherChild.PathName]; ok {
			return fmt.Errorf("node %v already has a child name %v", n.Path, otherChild.PathName)
		}
		childNamesSet[otherChild.PathName] = true

		// Populate a few values in case the otherChild is newly created by user.
		otherChild.nodeManager = n.nodeManager
		otherChild.Path = path.Join(n.Path, otherChild.PathName)

		child := NewNode()
		child.deepCopyFrom(otherChild, true /* copyChildren */)
		n.Children = append(n.Children, child)
	}
	return nil
}

// GetChildByPath returns the child node given the relative path to this node.
// The caller must ensure that the node tree is not modified during the call.
func (n *Node) GetChildByPath(subPath string) (*Node, error) {
	// Find the subnode if needed.
	parts := strings.Split(subPath, "/")

	currentNode := n
	for i := 0; i < len(parts); i++ {
		childPathName := parts[i]
		found := false
		for _, child := range currentNode.Children {
			if child.PathName == childPathName {
				found = true
				currentNode = child
				break
			}
		}
		if !found {
			return nil, fmt.Errorf("node %v has no children named %v", currentNode.Path, childPathName)
		}
	}
	return currentNode, nil
}

// ActionParameters describe an action initiated by the user.
type ActionParameters struct {
	// Path is the path of the Node the action was performed on.
	Path string `json:"path"`

	// Name is the Name of the Action.
	Name string `json:"name"`
}

// NodeManager manages the Node tree.
type NodeManager struct {
	// mu protects all the fields.
	mu sync.Mutex

	// roots points at the root nodes, by uuid.
	roots map[string]*Node

	// watchers is a map of channels that need notifications when
	// we change our tree.
	watchers map[int]chan []byte

	// nextWatcherIndex is the index of the next registered watcher.
	nextWatcherIndex int
}

// NewNodeManager returns a new NodeManager.
func NewNodeManager() *NodeManager {
	return &NodeManager{
		roots:            make(map[string]*Node),
		watchers:         make(map[int]chan []byte),
		nextWatcherIndex: 1,
	}
}

// AddRootNode adds a toplevel Node to the NodeManager,
// and broadcasts the Node to the listeners.
func (m *NodeManager) AddRootNode(n *Node) error {
	m.mu.Lock()
	defer m.mu.Unlock()

	if _, ok := m.roots[n.PathName]; ok {
		return fmt.Errorf("toplevel node %v (with name %v) already exists", n.Path, n.Name)
	}
	n.Path = "/" + n.PathName
	n.nodeManager = m

	savedNode := NewNode()
	m.roots[n.PathName] = savedNode
	return m.updateNodeAndBroadcastLocked(n, true /* updateChildren */)
}

// RemoveRootNode removes a toplevel Node from the NodeManager,
// and broadcasts the change to the listeners.
func (m *NodeManager) RemoveRootNode(n *Node) {
	m.mu.Lock()
	defer m.mu.Unlock()

	delete(m.roots, n.PathName)

	u := &Update{
		Deletes: []string{n.Path},
	}
	m.broadcastUpdateLocked(u)
}

func (m *NodeManager) toJSON(index int) ([]byte, error) {
	u := &Update{
		Index:      index,
		FullUpdate: true,
	}
	for _, n := range m.roots {
		u.Nodes = append(u.Nodes, n)
	}
	return json.Marshal(u)
}

// GetFullTree returns the JSON representation of the entire Node tree.
func (m *NodeManager) GetFullTree() ([]byte, error) {
	m.mu.Lock()
	defer m.mu.Unlock()
	return m.toJSON(0)
}

// GetAndWatchFullTree returns the JSON representation of the entire Node tree,
// and registers a watcher to monitor changes to the tree.
func (m *NodeManager) GetAndWatchFullTree(notifications chan []byte) ([]byte, int, error) {
	m.mu.Lock()
	defer m.mu.Unlock()

	i := m.nextWatcherIndex
	m.nextWatcherIndex++

	result, err := m.toJSON(i)
	if err != nil {
		return nil, 0, err
	}

	// It worked, register the watcher.
	m.watchers[i] = notifications
	return result, i, nil
}

// broadcastUpdateLocked sends the provided update to all watchers.
// Has to be called with the lock.
func (m *NodeManager) broadcastUpdateLocked(u *Update) {
	data, err := json.Marshal(u)
	if err != nil {
		log.Errorf("Cannot JSON encode update: %v", err)
		return
	}

	// If we can't write on the channel, we close it and remove it
	// from the list. It probably means the web browser on the
	// other side is not there any more.
	for i, watcher := range m.watchers {
		select {
		case watcher <- data:
		default:
			log.Infof("Couldn't write to watcher %v, closing it.", i)
			close(watcher)
			delete(m.watchers, i)
		}
	}
}

// updateNodeAndBroadcastLocked updates the contents of the Node saved inside node manager that
// corresponds to the provided user node, and then broadcasts the contents to all watchers.
// If updateChildren is false then contents of the node's children (as well as the list of
// children) is not updated and not included into the broadcast.
// Has to be called with the lock.
func (m *NodeManager) updateNodeAndBroadcastLocked(userNode *Node, updateChildren bool) error {
	savedNode, err := m.getNodeByPathLocked(userNode.Path)
	if err != nil {
		return err
	}

	userNode.LastChanged = time.Now().Unix()
	if err := savedNode.deepCopyFrom(userNode, updateChildren); err != nil {
		return err
	}

	savedChildren := savedNode.Children
	if !updateChildren {
		// Note that since we are under mutex it's okay to temporarily change
		// Children right here in-place.
		savedNode.Children = nil
	}

	u := &Update{
		Nodes: []*Node{savedNode},
	}
	m.broadcastUpdateLocked(u)

	savedNode.Children = savedChildren
	return nil
}

// CloseWatcher unregisters the watcher from this Manager.
func (m *NodeManager) CloseWatcher(i int) {
	m.mu.Lock()
	defer m.mu.Unlock()

	delete(m.watchers, i)
}

// Action is called by the UI agents to trigger actions.
func (m *NodeManager) Action(ctx context.Context, ap *ActionParameters) error {
	n, err := m.getNodeByPath(ap.Path)
	if err != nil {
		return err
	}

	m.mu.Lock()

	if n.Listener == nil {
		m.mu.Unlock()
		return fmt.Errorf("Action %v is invoked on a node without listener (node path is %v)", ap.Name, ap.Path)
	}
	nodeListener := n.Listener
	m.mu.Unlock()

	return nodeListener.Action(ctx, ap.Path, ap.Name)
}

func (m *NodeManager) getNodeByPath(nodePath string) (*Node, error) {
	m.mu.Lock()
	defer m.mu.Unlock()
	return m.getNodeByPathLocked(nodePath)
}

func (m *NodeManager) getNodeByPathLocked(nodePath string) (*Node, error) {
	// Find the starting node. Path is something like:
	// /XXXX-XXXX-XXX
	// /XXXX-XXXX-XXX/child1
	// /XXXX-XXXX-XXX/child1/grandchild1
	// So parts[0] will always be empty, and parts[1] will always
	// be the UUID.
	parts := strings.Split(nodePath, "/")
	n, ok := m.roots[parts[1]]
	if !ok {
		return nil, fmt.Errorf("no root node with path /%v", parts[1])
	}

	// Find the subnode if needed.
	for i := 1; i < len(parts)-1; i++ {
		childPathName := parts[i+1]
		found := false
		for _, sn := range n.Children {
			if sn.PathName == childPathName {
				found = true
				n = sn
				break
			}
		}
		if !found {
			return nil, fmt.Errorf("node %v has no children named %v", n.Path, childPathName)
		}
	}

	return n, nil
}


text:
A util to decompose a object on javascript.

See the documentation on:

* [Español](./es)


text:
<?php
use WebSocket\Client;
/**
 * Created by PhpStorm.
 * User: steve
 * Date: 22/10/2016
 * Time: 18:54
 */
class Graphene_WSS
{

    public $connversion = "WSS";

    private $client;
    function __construct()
    {
        $this->client = new Client("wss://steemit.com/wspa");
    }

    function request($method, $params=array()) {

        $this->client = new Client("wss://steemit.com/wspa");

        $parameters = array(
            "id"  => 1,
            "method" => $method,
            "params" => $params
        );

        $this->client->send(json_encode($parameters));

        //echo var_dump(json_encode($parameters));

        $response = @json_decode($this->client->receive());

        //return var_dump($response);

        if(property_exists($response, "error")) { App::Abort(404, $response->error->data->message); }

        return $response;
    }

    function format_response($response)
    {
        return @json_decode($response);
    }
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gem5: EtherObject Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">

Main Page

Modules

Namespaces

Classes

Files

Related Pages

      <form action="search.php" method="get">

             Search for
            <input type="text" name="query" value="" size="20" accesskey="s"/>

      </form>

Alphabetical List

Class List

Class Hierarchy

Class Members

EtherObject Class Reference
The base EtherObject class, allows for an accesor function to a simobj that returns the Port.
More...

#include <etherobject.hh>

Inheritance diagram for EtherObject:

<map name="EtherObject_map">
<area href="classSimObject.html" alt="SimObject" shape="rect" coords="105,56,200,80">
<area href="classEventManager.html" alt="EventManager" shape="rect" coords="0,0,95,24">
<area href="classSerializable.html" alt="Serializable" shape="rect" coords="105,0,200,24">
<area href="classDrainable.html" alt="Drainable" shape="rect" coords="210,0,305,24">
<area href="classEtherBus.html" alt="EtherBus" shape="rect" coords="0,168,95,192">
<area href="classEtherLink.html" alt="EtherLink" shape="rect" coords="105,168,200,192">
<area href="classEtherTap.html" alt="EtherTap" shape="rect" coords="210,168,305,192">
</map>
List of all members.

Public Types

typedef EtherObjectParams 	Params

Public Member Functions

 	EtherObject (const Params *params)

const Params * 	params () const

virtual EtherInt * 	getEthPort (const std::string &if_name, int idx=-1)=0

 	Additional function to return the Port of a memory object.

Detailed Description

The base EtherObject class, allows for an accesor function to a simobj that returns the Port.

Definition at line 48 of file etherobject.hh.

Member Typedef Documentation

          typedef EtherObjectParams EtherObject::Params

Reimplemented from SimObject.

Reimplemented in EtherBus, EtherLink, and EtherTap.

Definition at line 51 of file etherobject.hh.

Constructor & Destructor Documentation

          EtherObject::EtherObject
          (
          const Params *
           params
           )
           [inline]

Definition at line 52 of file etherobject.hh.

Member Function Documentation

          virtual EtherInt* EtherObject::getEthPort
          (
          const std::string &
           if_name,

          int
           idx = -1

          )
          		 [pure virtual]

Additional function to return the Port of a memory object.

Implemented in EtherBus, EtherLink, and EtherTap.

          const Params* EtherObject::params
          (

           )
           const [inline]

Reimplemented from SimObject.

Reimplemented in EtherBus, EtherLink, and EtherTap.

Definition at line 56 of file etherobject.hh.

References SimObject::_params.

The documentation for this class was generated from the following file:

dev/etherobject.hh

<address style="align: right;">
Generated on Fri Apr 17 12:39:37 2015 for gem5 by  doxygen 1.4.7</address>