text:
var searchData=
[
  ['positionaldata',['PositionalData',['../class_positional_data.html',1,'']]]
];


text:
package org.apache.pdfbox.preflight.process.reflect;

import static org.apache.pdfbox.preflight.PreflightConfiguration.EXTGSTATE_PROCESS;
import static org.apache.pdfbox.preflight.PreflightConfiguration.FONT_PROCESS;
import static org.apache.pdfbox.preflight.PreflightConfiguration.GRAPHIC_PROCESS;
import static org.apache.pdfbox.preflight.PreflightConfiguration.SHADING_PATTERN_PROCESS;
import static org.apache.pdfbox.preflight.PreflightConfiguration.TILING_PATTERN_PROCESS;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDFontFactory;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern;
import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
import org.apache.pdfbox.pdmodel.graphics.shading.PDShading;
import org.apache.pdfbox.pdmodel.graphics.PDXObject;
import org.apache.pdfbox.preflight.PreflightConstants;
import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION;
import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_MAIN;
import static org.apache.pdfbox.preflight.PreflightConstants.TRANPARENCY_DICTIONARY_KEY_EXTGSTATE;
import org.apache.pdfbox.preflight.PreflightContext;
import org.apache.pdfbox.preflight.PreflightPath;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
import org.apache.pdfbox.preflight.exception.ValidationException;
import org.apache.pdfbox.preflight.process.AbstractProcess;
import org.apache.pdfbox.preflight.utils.COSUtils;
import org.apache.pdfbox.preflight.utils.ContextHelper;

public class ResourcesValidationProcess extends AbstractProcess
{

    @Override
    public void validate(PreflightContext ctx) throws ValidationException
    {
        PreflightPath vPath = ctx.getValidationPath();
        if (vPath.isEmpty())
        {
        }
        else if (!vPath.isExpectedType(PDResources.class))
        {
            addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_PDF_PROCESSING_MISSING, "Resources validation process needs at least one PDResources object"));
        }
        else
        {
            PDResources resources = (PDResources) vPath.peek();

            validateFonts(ctx, resources);
            validateExtGStates(ctx, resources);
            validateShadingPattern(ctx, resources);
            validateTilingPattern(ctx, resources);
            validateXObjects(ctx, resources);
        }
    }

    /**
     * Check that fonts present in the Resources dictionary match with PDF/A-1 rules
     *
     * @param context
     * @param resources
     * @throws ValidationException
     */
    protected void validateFonts(PreflightContext context, PDResources resources) throws ValidationException
    {
        Map<String, PDFont> mapOfFonts = getFonts(resources.getCOSObject(), context);
        if (mapOfFonts != null)
        {
            for (Entry<String, PDFont> entry : mapOfFonts.entrySet())
            {
                ContextHelper.validateElement(context, entry.getValue(), FONT_PROCESS);
            }
        }
    }

    /**
     * This will get the map of fonts. This will never return null.
     *
     * @return The map of fonts.
     */
    private Map<String, PDFont> getFonts(COSDictionary resources, PreflightContext context)
    {
        Map<String, PDFont> fonts = new HashMap<String, PDFont>();
        COSDictionary fontsDictionary = (COSDictionary) resources.getDictionaryObject(COSName.FONT);
        if (fontsDictionary == null)
        {
            fontsDictionary = new COSDictionary();
            resources.setItem(COSName.FONT, fontsDictionary);
        }
        for (COSName fontName : fontsDictionary.keySet())
        {
            COSBase font = fontsDictionary.getDictionaryObject(fontName);
            // data-000174.pdf contains a font that is a COSArray, looks to be an error in the
            // PDF, we will just ignore entries that are not dictionaries.
            if (font instanceof COSDictionary)
            {
                PDFont newFont = null;
                try
                {
                    newFont = PDFontFactory.createFont((COSDictionary) font);
                }
                catch (IOException e)
                {
                    addFontError((COSDictionary)font, context);
                }
                if (newFont != null)
                {
                    fonts.put(fontName.getName(), newFont);
                }
            }
        }
        return fonts;
    }

    /**
     * PDFont loads embedded fonts in its constructor so we have to handle IOExceptions
     * from PDFont and translate them into validation errors.
     */
    private void addFontError(COSDictionary dictionary, PreflightContext context)
    {
        COSName type = dictionary.getCOSName(COSName.TYPE, COSName.FONT);
        if (!COSName.FONT.equals(type))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_UNKNOWN_FONT_TYPE,
                    "Expected 'Font' dictionary but found '" + type.getName() + "'"));
        }

        String fontName = "Unknown";
        if (dictionary.containsKey(COSName.BASE_FONT))
        {
            fontName = dictionary.getNameAsString(COSName.BASE_FONT);
        }

        COSName subType = dictionary.getCOSName(COSName.SUBTYPE);
        if (COSName.TYPE1.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_TYPE1_DAMAGED,
                    "The FontFile can't be read for " + fontName));
        }
        else if (COSName.MM_TYPE1.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_TYPE1_DAMAGED,
                    "The FontFile can't be read for " + fontName));
        }
        else if (COSName.TRUE_TYPE.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_TRUETYPE_DAMAGED,
                                        "The FontFile can't be read for " + fontName));
        }
        else if (COSName.TYPE3.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_TYPE3_DAMAGED,
                    "The FontFile can't be read for " + fontName));
        }
        else if (COSName.TYPE0.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_CID_DAMAGED,
                    "The FontFile can't be read for " + fontName));
        }
        else if (COSName.CID_FONT_TYPE0.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_UNKNOWN_FONT_TYPE,
                    "Unexpected CIDFontType0 descendant font for " + fontName));
        }
        else if (COSName.CID_FONT_TYPE2.equals(subType))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_UNKNOWN_FONT_TYPE,
                    "Unexpected CIDFontType2 descendant font for " + fontName));
        }
        else
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_FONTS_UNKNOWN_FONT_TYPE,
                    "Unknown font type for " + fontName));
        }
    }

    /**
     *
     * @param context
     * @param resources
     * @throws ValidationException
     */
    protected void validateExtGStates(PreflightContext context, PDResources resources) throws ValidationException
    {
        COSBase egsEntry = resources.getCOSObject().getItem(TRANPARENCY_DICTIONARY_KEY_EXTGSTATE);
        COSDocument cosDocument = context.getDocument().getDocument();
        COSDictionary extGState = COSUtils.getAsDictionary(egsEntry, cosDocument);
        if (egsEntry != null)
        {
            ContextHelper.validateElement(context, extGState, EXTGSTATE_PROCESS);
        }
    }

    /**
     * This method check the Shading entry of the resource dictionary if exists.
     *
     * @param context
     * @param resources
     * @throws ValidationException
     */
    protected void validateShadingPattern(PreflightContext context, PDResources resources) throws ValidationException
    {
        try
        {
            for (COSName name : resources.getShadingNames())
            {
                PDShading shading = resources.getShading(name);
                ContextHelper.validateElement(context, shading, SHADING_PATTERN_PROCESS);
            }
        }
        catch (IOException e)
        {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION, e.getMessage(), e));
        }
    }

    /**
     * This method check the Shading entry of the resource dictionary if exists.
     *
     * @param context
     * @param resources
     * @throws ValidationException
     */
    protected void validateTilingPattern(PreflightContext context, PDResources resources) throws ValidationException
    {
        try
        {
            for (COSName name : resources.getPatternNames())
            {
                PDAbstractPattern pattern = resources.getPattern(name);
                if (pattern instanceof PDTilingPattern)
                {
                    ContextHelper.validateElement(context, pattern, TILING_PATTERN_PROCESS);
                }
            }
        }
        catch (IOException e)
        {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION, e.getMessage(), e));
        }
    }

    protected void validateXObjects(PreflightContext context, PDResources resources) throws ValidationException
    {
        COSDocument cosDocument = context.getDocument().getDocument();
        COSDictionary mapOfXObj = COSUtils.getAsDictionary(resources.getCOSObject().getItem(COSName.XOBJECT),
                cosDocument);
        if (mapOfXObj != null)
        {
            for (Entry<COSName, COSBase> entry : mapOfXObj.entrySet())
            {
                COSBase xobj = entry.getValue();
                if (xobj != null && COSUtils.isStream(xobj, cosDocument))
                {
                    try
                    {
                        COSStream stream = COSUtils.getAsStream(xobj, cosDocument);
                        PDXObject pdXObject = PDXObject.createXObject(stream, entry.getKey().getName(), resources);
                        if (pdXObject != null)
                        {
                            ContextHelper.validateElement(context, pdXObject, GRAPHIC_PROCESS);
                        }
                        else
                        {
                            ContextHelper.validateElement(context, stream, GRAPHIC_PROCESS);
                        }
                    }
                    catch (IOException e)
                    {
                        context.addValidationError(new ValidationError(ERROR_GRAPHIC_MAIN,
                                e.getMessage() + " for entry '"
                                + entry.getKey().getName() + "'", e));
                    }
                }
            }
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
NS_ASSUME_NONNULL_BEGIN

@interface ZeroConfigState : NSObject

@property (atomic, copy, nullable) NSString* partnerXcs;
@property (atomic) BOOL disposition;
@property (atomic) BOOL sentMCCMNC;

@property (nonatomic, readonly) BOOL zeroOnDialogShownOnce;
@property (nonatomic, readonly) BOOL warnWhenLeaving;
@property (nonatomic, readonly) BOOL fakeZeroOn;

- (void)setZeroOnDialogShownOnce;
- (void)toggleWarnWhenLeaving;
- (void)toggleFakeZeroOn;

@end

NS_ASSUME_NONNULL_END


text:
namespace omaha {

// Timeout for tearing down thread
const int kMaxThreadDestructionTimeMs = 2000;

const int kRegisterExeTimeoutMs =                  30000;      // 30 seconds

}  // namespace omaha

#endif  // OMAHA_COMMON_CONST_TIMEOUTS_H__


text:
package com.BLKBelediye.balikesirbelediye;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;

/**
 * Created by EsatTaha on 30.01.2014.
 */
public class deneme extends Activity {
    String temp;
    private static ArrayList<ArrayList> result = new ArrayList<ArrayList>();
    TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.deneme);

        tv = (TextView) findViewById(R.id.tvDeneme);

        temp = "";
        try {
            result = MethodInfoGetter.methodRequest("HaberGetir", "", "");
            Log.i("MainMenu", "Result gelis vakti");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if(result.isEmpty())
        {
            tv.setText("Result is emty");
        }
        else
        {
            for(int i = 0 ; i < result.size() ; i++)
            {
                temp += "\n Burasi iki element arasi \n";
                Log.i("Deneme icindeki result sayisi",String.valueOf(result.get(i).size()));
                for(int j = 0 ; j < result.get(i).size() ; j++ )
                {
                    temp += result.get(i).get(j) + "\n burasi iki tag arasi \n";
                }
            }
        }
        tv.setText(temp);

    }
}


text:
import logging
import traceback
import sys

class LogStream(object):
    def __init__(self, logger=None, level=logging.INFO):
        self.level = level
        if not logger:
            self.logger = logging.getLogger()
        else:
            self.logger = logger

    def write(self, text):
        self.logger.log(self.level, text)

class LogHandler(logging.Handler):
    def __init__(self, format=None):
        logging.Handler.__init__(self)
        format = format or "%(asctime)s %(levelname)s %(message)s"
        formatter = logging.Formatter(format)
        self.setFormatter(formatter)
        self.listeners = []
    def register(self, func):
        self.listeners.append(func)
    def unregister(self, func):
        self.listeners.remove(func)
    def emit(self, record):
        for listener in self.listeners:
            listener(self, record)

def redirect_stdout(logname=None):
    sys.stdout = LogStream(logging.getLogger(logname), level=logging.INFO)
    pass

def redirect_stderr(logname=None):
    sys.stderr = LogStream(logging.getLogger(logname), level=logging.INFO)
    pass

# Global stuff
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(levelname)s %(message)s',
                    filename="log.txt",
                    filemode='w')


text:
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

queue = client.queues.create(friendly_name="newqueue")
print(queue.sid)


text:
const electron = require('electron');
const {
	ipcRenderer
} = require('electron');

const {remote} = electron;
const mainProcess = remote.require('./main');
window.$ = window.jQuery = require('jquery'); // eslint-disable-line no-multi-assign
require('../notification'); // eslint-disable-line  import/no-unassigned-import

/* global $:true */
/* global window:true */
/* global document:true */

$(document).ready(async () => {
	const menuItems = await mainProcess.menuItems()
		.catch(error => {
			console.error(error);
		});
	for (let i = 0; i < menuItems.length; i++) {
		$('#menu_smartphone ul').append(`<li id="menu_${menuItems[i].id}"><span class="glyphicon glyphicon-${menuItems[i].glyphicon}"></span> ${menuItems[i].name}</li>`);
	}

	require('../menu'); // eslint-disable-line  import/no-unassigned-import
	const availableEncoders = await mainProcess.availableEncoders()
		.catch(error => {
			console.error(error);
		});
	let encodersHTML = '';
	let selected = '';
	for (const i in availableEncoders) {
		if ({}.hasOwnProperty.call(availableEncoders, i)) {
			if (i === '0') {
				selected = ' selected';
			}

			encodersHTML += `<option value="${availableEncoders[i].id}"${selected}>${availableEncoders[i].name}</option>`;
			selected = '';
		}
	}

	$('#config-encoder').html(encodersHTML);
	const configData = await mainProcess.parseConfigRenderer('get', 'main', false)
		.catch(error => {
			console.error(error);
			console.error(error);
		});
	if (configData.renderScale !== undefined) {
		$('#config-renderScale').val(configData.renderScale);
	}

	if (configData.encoder !== undefined) {
		$('#config-encoder').val(configData.encoder);
	}

	if (configData.hwaccel === true) {
		$('#config-hwaccel').prop('checked', true);
	}

	if (configData.muteAudio === true) {
		$('#config-muteAudio').prop('checked', true);
	}

	if (configData.generateReport === true) {
		$('#config-generateReport').prop('checked', true);
	}

	if (configData.extraCabinets === true) {
		$('#config-extraCabinets').prop('checked', true);
	}

	if (configData.maxDuration !== undefined) {
		if (configData.maxDuration === false) {
			$('#config-maxDuration').val(null);
		} else {
			$('#config-maxDuration').val(configData.maxDuration);
		}
	}

	if (configData.attractScreenPath === undefined) {
		const elem = $('.bottom-bar');
		elem.html('Set Attract Screen Path!');
		elem.addClass('bottom-bar-error');
	} else {
		$('#label-attractScreenPath').html('Attract Screen Video - Set');
	}

	$('#config-attractScreenPath').off('click').on('click', () => {
		mainProcess.selectAttractScreenFile();
	});
	$('#config-form').change(event => {
		if (event.target.name === 'renderScale') {
			const split = event.target.value.split(':');
			// Calculate greatest common divisor
			const gcd = function (a, b) {
				return (!b) ? a : gcd(b, a % b); // eslint-disable-line no-negated-condition
			};

			const videoGCD = gcd(split[0], split[1]);
			// Divide width and height by GCD to validate aspect ratio
			if (split[0] / videoGCD === 4 && split[1] / videoGCD === 3) {
				$(`#errorBlock-${event.target.name}`).addClass('hidden');
				$(`#config-${event.target.name}`).parent().removeClass('has-error');
				$(`#config-${event.target.name}`).parent().removeClass('has-feedback');
				mainProcess.updateSettings([event.target.name, event.target.value]);
			} else {
				$(`#config-${event.target.name}`).parent().addClass('has-error');
				$(`#config-${event.target.name}`).parent().addClass('has-feedback');
				$(`#errorBlock-${event.target.name}`).html('Invalid render scale ratio - must be 4:3');
				$(`#errorBlock-${event.target.name}`).removeClass('hidden');
			}
		} else if (event.target.type === 'checkbox') {
			mainProcess.updateSettings([event.target.name, event.target.checked]);
			if (event.target.name === 'extraCabinets') {
				mainProcess.editConfigINI(event.target.checked);
			}
		} else if (event.target.name === 'maxDuration') {
			if (Number(event.target.value) === 0) {
				mainProcess.updateSettings([event.target.name, false]);
			} else {
				mainProcess.updateSettings([event.target.name, Number(event.target.value)]);
			}
		} else {
			mainProcess.updateSettings([event.target.name, event.target.value]);
		}
	});
});

ipcRenderer.on('attractScreenSet', (event, data) => {
	if (data === true) {
		$('#label-attractScreenPath').html('Attract Screen Video - Set');
		const elem = $('.bottom-bar');
		elem.html('');
		elem.removeClass('bottom-bar-error');
	}
});


text:
<TimeML
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../../dtd/timeml_1.2.1.xsd">

<DOCNO> WSJ891026-0023 </DOCNO>
<DD> = 891026 </DD>
<AN> 891026-0023. </AN>
<HL> Business Brief -- Esselte AB:
@  Bid to Buy Remaining 22%
@  Of Unit Is Made by Firm </HL>
<DD> 10/26/89 </DD>
<SO> WALL STREET JOURNAL (J) </SO>
<CO> S.ESL ESB </CO>
<IN> TENDER OFFERS, MERGERS, ACQUISITIONS (TNM)
EARNINGS (ERN) </IN>
<TEXT>
   Esselte AB, the Stockholm office supplies company, as expected, proposed to acquire the 22% it doesn't own of its U.S. unit, Esselte Business Systems Inc.

   The price in the proposal is $43.50 for each of the 4.9 million shares the parent doesn't own, or $213.2 million.

   In New York Stock Exchange composite trading, Esselte closed yesterday at $43.50 a share, up $1.

   A committee of outside directors for the Garden City, N.Y., unit is evaluating the proposal; the parent asked it to respond by Oct. 31.
The unit said it can provide no assurance a transaction will occur.

   Esselte AB sold the minority stake five years ago in a $40 million international share offering.
The unit, which is the holding company for Esselte's non-Swedish units, accounted for 58% of sales and 71% of operating profit last year.

   Separately, Esselte Business Systems reported third-quarter net income fell 5.9% to $9.5 million, or 46 cents a share, from $10.1 million, or 49 cents a share, in the year-ago period.
Sales rose 2.9% to $329.2 million from $320 million.

</TEXT>

</TimeML>


text:
/* ###
 * IP: GHIDRA
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ghidra.file.formats.dump.mdmp;

import java.io.IOException;

import ghidra.app.util.bin.StructConverter;
import ghidra.file.formats.dump.DumpFileReader;
import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException;

public class Memory64ListStream implements StructConverter {

	public final static String NAME = "MINIDUMP_MEMORY_RANGE_64_LIST";

	private int numberOfMemoryRanges;
	private long baseRVA;
	private MemoryRange64[] memoryRanges;

	private DumpFileReader reader;
	private long index;

	Memory64ListStream(DumpFileReader reader, long index) throws IOException {
		this.reader = reader;
		this.index = index;

		parse();
	}

	private void parse() throws IOException {
		reader.setPointerIndex(index);

		setNumberOfMemoryRanges((int) reader.readNextLong());
		setBaseRVA(reader.readNextLong());
		memoryRanges = new MemoryRange64[numberOfMemoryRanges];
		for (int i = 0; i < numberOfMemoryRanges; i++) {
			setMemoryRange(new MemoryRange64(reader, reader.getPointerIndex()), i);
		}
	}

	/**
	 * @see ghidra.app.util.bin.StructConverter#toDataType()
	 */
	public DataType toDataType() throws DuplicateNameException {
		StructureDataType struct = new StructureDataType(NAME, 0);

		struct.add(QWORD, 8, "NumberOfMemoryRanges", null);
		struct.add(POINTER, 8, "BaseRva", null);
		DataType t = memoryRanges[0].toDataType();
		ArrayDataType a = new ArrayDataType(t, numberOfMemoryRanges, t.getLength());
		struct.add(a, a.getLength(), "MemoryRanges", null);

		struct.setCategoryPath(new CategoryPath("/MDMP"));

		return struct;
	}

	public long getNumberOfMemoryRanges() {
		return numberOfMemoryRanges;
	}

	public void setNumberOfMemoryRanges(int numberOfMemoryRanges) {
		this.numberOfMemoryRanges = numberOfMemoryRanges;
	}

	public void setBaseRVA(long baseRVA) {
		this.baseRVA = baseRVA;
	}

	public long getBaseRVA() {
		return baseRVA;
	}

	public MemoryRange64 getMemoryRange(int idx) {
		return memoryRanges[idx];
	}

	public void setMemoryRange(MemoryRange64 memoryRange, int index) {
		this.memoryRanges[index] = memoryRange;
	}

}


text:
r"""Creates test sets for the SentEval word_content task from Gutenberg data.

In the word_content task, all sentences contain exactly 1 out of a set of
mid-frequency words. This script creates new test sets conforming to the same
setup.

Please note that the number of target words in the new test set might be smaller
than the original 1000, because we might not have enough sentences for all of
the target words. This is not a problem, because it resembles exactly possible
test time scenarios.

The script assumes that the Gutenberg data was preprocessed with
fl_preprocess_gutenberg_main.

Train and dev sets are kept as is, meaning they are the original SentEval
train/dev data. This way the existing architecture can be trained as usual but
tested on new Gutenberg data.

This script doesn't do any case normalization, neither on the target words nor
on sentence duplicate detection.

This script generates the following directory structure under the
`base_out_dir`. This follows the original SentEval directory structure and thus
allows running the original scripts with no change.

base_out_dir/
  probing/TASK_NAME.txt  # Data for this task.
  probing/TASK_NAME.txt-settings.json  # Some information on the generated data.

TASK_NAME.txt contains all examples with their respective set labels attached.
This file follows the original SentEval data format.

Example call:
python -m \
  talk_about_random_splits.probing.\
create_test_set_from_gutenberg_word_content_main \
  --senteval_path="/tmp/senteval/task_data/probing" \
  --base_out_dir="YOUR_PATH_HERE" \
  --gutenberg_path="YOUR_PREPROCESSED_DATA_PATH_HERE" --alsologtostderr \
"""
import csv
import json
import os
import random

from absl import app
from absl import flags
from absl import logging
import pandas as pd

from talk_about_random_splits.probing import probing_utils

FLAGS = flags.FLAGS

flags.DEFINE_string(
    'gutenberg_path', None,
    'Path to the preprocessed Gutenberg data. Data must be preprocessed with '
    'fl_preprocess_gutenberg_main.')
flags.DEFINE_string('senteval_path', None,
                    'Path to the original SentEval data in tsv format.')
flags.DEFINE_string(
    'base_out_dir', None,
    'Base working dir in which to create subdirs for this script\'s results.')
flags.DEFINE_string(
    'split_name', 'gutenberg',
    'Determines the base name of result sub-directories in `base_out_dir`.')
flags.DEFINE_integer('num_trials', 5, 'Number of trials to generate data for.')
flags.DEFINE_integer('test_set_size', 10000,
                     'Number of requested examples in test sets.')

_TASK_NAME = 'word_content.txt'

def main(argv):
  if len(argv) > 1:
    raise app.UsageError('Too many command-line arguments.')

  word_content_data = probing_utils.read_senteval_data(FLAGS.senteval_path,
                                                       _TASK_NAME)
  target_words = set(word_content_data['target'])
  senteval_sentences = set(word_content_data['text'])
  target_word_to_sentences = probing_utils.get_target_word_to_sentence_mapping(
      target_words, senteval_sentences,
      probing_utils.get_strings_from_sharded_recordio(FLAGS.gutenberg_path))
  class_count = len(target_words)
  items_per_class = FLAGS.test_set_size // class_count
  target_word_counts = {k: len(v) for k, v in target_word_to_sentences.items()}
  valid_target_words = {
      k for k, v in target_word_counts.items() if v >= items_per_class
  }
  logging.info('Number of target words for which we have enough data: %d.',
               len(valid_target_words))
  assert valid_target_words

  train_set = word_content_data.loc[word_content_data['set'] == 'tr', :]
  dev_set = word_content_data.loc[word_content_data['set'] == 'va', :]

  experiment_base_dir = os.path.join(FLAGS.base_out_dir,
                                     f'{FLAGS.split_name}-{{}}')

  for trial_id in range(FLAGS.num_trials):
    split_dir = experiment_base_dir.format(trial_id)
    probing_dir = os.path.join(split_dir, 'probing')
    settings_path = os.path.join(probing_dir, f'{_TASK_NAME}-settings.json')
    data_out_path = os.path.join(probing_dir, _TASK_NAME)

    logging.info('Starting run: %d.', trial_id)

    data_sample = []

    for valid_target_word in valid_target_words:
      sentences = target_word_to_sentences[valid_target_word]
      current_sample = random.sample(sentences, items_per_class)
      data_sample.extend(
          ('te', valid_target_word, sample) for sample in current_sample)

    test_set = pd.DataFrame(data_sample, columns=train_set.columns)
    new_data = pd.concat([train_set, dev_set, test_set], ignore_index=True)

    logging.info('Writing output to file: %s.', data_out_path)
    os.make_dirs(probing_dir)

    with open(settings_path, 'w') as settings_file:
      settings = {
          'task_name': _TASK_NAME,
          'trial_id': trial_id,
          'train_size': len(train_set),
          'dev_size': len(dev_set),
          'test_size': len(test_set),
          'valid_target_words_size': len(valid_target_words),
          'valid_target_words': sorted(valid_target_words),
      }
      logging.info('Settings:\n%r', settings)
      json.dump(settings, settings_file, indent=2)

    with open(data_out_path, 'w') as data_file:
      # Don't add quoting to retain the original format unaltered.
      new_data[['set', 'target', 'text']].to_csv(
          data_file,
          sep='\t',
          header=False,
          index=False,
          quoting=csv.QUOTE_NONE,
          doublequote=False)

if __name__ == '__main__':
  flags.mark_flags_as_required(
      ['gutenberg_path', 'senteval_path', 'base_out_dir'])
  app.run(main)


text:
package org.overlord.dtgov.ui.server.services.tasks;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import org.apache.commons.configuration.Configuration;
import org.overlord.commons.config.JBossServer;
import org.overlord.dtgov.taskapi.types.FindTasksRequest;
import org.overlord.dtgov.taskapi.types.FindTasksResponse;
import org.overlord.dtgov.taskapi.types.StatusType;
import org.overlord.dtgov.taskapi.types.TaskDataType;
import org.overlord.dtgov.taskapi.types.TaskDataType.Entry;
import org.overlord.dtgov.taskapi.types.TaskSummaryType;
import org.overlord.dtgov.taskapi.types.TaskType;
import org.overlord.dtgov.taskclient.TaskApiClient;
import org.overlord.dtgov.taskclient.auth.AuthenticationProvider;
import org.overlord.dtgov.ui.client.shared.beans.TaskActionEnum;
import org.overlord.dtgov.ui.client.shared.beans.TaskBean;
import org.overlord.dtgov.ui.client.shared.beans.TaskInboxFilterBean;
import org.overlord.dtgov.ui.client.shared.beans.TaskInboxResultSetBean;
import org.overlord.dtgov.ui.client.shared.beans.TaskOwnerEnum;
import org.overlord.dtgov.ui.client.shared.beans.TaskSummaryBean;
import org.overlord.dtgov.ui.server.DtgovUIConfig;

/**
 * An implementation of a task client that goes against the Task API defined in DtGov.
 * @author eric.wittmann@redhat.com
 */
public class DtGovTaskApiClient implements ITaskClient {

    private TaskApiClient client;

    /**
     * Constructor.
     */
    public DtGovTaskApiClient(Configuration config) {
        String defaultTaskApiEndpoint = JBossServer.getBaseUrl() + "/dtgov/rest/tasks"; //$NON-NLS-1$
        String endpoint = config.getString(DtgovUIConfig.TASK_API_ENDPOINT, defaultTaskApiEndpoint);
        AuthenticationProvider authProvider = null;
        String authProviderClass = config.getString(DtgovUIConfig.TASK_API_AUTH_PROVIDER);
        try {
            if (authProviderClass != null && authProviderClass.trim().length() > 0) {
                Class<?> c = Class.forName(authProviderClass);
                Constructor<?> constructor = null;
                try {
                    constructor = c.getConstructor(Configuration.class);
                    authProvider = (AuthenticationProvider) constructor.newInstance(config);
                } catch (NoSuchMethodException e) {}
                try {
                    constructor = c.getConstructor();
                    authProvider = (AuthenticationProvider) constructor.newInstance();
                } catch (NoSuchMethodException e) {}
            }
            client = new TaskApiClient(endpoint, authProvider);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * @see org.overlord.dtgov.ui.server.services.tasks.ITaskClient#getTasks(org.overlord.dtgov.ui.client.shared.beans.TaskInboxFilterBean, int, int, java.lang.String, boolean)
     */
    @Override
    public TaskInboxResultSetBean getTasks(TaskInboxFilterBean filters, int startIndex, int endIndex,
            String sortColumnId, boolean sortAscending) throws Exception {
        FindTasksRequest request = createFindTasksRequest(filters);
        request.setStartIndex(startIndex);
        request.setEndIndex(endIndex);
        request.setOrderBy(sortColumnId);
        request.setOrderAscending(sortAscending);
        FindTasksResponse findTasksResponse = client.findTasks(request);

        TaskInboxResultSetBean result = new TaskInboxResultSetBean();
        result.setTasks(new ArrayList<TaskSummaryBean>());
        for (TaskSummaryType taskSummaryType : findTasksResponse.getTaskSummary()) {
            TaskSummaryBean taskSummaryBean = convertToBean(taskSummaryType);
            result.getTasks().add(taskSummaryBean);
        }
        result.setItemsPerPage((endIndex - startIndex) + 1);
        result.setTotalResults(findTasksResponse.getTotalResults());
        result.setStartIndex(startIndex);

        return result;
    }

    /**
     * @see org.overlord.dtgov.ui.server.services.tasks.ITaskClient#getTask(java.lang.String)
     */
    @Override
    public TaskBean getTask(String taskId) throws Exception {
        TaskType task = client.getTask(taskId);
        return convertToBean(task);
    }

    /**
     * @see org.overlord.dtgov.ui.server.services.tasks.ITaskClient#updateTask(org.overlord.dtgov.ui.client.shared.beans.TaskBean)
     */
    @Override
    public void updateTask(TaskBean task) throws Exception {
        // TODO implement updating a task!!  what are the jbpm/dtgov capabilities here?
    }

    /**
     * @see org.overlord.dtgov.ui.server.services.tasks.ITaskClient#executeAction(org.overlord.dtgov.ui.client.shared.beans.TaskBean, org.overlord.dtgov.ui.client.shared.beans.TaskActionEnum)
     */
    @Override
    public TaskBean executeAction(TaskBean task, TaskActionEnum action) throws Exception {
        TaskType updatedTask = null;
        if (action == TaskActionEnum.claim) {
            updatedTask = client.claimTask(task.getId());
        } else if (action == TaskActionEnum.complete) {
            updatedTask = client.completeTask(task.getId(), task.getTaskData());
        } else if (action == TaskActionEnum.start) {
            updatedTask = client.startTask(task.getId());
        } else if (action == TaskActionEnum.stop) {
            updatedTask = client.stopTask(task.getId());
        } else if (action == TaskActionEnum.release) {
            updatedTask = client.releaseTask(task.getId());
        } else if (action == TaskActionEnum.fail) {
            updatedTask = client.failTask(task.getId(), task.getTaskData());
        }
        return convertToBean(updatedTask);
    }

    /**
     * @throws DatatypeConfigurationException
     */
    protected DatatypeFactory getXmlFactory() {
        try {
            return DatatypeFactory.newInstance();
        } catch (DatatypeConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Converts the given task summary API object to a UI bean.
     * @param taskSummaryType
     */
    private TaskSummaryBean convertToBean(TaskSummaryType taskSummaryType) {
        TaskSummaryBean bean = new TaskSummaryBean();
        XMLGregorianCalendar dueDate = taskSummaryType.getDueDate();
        if (dueDate != null) {
            bean.setDueDate(dueDate.toGregorianCalendar().getTime());
        }
        bean.setId(taskSummaryType.getId());
        bean.setName(taskSummaryType.getName());
        bean.setOwner(taskSummaryType.getOwner());
        bean.setPriority(taskSummaryType.getPriority());
        bean.setStatus(taskSummaryType.getStatus().value());
        return bean;
    }

    /**
     * Converts the given task API object to a UI bean.
     * @param taskSummaryType
     */
    private TaskBean convertToBean(TaskType taskType) {
        TaskBean bean = new TaskBean();
        XMLGregorianCalendar dueDate = taskType.getDueDate();
        if (dueDate != null) {
            bean.setDueDate(dueDate.toGregorianCalendar().getTime());
        }
        bean.setId(taskType.getId());
        bean.setName(taskType.getName());
        bean.setOwner(taskType.getOwner());
        bean.setPriority(taskType.getPriority());
        bean.setStatus(taskType.getStatus().value());
        bean.setType(taskType.getType());
        bean.setDescription(taskType.getDescription());
        Map<String, String> taskData = new HashMap<String, String>();
        TaskDataType data = taskType.getTaskData();
        if (data != null) {
            List<Entry> entries = data.getEntry();
            for (Entry entry : entries) {
                taskData.put(entry.getKey(), entry.getValue());
            }
        }
        bean.setTaskData(taskData);
        assignAvailableActions(bean, taskType.getStatus());
        return bean;
    }

    /**
     * Adds the available actions to the task bean based on the status of the task.
     * @param bean
     * @param status
     */
    private void assignAvailableActions(TaskBean bean, StatusType status) {
        if (status == StatusType.COMPLETED || status == StatusType.FAILED || status == StatusType.ERROR) {
            // No actions available - tasks are complete.
        } else if (status == StatusType.READY) {
            bean.addAllowedAction(TaskActionEnum.claim);
        } else if (status == StatusType.IN_PROGRESS) {
            bean.addAllowedAction(TaskActionEnum.stop);
            bean.addAllowedAction(TaskActionEnum.complete);
            bean.addAllowedAction(TaskActionEnum.fail);
        } else if (status == StatusType.RESERVED) {
            bean.addAllowedAction(TaskActionEnum.release);
            bean.addAllowedAction(TaskActionEnum.start);
        }
    }

    /**
     * Creates a {@link FindTasksRequest} from the given task inbox filter bean.
     * @param filters
     */
    protected FindTasksRequest createFindTasksRequest(TaskInboxFilterBean filters) {
        FindTasksRequest request = new FindTasksRequest();
        if (filters.getPriority() >= 0) {
            request.getPriority().add(filters.getPriority());
        }
        if (filters.getDateDueFrom() != null) {
            DatatypeFactory dtFactory = getXmlFactory();
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(filters.getDateDueFrom());
            XMLGregorianCalendar from = dtFactory.newXMLGregorianCalendar(cal);
            request.setDueOnFrom(from);
        }
        if (filters.getDateDueTo() != null) {
            DatatypeFactory dtFactory = getXmlFactory();
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(filters.getDateDueTo());
            XMLGregorianCalendar to = dtFactory.newXMLGregorianCalendar(cal);
            request.setDueOnTo(to);
        }
        TaskOwnerEnum owner = filters.getOwner();
        if (owner == TaskOwnerEnum.any) {
            request.getStatus().add(StatusType.CREATED);
            request.getStatus().add(StatusType.READY);
            request.getStatus().add(StatusType.IN_PROGRESS);
            request.getStatus().add(StatusType.RESERVED);
        } else if (owner == TaskOwnerEnum.active) {
            request.getStatus().add(StatusType.IN_PROGRESS);
        } else if (owner == TaskOwnerEnum.mine) {
            request.getStatus().add(StatusType.IN_PROGRESS);
            request.getStatus().add(StatusType.RESERVED);
        } else if (owner == TaskOwnerEnum.group) {
            request.getStatus().add(StatusType.CREATED);
            request.getStatus().add(StatusType.READY);
        }
        return request;
    }

    /**
     * @see org.overlord.dtgov.ui.server.services.tasks.ITaskClient#setLocale(java.util.Locale)
     */
    @Override
    public void setLocale(Locale locale) {
        client.setLocale(locale);
    }

}


text:
package Net::ThreeScale::Client;

use strict;
use warnings;
use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS %QUEUE @QUEUE $QUEUE);
use Exporter;
use Data::Dumper;
use Carp;

use XML::Parser;
use XML::Simple;

use LWP::UserAgent;
use URI::Escape;
use HTTP::Request;
use HTTP::Status;
use HTTP::Request::Common;

use Net::ThreeScale::Response;
my $DEFAULT_USER_AGENT;

use constant {
	TS_RC_SUCCESS                => 'client.success',
	TS_RC_AUTHORIZE_FAILED       => 'provider_key_invalid',
	TS_RC_UNKNOWN_ERROR          => 'client.unknown_error'
};

BEGIN {
	@ISA         = qw(Exporter);
	$VERSION     = "2.0.2";
	@EXPORT_OK   = qw();
	%EXPORT_TAGS = (
		'all' => \@EXPORT_OK,
		'ALL' => \@EXPORT_OK,
	);
	$DEFAULT_USER_AGENT = "threescale_perl_client/$VERSION";

}

sub new {
	my $class = shift;
	my $params = ( $#_ == 0 ) ? { %{ (shift) } } : {@_};

	my $agent_string =
	  ( defined( $params->{user_agent} ) )
	  ? $params->{user_agent}
	  : $DEFAULT_USER_AGENT;

	croak("provider_key is a required parameter")
		unless defined( $params->{provider_key} );

	$params->{url} = 'http://su1.3scale.net'
		unless(defined($params->{url}));

	my $self = {};
	$self->{provider_key} = $params->{provider_key};
	$self->{url}          = $params->{url};
	$self->{DEBUG}        = $params->{DEBUG};
	$self->{ua}           = LWP::UserAgent->new( agent => $agent_string );

	return bless $self, $class;
}

sub authorize {
	my $self     = shift;
	my $p        = ( $#_ == 0 ) ? { %{ (shift) } } : {@_};

	die("app_id is required") unless defined($p->{app_id});

	my %query = (
		provider_key => $self->{provider_key},
	);

	while (my ($k, $v) = each(%{$p})) {
		$query{$k} = $v;
	}

	my $url = URI->new($self->{url} . "/transactions/authorize.xml");

	$url->query_form(%query);

	my $request = HTTP::Request::Common::GET($url);

	$self->_debug( "start> sending request: ", $request->as_string );
	my $response = $self->{ua}->request($request);

	$self->_debug( "start> got response : ", $response->as_string );

	if ( not ( $response->is_success || $response->status_line =~ /409/)) {
		return $self->_wrap_error($response);
	}

	my $data = $self->_parse_authorize_response( $response->content() );

	if ($data->{authorized} ne "true") {
		my $reason = $data->{reason};

		$self->_debug("authorization failed: $reason");

		return Net::ThreeScale::Response->new(
			success            => 0,
			error_code         => TS_RC_UNKNOWN_ERROR,
			error_message      => $reason
		)
	}

	$self->_debug( "success" );

	return Net::ThreeScale::Response->new(
		error_code  => TS_RC_SUCCESS,
		success     => 1,
		usage_reports => \@{$data->{usage_reports}->{usage_report}}
	);
}

sub report {
	my $self     = shift;
	my $p        = ( $#_ == 0 ) ? { %{ (shift) } } : {@_};

	die("transactions is a required parameter") unless defined($p->{transactions});
	die("transactions parameter must be a list")
		unless (ref($p->{transactions}) eq "ARRAY");

	my %query = (
		provider_key => $self->{provider_key},
	);

	while (my ($k, $v) = each(%{$p})) {
		if ($k eq "transactions") {
			next;
		}

		$query{$k} = $v;
	}

	my $content = "";

	while (my ($k, $v) = each(%query)) {
		if (length($content)) {
				$content .= "&\r\n";
		}

		$content .= "$k=" . uri_escape($v);
	}

	my $txnString = $self->_format_transactions(@{$p->{transactions}});

	$content .= "&" . $txnString;

	my $url = $self->{url} . "/transactions.xml";

	my $request = HTTP::Request::Common::POST($url, Content=>$content);

	$self->_debug( "start> sending request: ", $request->as_string );
	my $response = $self->{ua}->request($request);

	$self->_debug( "start> got response : ", $response->as_string );

	if ( not $response->is_success ) {
		return $self->_wrap_error($response);
	}

	$self->_debug( "success" );

	return Net::ThreeScale::Response->new(
		error_code  => TS_RC_SUCCESS,
		success     => 1,
	);
}

#Wraps an HTTP::Response message into a Net::ThreeScale::Response error return value
sub _wrap_error {
	my $self = shift;
	my $res  = shift;
	my $error_code;
	my $message;

	eval { ( $error_code, $message ) = $self->_parse_errors( $res->content() ); };

	if ($@) {
		$error_code = TS_RC_UNKNOWN_ERROR;
		$message    = 'unknown_error';
	}

	return Net::ThreeScale::Response->new(
		success    => 0,
		error_code => $error_code,    #
		error_message      => $message
	);
}

# Parses an error document out of a response body
# If no sensible error messages are found in the response, insert the standard error value
sub _parse_errors {
	my $self = shift;
	my $body = shift;
	my $cur_error;
	my $in_error  = 0;
	my $errstring = undef;
	my $errcode   = TS_RC_UNKNOWN_ERROR;

	return undef if !defined($body);
	my $parser = new XML::Parser(
		Handlers => {
			Start => sub {
				my $expat   = shift;
				my $element = shift;
				my %atts    = @_;

				if ( $element eq 'error' ) {
					$in_error  = 1;
					$cur_error = "";
					if ( defined( $atts{code} ) ) {
						$errcode = $atts{code};
					}
				}
			},
			End => sub {
				if ( $_[1] eq 'error' ) {
					$errstring = $cur_error;
					$cur_error = undef;
					$in_error  = 0;
				}
			},
			Char => sub {
				if ($in_error) {
					$cur_error .= $_[1];
				}
			  }
		}
	);

	eval { $parser->parse($body); };

	return ( $errcode, $errstring );
}

sub _parse_authorize_response {
	my $self          = shift;
	my $response_body = shift;

	my $xml = new XML::Simple(ForceArray=>['usage_report']);

	my $data = {};

	if (length($response_body)) {
		$data = $xml->XMLin($response_body);
	}

	return $data;
}

sub _format_transactions {
	my $self          = shift;
	my (@transactions)  = @_;

	my $output = "";

	my $transNumber = 0;

	for my $trans (@transactions) {
		die("Transactions should be given as hashes")
			unless(ref($trans) eq "HASH");

		die("Transactions need an 'app_id'")
			unless(defined($trans->{app_id}));

		die("Transactions need a 'usage' hash")
			unless(defined($trans->{usage}) and (ref($trans->{usage}) eq "HASH"));

		die("Transactions need a 'timestamp'")
			unless(defined($trans->{app_id}));

		my $pref = "transactions[$transNumber]";

		if ($transNumber > 0) {
				$output .= "&";
		}

		$output .= $pref . "[app_id]=" . $trans->{app_id};

		while (my ($k, $v) = each(%{$trans->{usage}})) {
			$k = uri_escape($k);
			$v = uri_escape($v);
			$output .= "&";
			$output .= $pref . "[usage][$k]=$v";
		}

		$output .= "&" . $pref . "[timestamp]=" . uri_escape($trans->{timestamp});

		$transNumber += 1;
	}

	return $output;
}

sub _debug {
	my $self = shift;
	if ( $self->{DEBUG} ) {
		print STDERR "DBG:", @_, "\n";
	}

}
1;

=head1 NAME

Net::ThreeScale::Client - Client for 3Scale.com web API version 2.0

=head1 SYNOPSIS

 use Net::ThreeScale::Client;

 my $client = new Net::ThreeScale::Client(provider_key=>"my_assigned_provider_key",
                                        url=>"http://su1.3Scale.net");

 my $response = $client->authorize(app_id  => $app_id,
                                   app_key => $app_key);

 if($response->is_success) {
       print "authorized ", $response->transaction,"\"n";
   ...

   my @transactions = (
      {
         app_id => $app_id,
         usage => {
           hits => 1,
         },

         timestamp => "2010-09-01 09:01:00",
      },

      {
         app_id => $app_id,
         usage => {
            hits => 1,
         },

         timestamp => "2010-09-02 09:02:00",
      }
   );

   my $report_response = $client->report(transactions=>\@transactions));
   if($report_response->is_success){
      print STDERR "Transactions reported\n";
   } else {
      print STDERR "Failed to report transactions",
                  $response->error_code(),":",
                  $response->error_message(),"\n";
   }
 } else {
   print STDERR "authorize failed with error :",
      $response->error_message,"\n";
   if($response->error_code == TS_RC_AUTHORIZE_FAILED) {
      print "Provider key is invalid";
   } else {
     ...
   }
 }

=head1 CONSTRUCTOR

 The class method new(...) creates a new 3Scale client object. This may
 be used to conduct transactions with the 3Scale service. The object is
 stateless and transactions may span multiple clients. The following
 parameters are recognised as arguments to new():

=over 4

=item provider_key

(required) The provider key used to identify you with the 3Scale service

=item url

(optional) The 3Scale service URL, usually this should be left to the
default value

=back

=head1 $response = $client->authorize(app_id=>$app_id, app_key=>$app_key)

Starts a new client transaction the call must include a application id (as
a string) and (optionally) an application key (string), identifying the
application to use.

Returns a Net::ThreeScale::Response object which indicates whether the
authorization was successful or indicates an error if one occured.

=head1 $response = $client->report(transactions=>\@transactions)

Reports a list of transactions to 3Scale.

=over 4

=item transactions=>{app_id=>value,...}

Should be an array similar to the following:

=over 4

  my @transactions = (
    {
      app_id => $app_id,
      usage => {
        hits => 1,
     }
     timestamp => "2010-09-01 09:01:00",
    },
    {
      app_id => $app_id,
      usage => {
        hits => 1,
      }
      timestamp => "2010-09-01 09:02:00",
    },
  );

=back

=back

=head1 EXPORTS / ERROR CODES

The following constants are exported and correspond to error codes
which may appear in calls to Net::ThreeScale::Response::error_code

=over 4

=item TS_RC_SUCCESS

The operation completed successfully

=item TS_RC_AUTHORIZE_FAILED

The  passed provider key was invalid

=item TS_RC_UNKNOWN_ERROR

An unspecified error occurred.  See the corresponding message for more detail.

=back

=head1 SEE ALSO

=over 4

=item  Net::ThreeScale::Response

Contains details of response contnet and values.

=back

=head1 AUTHOR

(c) Owen Cliffe 2008, Eugene Oden 2010


text:
package com.betfair.domain

import com.betfair.domain.InstructionReportErrorCode.InstructionReportErrorCode
import com.betfair.domain.InstructionReportStatus.InstructionReportStatus
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import play.api.libs.json._

case class PlaceInstructionReport(status: Option[InstructionReportStatus],
                                  errorCode: Option[InstructionReportErrorCode],
                                  instruction: Option[PlaceInstruction],
                                  betId: Option[String],
                                  placedDate: Option[DateTime],
                                  averagePriceMatched: Option[Double],
                                  sizeMatched: Option[Double])

object PlaceInstructionReport {

  val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

  implicit val jodaDateReads = Reads[DateTime](js =>
    js.validate[String].map[DateTime](dtString =>
      DateTime.parse(dtString, DateTimeFormat.forPattern(dateFormat))
    )
  )

  implicit val readsPlaceInstructionReport = Json.reads[PlaceInstructionReport]
}


text:
{% extends "site_base.html" %}

{% load i18n %}

{% block head_title %}{% trans "Welcome" %}{% endblock %}

{% block body_class %}home{% endblock %}

{% block body %}

        Kontulari es un software de gestión para la pymes, podrás gestionar clientes asistencias y bonos de mantenimiento y generar facturas.

{% endblock %}


text:
set -e

srcdir=`dirname $0`
test -n "$srcdir" && cd "$srcdir"

echo "Updating build configuration files, please wait...."

ACLOCAL_FLAGS="-I m4"
autoreconf -isf


text:
package com.icytown.course.experimentone.handler;

import android.content.Context;
import android.view.View;

import com.icytown.course.experimentone.context.FoodListActivity;
import com.icytown.course.experimentone.context.MainActivity;
import com.icytown.course.experimentone.databinding.ActivityStartBinding;

public class StartHandler {

    private Context mContext;
    private ActivityStartBinding mBinding;

    public StartHandler(Context context, ActivityStartBinding binding) {
        mContext = context;
        mBinding = binding;
    }

    public void onClickToMainActivity(View view) {
        MainActivity.startActivity(mContext);
    }

    public void onClickToListActivity(View view) {
        FoodListActivity.startActivity(mContext);
    }
}


text:
#include "src/core/lib/security/transport/handshake.h"

#include <stdbool.h>
#include <string.h>

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/transport/secure_endpoint.h"

#define GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE 256

typedef struct {
  grpc_security_connector *connector;
  tsi_handshaker *handshaker;
  bool is_client_side;
  unsigned char *handshake_buffer;
  size_t handshake_buffer_size;
  grpc_endpoint *wrapped_endpoint;
  grpc_endpoint *secure_endpoint;
  gpr_slice_buffer left_overs;
  gpr_slice_buffer incoming;
  gpr_slice_buffer outgoing;
  grpc_security_handshake_done_cb cb;
  void *user_data;
  grpc_closure on_handshake_data_sent_to_peer;
  grpc_closure on_handshake_data_received_from_peer;
  grpc_auth_context *auth_context;
} grpc_security_handshake;

static void on_handshake_data_received_from_peer(grpc_exec_ctx *exec_ctx,
                                                 void *setup, bool success);

static void on_handshake_data_sent_to_peer(grpc_exec_ctx *exec_ctx, void *setup,
                                           bool success);

static void security_connector_remove_handshake(grpc_security_handshake *h) {
  GPR_ASSERT(!h->is_client_side);
  grpc_security_connector_handshake_list *node;
  grpc_security_connector_handshake_list *tmp;
  grpc_server_security_connector *sc =
      (grpc_server_security_connector *)h->connector;
  gpr_mu_lock(&sc->mu);
  node = sc->handshaking_handshakes;
  if (node && node->handshake == h) {
    sc->handshaking_handshakes = node->next;
    gpr_free(node);
    gpr_mu_unlock(&sc->mu);
    return;
  }
  while (node) {
    if (node->next->handshake == h) {
      tmp = node->next;
      node->next = node->next->next;
      gpr_free(tmp);
      gpr_mu_unlock(&sc->mu);
      return;
    }
    node = node->next;
  }
  gpr_mu_unlock(&sc->mu);
}

static void security_handshake_done(grpc_exec_ctx *exec_ctx,
                                    grpc_security_handshake *h,
                                    int is_success) {
  if (!h->is_client_side) {
    security_connector_remove_handshake(h);
  }
  if (is_success) {
    h->cb(exec_ctx, h->user_data, GRPC_SECURITY_OK, h->secure_endpoint,
          h->auth_context);
  } else {
    if (h->secure_endpoint != NULL) {
      grpc_endpoint_shutdown(exec_ctx, h->secure_endpoint);
      grpc_endpoint_destroy(exec_ctx, h->secure_endpoint);
    } else {
      grpc_endpoint_destroy(exec_ctx, h->wrapped_endpoint);
    }
    h->cb(exec_ctx, h->user_data, GRPC_SECURITY_ERROR, NULL, NULL);
  }
  if (h->handshaker != NULL) tsi_handshaker_destroy(h->handshaker);
  if (h->handshake_buffer != NULL) gpr_free(h->handshake_buffer);
  gpr_slice_buffer_destroy(&h->left_overs);
  gpr_slice_buffer_destroy(&h->outgoing);
  gpr_slice_buffer_destroy(&h->incoming);
  GRPC_AUTH_CONTEXT_UNREF(h->auth_context, "handshake");
  GRPC_SECURITY_CONNECTOR_UNREF(h->connector, "handshake");
  gpr_free(h);
}

static void on_peer_checked(grpc_exec_ctx *exec_ctx, void *user_data,
                            grpc_security_status status,
                            grpc_auth_context *auth_context) {
  grpc_security_handshake *h = user_data;
  tsi_frame_protector *protector;
  tsi_result result;
  if (status != GRPC_SECURITY_OK) {
    gpr_log(GPR_ERROR, "Error checking peer.");
    security_handshake_done(exec_ctx, h, 0);
    return;
  }
  h->auth_context = GRPC_AUTH_CONTEXT_REF(auth_context, "handshake");
  result =
      tsi_handshaker_create_frame_protector(h->handshaker, NULL, &protector);
  if (result != TSI_OK) {
    gpr_log(GPR_ERROR, "Frame protector creation failed with error %s.",
            tsi_result_to_string(result));
    security_handshake_done(exec_ctx, h, 0);
    return;
  }
  h->secure_endpoint =
      grpc_secure_endpoint_create(protector, h->wrapped_endpoint,
                                  h->left_overs.slices, h->left_overs.count);
  h->left_overs.count = 0;
  h->left_overs.length = 0;
  security_handshake_done(exec_ctx, h, 1);
  return;
}

static void check_peer(grpc_exec_ctx *exec_ctx, grpc_security_handshake *h) {
  tsi_peer peer;
  tsi_result result = tsi_handshaker_extract_peer(h->handshaker, &peer);

  if (result != TSI_OK) {
    gpr_log(GPR_ERROR, "Peer extraction failed with error %s",
            tsi_result_to_string(result));
    security_handshake_done(exec_ctx, h, 0);
    return;
  }
  grpc_security_connector_check_peer(exec_ctx, h->connector, peer,
                                     on_peer_checked, h);
}

static void send_handshake_bytes_to_peer(grpc_exec_ctx *exec_ctx,
                                         grpc_security_handshake *h) {
  size_t offset = 0;
  tsi_result result = TSI_OK;
  gpr_slice to_send;

  do {
    size_t to_send_size = h->handshake_buffer_size - offset;
    result = tsi_handshaker_get_bytes_to_send_to_peer(
        h->handshaker, h->handshake_buffer + offset, &to_send_size);
    offset += to_send_size;
    if (result == TSI_INCOMPLETE_DATA) {
      h->handshake_buffer_size *= 2;
      h->handshake_buffer =
          gpr_realloc(h->handshake_buffer, h->handshake_buffer_size);
    }
  } while (result == TSI_INCOMPLETE_DATA);

  if (result != TSI_OK) {
    gpr_log(GPR_ERROR, "Handshake failed with error %s",
            tsi_result_to_string(result));
    security_handshake_done(exec_ctx, h, 0);
    return;
  }

  to_send =
      gpr_slice_from_copied_buffer((const char *)h->handshake_buffer, offset);
  gpr_slice_buffer_reset_and_unref(&h->outgoing);
  gpr_slice_buffer_add(&h->outgoing, to_send);
  /* TODO(klempner,jboeuf): This should probably use the client setup
     deadline */
  grpc_endpoint_write(exec_ctx, h->wrapped_endpoint, &h->outgoing,
                      &h->on_handshake_data_sent_to_peer);
}

static void on_handshake_data_received_from_peer(grpc_exec_ctx *exec_ctx,
                                                 void *handshake,
                                                 bool success) {
  grpc_security_handshake *h = handshake;
  size_t consumed_slice_size = 0;
  tsi_result result = TSI_OK;
  size_t i;
  size_t num_left_overs;
  int has_left_overs_in_current_slice = 0;

  if (!success) {
    gpr_log(GPR_ERROR, "Read failed.");
    security_handshake_done(exec_ctx, h, 0);
    return;
  }

  for (i = 0; i < h->incoming.count; i++) {
    consumed_slice_size = GPR_SLICE_LENGTH(h->incoming.slices[i]);
    result = tsi_handshaker_process_bytes_from_peer(
        h->handshaker, GPR_SLICE_START_PTR(h->incoming.slices[i]),
        &consumed_slice_size);
    if (!tsi_handshaker_is_in_progress(h->handshaker)) break;
  }

  if (tsi_handshaker_is_in_progress(h->handshaker)) {
    /* We may need more data. */
    if (result == TSI_INCOMPLETE_DATA) {
      grpc_endpoint_read(exec_ctx, h->wrapped_endpoint, &h->incoming,
                         &h->on_handshake_data_received_from_peer);
      return;
    } else {
      send_handshake_bytes_to_peer(exec_ctx, h);
      return;
    }
  }

  if (result != TSI_OK) {
    gpr_log(GPR_ERROR, "Handshake failed with error %s",
            tsi_result_to_string(result));
    security_handshake_done(exec_ctx, h, 0);
    return;
  }

  /* Handshake is done and successful this point. */
  has_left_overs_in_current_slice =
      (consumed_slice_size < GPR_SLICE_LENGTH(h->incoming.slices[i]));
  num_left_overs =
      (has_left_overs_in_current_slice ? 1 : 0) + h->incoming.count - i - 1;
  if (num_left_overs == 0) {
    check_peer(exec_ctx, h);
    return;
  }

  /* Put the leftovers in our buffer (ownership transfered). */
  if (has_left_overs_in_current_slice) {
    gpr_slice_buffer_add(
        &h->left_overs,
        gpr_slice_split_tail(&h->incoming.slices[i], consumed_slice_size));
    gpr_slice_unref(
        h->incoming.slices[i]); /* split_tail above increments refcount. */
  }
  gpr_slice_buffer_addn(
      &h->left_overs, &h->incoming.slices[i + 1],
      num_left_overs - (size_t)has_left_overs_in_current_slice);
  check_peer(exec_ctx, h);
}

/* If handshake is NULL, the handshake is done. */
static void on_handshake_data_sent_to_peer(grpc_exec_ctx *exec_ctx,
                                           void *handshake, bool success) {
  grpc_security_handshake *h = handshake;

  /* Make sure that write is OK. */
  if (!success) {
    gpr_log(GPR_ERROR, "Write failed.");
    if (handshake != NULL) security_handshake_done(exec_ctx, h, 0);
    return;
  }

  /* We may be done. */
  if (tsi_handshaker_is_in_progress(h->handshaker)) {
    /* TODO(klempner,jboeuf): This should probably use the client setup
       deadline */
    grpc_endpoint_read(exec_ctx, h->wrapped_endpoint, &h->incoming,
                       &h->on_handshake_data_received_from_peer);
  } else {
    check_peer(exec_ctx, h);
  }
}

void grpc_do_security_handshake(grpc_exec_ctx *exec_ctx,
                                tsi_handshaker *handshaker,
                                grpc_security_connector *connector,
                                bool is_client_side,
                                grpc_endpoint *nonsecure_endpoint,
                                grpc_security_handshake_done_cb cb,
                                void *user_data) {
  grpc_security_connector_handshake_list *handshake_node;
  grpc_security_handshake *h = gpr_malloc(sizeof(grpc_security_handshake));
  memset(h, 0, sizeof(grpc_security_handshake));
  h->handshaker = handshaker;
  h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake");
  h->is_client_side = is_client_side;
  h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE;
  h->handshake_buffer = gpr_malloc(h->handshake_buffer_size);
  h->wrapped_endpoint = nonsecure_endpoint;
  h->user_data = user_data;
  h->cb = cb;
  grpc_closure_init(&h->on_handshake_data_sent_to_peer,
                    on_handshake_data_sent_to_peer, h);
  grpc_closure_init(&h->on_handshake_data_received_from_peer,
                    on_handshake_data_received_from_peer, h);
  gpr_slice_buffer_init(&h->left_overs);
  gpr_slice_buffer_init(&h->outgoing);
  gpr_slice_buffer_init(&h->incoming);
  if (!is_client_side) {
    grpc_server_security_connector *server_connector =
        (grpc_server_security_connector *)connector;
    handshake_node = gpr_malloc(sizeof(grpc_security_connector_handshake_list));
    handshake_node->handshake = h;
    gpr_mu_lock(&server_connector->mu);
    handshake_node->next = server_connector->handshaking_handshakes;
    server_connector->handshaking_handshakes = handshake_node;
    gpr_mu_unlock(&server_connector->mu);
  }
  send_handshake_bytes_to_peer(exec_ctx, h);
}

void grpc_security_handshake_shutdown(grpc_exec_ctx *exec_ctx,
                                      void *handshake) {
  grpc_security_handshake *h = handshake;
  grpc_endpoint_shutdown(exec_ctx, h->wrapped_endpoint);
}


text:
require 'rubygems'
require 'rspec'

require File.join(File.dirname(__FILE__), '..', 'lib', 'kathy_lee')

require File.join(File.dirname(__FILE__), 'support', 'faux_record')
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require File.expand_path(f)}

Rspec.configure do |config|

  config.before(:all) do

  end

  config.after(:all) do

  end

  config.before(:each) do
    @old_list = fakes.list.dup
  end

  config.after(:each) do
    fakes.list = @old_list
  end

end

def fakes
  KathyLee::Fakes.instance
end


text:
/*
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.comcast.cdn.traffic_control.traffic_router.core.config;

import com.comcast.cdn.traffic_control.traffic_router.shared.CertificateData;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;

public class CertificateChecker {
	private final static Logger LOGGER = Logger.getLogger(CertificateChecker.class);

	public String getDeliveryServiceType(final JSONObject deliveryServiceJson) {
		final JSONArray matchsets = deliveryServiceJson.optJSONArray("matchsets");

		for (int i = 0; i < matchsets.length(); i++) {
			final JSONObject matchset = matchsets.optJSONObject(i);
			if (matchset == null) {
				continue;
			}

			final String deliveryServiceType = matchset.optString("protocol", "");
			if (!deliveryServiceType.isEmpty()) {
				return deliveryServiceType;
			}
		}
		return null;
	}

	public boolean certificatesAreValid(final List<CertificateData> certificateDataList, final JSONObject deliveryServicesJson) {
		for (final String deliveryServiceId : JSONObject.getNames(deliveryServicesJson)) {
			if (!deliveryServiceHasValidCertificates(certificateDataList, deliveryServicesJson, deliveryServiceId)) {
				return false;
			}
		}
		return true;
	}

	public boolean hasCertificate(final List<CertificateData> certificateDataList, final String deliveryServiceId) {
		return certificateDataList.stream()
			.filter(cd -> cd.getDeliveryservice().equals(deliveryServiceId))
			.findFirst()
			.isPresent();
	}

	private Boolean deliveryServiceHasValidCertificates(final List<CertificateData> certificateDataList, final JSONObject deliveryServicesJson, final String deliveryServiceId) {
		final JSONObject deliveryServiceJson = deliveryServicesJson.optJSONObject(deliveryServiceId);
		final JSONObject protocolJson = deliveryServiceJson.optJSONObject("protocol");

		if (!supportsHttps(deliveryServiceJson, protocolJson)) {
			return true;
		}

		final JSONArray domains = deliveryServiceJson.optJSONArray("domains");

		if (domains == null) {
			LOGGER.warn("Delivery Service " + deliveryServiceId + " is not configured with any domains!");
			return true;
		}

		if (domains.length() == 0) {
			return true;
		}

		boolean hasValidCertificates = false;

		for (int i = 0; i < domains.length(); i++) {
			final String domain = domains.optString(i, "").replaceAll("^\\*\\.", "");
			if (domain == null || domain.isEmpty()) {
				continue;
			}

			for (final CertificateData certificateData : certificateDataList) {
				if (certificateData.getDeliveryservice().equals(deliveryServiceId)) {
					hasValidCertificates = true;
				}
			}
			LOGGER.error("No certificate data for https " + deliveryServiceId + " domain " + domain);
		}

		return hasValidCertificates;
	}

	private boolean supportsHttps(final JSONObject deliveryServiceJson, final JSONObject protocolJson) {
		if (!"HTTP".equals(getDeliveryServiceType(deliveryServiceJson))) {
			return false;
		}

		return protocolJson != null ? protocolJson.optBoolean("acceptHttps", false) : false;
	}
}