text:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmSearch
    Inherits System.Windows.Forms.Form

    'Form reemplaza a Dispose para limpiar la lista de componentes.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Requerido por el Diseñador de Windows Forms
    Private components As System.ComponentModel.IContainer

    'NOTA: el Diseñador de Windows Forms necesita el siguiente procedimiento
    'Se puede modificar usando el Diseñador de Windows Forms.
    'No lo modifique con el editor de código.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim ListViewGroup1 As System.Windows.Forms.ListViewGroup = New System.Windows.Forms.ListViewGroup("ListViewGroup", System.Windows.Forms.HorizontalAlignment.Left)
        Dim ListViewGroup2 As System.Windows.Forms.ListViewGroup = New System.Windows.Forms.ListViewGroup("ListViewGroup", System.Windows.Forms.HorizontalAlignment.Left)
        Dim ListViewGroup3 As System.Windows.Forms.ListViewGroup = New System.Windows.Forms.ListViewGroup("ListViewGroup", System.Windows.Forms.HorizontalAlignment.Left)
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmSearch))
        Me.txtSearch = New System.Windows.Forms.TextBox()
        Me.btnSearch = New System.Windows.Forms.Button()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.rdBase = New System.Windows.Forms.RadioButton()
        Me.rdTranslation = New System.Windows.Forms.RadioButton()
        Me.rdBoth = New System.Windows.Forms.RadioButton()
        Me.chkIgnoreCase = New System.Windows.Forms.CheckBox()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.ListView1 = New System.Windows.Forms.ListView()
        Me.btnCancel = New System.Windows.Forms.Button()
        Me.cbIgnoreFormat = New System.Windows.Forms.CheckBox()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'txtSearch
        '
        Me.txtSearch.Location = New System.Drawing.Point(14, 32)
        Me.txtSearch.Name = "txtSearch"
        Me.txtSearch.Size = New System.Drawing.Size(434, 20)
        Me.txtSearch.TabIndex = 16
        '
        'btnSearch
        '
        Me.btnSearch.Location = New System.Drawing.Point(372, 76)
        Me.btnSearch.Name = "btnSearch"
        Me.btnSearch.Size = New System.Drawing.Size(75, 23)
        Me.btnSearch.TabIndex = 17
        Me.btnSearch.Text = "&Search"
        Me.btnSearch.UseVisualStyleBackColor = True
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(11, 14)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(67, 13)
        Me.Label2.TabIndex = 18
        Me.Label2.Text = "Search term:"
        '
        'rdBase
        '
        Me.rdBase.AutoSize = True
        Me.rdBase.Checked = True
        Me.rdBase.Location = New System.Drawing.Point(14, 59)
        Me.rdBase.Name = "rdBase"
        Me.rdBase.Size = New System.Drawing.Size(69, 17)
        Me.rdBase.TabIndex = 19
        Me.rdBase.TabStop = True
        Me.rdBase.Text = "&Base text"
        Me.rdBase.UseVisualStyleBackColor = True
        '
        'rdTranslation
        '
        Me.rdTranslation.AutoSize = True
        Me.rdTranslation.Location = New System.Drawing.Point(89, 58)
        Me.rdTranslation.Name = "rdTranslation"
        Me.rdTranslation.Size = New System.Drawing.Size(77, 17)
        Me.rdTranslation.TabIndex = 20
        Me.rdTranslation.Text = "&Translation"
        Me.rdTranslation.UseVisualStyleBackColor = True
        '
        'rdBoth
        '
        Me.rdBoth.AutoSize = True
        Me.rdBoth.Location = New System.Drawing.Point(172, 58)
        Me.rdBoth.Name = "rdBoth"
        Me.rdBoth.Size = New System.Drawing.Size(47, 17)
        Me.rdBoth.TabIndex = 21
        Me.rdBoth.Text = "B&oth"
        Me.rdBoth.UseVisualStyleBackColor = True
        '
        'chkIgnoreCase
        '
        Me.chkIgnoreCase.AutoSize = True
        Me.chkIgnoreCase.Location = New System.Drawing.Point(14, 85)
        Me.chkIgnoreCase.Name = "chkIgnoreCase"
        Me.chkIgnoreCase.Size = New System.Drawing.Size(94, 17)
        Me.chkIgnoreCase.TabIndex = 22
        Me.chkIgnoreCase.Text = "C&ase sensitive"
        Me.chkIgnoreCase.UseVisualStyleBackColor = True
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.ListView1)
        Me.GroupBox1.Location = New System.Drawing.Point(14, 115)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(434, 191)
        Me.GroupBox1.TabIndex = 23
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "Search results"
        '
        'ListView1
        '
        Me.ListView1.Enabled = False
        Me.ListView1.FullRowSelect = True
        Me.ListView1.GridLines = True
        ListViewGroup1.Header = "ListViewGroup"
        ListViewGroup1.Name = "ListViewGroup1"
        ListViewGroup2.Header = "ListViewGroup"
        ListViewGroup2.Name = "ListViewGroup2"
        ListViewGroup3.Header = "ListViewGroup"
        ListViewGroup3.Name = "ListViewGroup3"
        Me.ListView1.Groups.AddRange(New System.Windows.Forms.ListViewGroup() {ListViewGroup1, ListViewGroup2, ListViewGroup3})
        Me.ListView1.Location = New System.Drawing.Point(6, 19)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(422, 167)
        Me.ListView1.TabIndex = 14
        Me.ListView1.UseCompatibleStateImageBehavior = False
        '
        'btnCancel
        '
        Me.btnCancel.Location = New System.Drawing.Point(373, 314)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 15
        Me.btnCancel.Text = "&Close"
        Me.btnCancel.UseVisualStyleBackColor = True
        '
        'cbIgnoreFormat
        '
        Me.cbIgnoreFormat.AutoSize = True
        Me.cbIgnoreFormat.Location = New System.Drawing.Point(114, 85)
        Me.cbIgnoreFormat.Name = "cbIgnoreFormat"
        Me.cbIgnoreFormat.Size = New System.Drawing.Size(111, 17)
        Me.cbIgnoreFormat.TabIndex = 24
        Me.cbIgnoreFormat.Text = "&Ignore format tags"
        Me.cbIgnoreFormat.UseVisualStyleBackColor = True
        Me.cbIgnoreFormat.Visible = False
        '
        'frmSearch
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(459, 348)
        Me.Controls.Add(Me.cbIgnoreFormat)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.chkIgnoreCase)
        Me.Controls.Add(Me.rdBoth)
        Me.Controls.Add(Me.rdTranslation)
        Me.Controls.Add(Me.rdBase)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.btnSearch)
        Me.Controls.Add(Me.txtSearch)
        Me.Controls.Add(Me.btnCancel)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmSearch"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Search"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents txtSearch As System.Windows.Forms.TextBox
    Friend WithEvents btnSearch As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents rdBase As System.Windows.Forms.RadioButton
    Friend WithEvents rdTranslation As System.Windows.Forms.RadioButton
    Friend WithEvents rdBoth As System.Windows.Forms.RadioButton
    Friend WithEvents chkIgnoreCase As System.Windows.Forms.CheckBox
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents cbIgnoreFormat As System.Windows.Forms.CheckBox
End Class


text:
// Copyright 2019 Google LLC
//
// 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 storage

import (
	"fmt"
	"net/http"
	"net/url"
	"os"
	"strconv"
	"strings"

	"github.com/golang/protobuf/jsonpb" /* copybara-comment */
	"github.com/golang/protobuf/proto" /* copybara-comment */

	cpb "github.com/GoogleCloudPlatform/healthcare-federated-access-services/proto/common/v1" /* copybara-comment: go_proto */
)

var (
	secretParams = map[string]bool{
		"clientSecret":  true,
		"client_secret": true,
		"code":          true,
		"link_token":    true,
		"redirect_uri":  true,
	}
)

func MakeConfigHistory(desc, resType string, rev int64, ts float64, r *http.Request, user string, orig, update proto.Message) proto.Message {
	path := ""
	query := ""
	method := ""
	if r != nil {
		path = r.URL.Path
		method = r.Method
		first := true
		for name, values := range r.URL.Query() {
			if first {
				first = false
			} else {
				query += "&"
			}
			value := strings.Join(values, ",")
			if _, ok := secretParams[name]; ok {
				value = "***"
			}
			query += url.QueryEscape(name) + "=" + url.QueryEscape(value)
		}
	}
	m := jsonpb.Marshaler{}
	ov, _ := m.MarshalToString(orig)
	uv, _ := m.MarshalToString(update)

	return &cpb.HistoryEntry{
		Revision:      rev,
		User:          user,
		CommitTime:    ts,
		Path:          path,
		Query:         query,
		Desc:          desc,
		Method:        method,
		ChangeType:    resType,
		OriginalValue: ov,
		ChangeRequest: uv,
	}
}

// GetHistory returns a History object based on the input parameters.
func GetHistory(store Store, datatype, realm, user, id string, r *http.Request) (*cpb.History, int, error) {
	hlist := make([]proto.Message, 0)
	if err := store.ReadHistory(datatype, realm, user, id, &hlist); err != nil {
		if os.IsNotExist(err) {
			// TODO: perhaps this should be the empty list?
			return nil, http.StatusBadRequest, fmt.Errorf("no config history available")
		}
		return nil, http.StatusBadRequest, fmt.Errorf("service storage unavailable: %v, retry later", err)
	}
	he := make([]*cpb.HistoryEntry, len(hlist))
	var ok bool
	for i, e := range hlist {
		he[i], ok = e.(*cpb.HistoryEntry)
		if !ok {
			return nil, http.StatusInternalServerError, fmt.Errorf("cannot load history entry %d", i)
		}
	}
	history := &cpb.History{
		History: he,
	}
	pageToken := r.URL.Query().Get("pageToken")
	start, err := strconv.ParseInt(pageToken, 10, 64)
	if err != nil {
		start = 0
	}

	pageSize := r.URL.Query().Get("pageSize")
	size, err := strconv.ParseInt(pageSize, 10, 64)
	if err != nil || size < 1 {
		size = 50
	}
	if size > 1000 {
		size = 1000
	}
	// Reverse order
	a := history.History
	for i := len(a)/2 - 1; i >= 0; i-- {
		opp := len(a) - 1 - i
		a[i], a[opp] = a[opp], a[i]
	}

	for i, entry := range history.History {
		if entry.Revision <= start {
			history.History = history.History[i:]
			break
		}
	}
	if len(history.History) > int(size) {
		history.NextPageToken = fmt.Sprintf("%d", history.History[size].Revision)
		history.History = history.History[:size]
	}
	return history, http.StatusOK, nil
}

// ReplaceContentVariables does simple string replacement of variable names to values.
// If varValues is nil, then it only checks that `content` is JSON.
func ReplaceContentVariables(content proto.Message, varValues map[string]string) error {
	m := jsonpb.Marshaler{}
	js, err := m.MarshalToString(content)
	if err != nil {
		return err
	}
	replace := 0
	for k, v := range varValues {
		js = strings.Replace(js, k, v, -1)
		replace++
	}
	if replace == 0 {
		return nil
	}
	if err := jsonpb.Unmarshal(strings.NewReader(js), content); err != nil {
		return err
	}
	return nil
}

redpajama_set_name: RedPajamaGithub


text:
/*

  This is a Thymol extension to emulate the behaviour of the Spring dialect th:field attribute.
  Implements only enough functionality to get the STSM examples to do something!

 */

function fieldAttrProcessor(element, attr, thAttr) {
	var varExpr = new RegExp("[\*]{1}\{([^}]*)\}$"), fieldName = null, expr = attr.nodeValue, domUpdated = false, args, type, exprValue;
	if (expr) {
		expr = expr.trim();
		args = expr.match(varExpr);
		if (args) {
			fieldName = args[1];
			thymol.objects.thIdsObject.seq(fieldName);
		}
	}
	var name = element.nodeName.toLowerCase();
	if (name === "input") {
		type = element.getAttributeNode("type");
		if (type) {
			var inputType = type.nodeValue;
			if (inputType === "checkbox") {
				element.setAttribute("name", fieldName);
				element.setAttribute("id", thymol.objects.thIdsObject.prev(fieldName));
				var child = element.ownerDocument.createElement("input");
				child.setAttribute("type", "hidden");
				child.setAttribute("value", "on");
				child.setAttribute("name", "_" + fieldName);
				element.appendChild(child);
				domUpdated = true;
			}
			else if (inputType === "text") {
				exprValue = thymol.getExpression(expr, element) || "";
				element.setAttribute("value", exprValue);
				element.setAttribute("name", fieldName);
				element.setAttribute("id", fieldName);
			}
		}
	}
	else if (name === "select") {
		element.setAttribute("name", fieldName);
		element.setAttribute("id", fieldName);
	}
	element.removeAttribute(attr.name);
	return domUpdated;
}


text:
import numpy
import sys

from mmdlab.readers.backup_data_reader import BackupDataReader
from mmdlab.readers import transport
from mmdlab.filters import RegionFilter

from mmdlab.utils import init_mlab_scene
from mmdlab.utils import showable
from mmdlab.utils import saveimg

from mmdlab.utils import offscreen

from mayavi import mlab

elements_description = \
{ "Nickel" : { "id" : 0, "atom_mass" : 97.474, "atom_d" : 0.248},
  "Nitrogen" : { "id" : 1, "atom_mass" : 46.517, "atom_d" : 0.296} }

def read(f):

	reader = BackupDataReader(elements_description)

	elements = reader.read(transport.ssh_backup_dir(f,490000))

	m = elements["Nickel"]
	g = elements["Nitrogen"]

	f = RegionFilter([0,10,0,10,0,30])
	return f(m),f(g)

#@saveimg("lol.png")
#@offscreen()
@showable
def draw():

	m,g = read(sys.argv[1])
	init_mlab_scene((1024,768))
	print "Drawing Nickel"
	mlab.points3d(m.x, m.y, m.z, m.t, mode="point", scale_mode="none",scale_factor=m.d, colormap="black-white")
	print "Drawing Nitrogenium"
	mlab.points3d(g.x, g.y, g.z, g.t, mode="point", scale_mode="none",scale_factor=g.d, colormap="cool")
	mlab.outline()

draw()


text:
import boto
import csv
import logging
import os
import re
import sys
import transaction
import zipfile
from datetime import date, datetime, timedelta
from dateutil.relativedelta import relativedelta

from sqlalchemy import engine_from_config
from sqlalchemy.sql import functions

from pyramid.paster import (get_appsettings,
                            setup_logging)

from pyramid.scripts.common import parse_vars

from ..models import (DBSession,
                      AwsDetailedLineItem,
                      AwsInvoiceLineItem,
                      AwsCostAllocation,
                      Base)

from ..util.fileloader import load_json, save_json

s3_bucket_name = 'primary_billing_bucket'
checksum_filename = 'checksums.json'

# How many records to commit in a single transaction.
COMMIT_THRESHOLD = 10000

# connect to AWS
# look up S3 Bucket
# list files
# get ETags / md5 checksums
# compare etags / checksums with file cache
# download new/changed files
# unzip detailed-billing-with-tags CSV
# process each CSV line
# insert into aws_detailed_line_item table
# TODO: insert invoice totals lines into aws_invoice_line_item table

def get_s3_bucket():
    log.debug("Connecting to S3...")
    try:
        access_key = os.environ['AWS_ACCESS_KEY_ID']
        secret_key = os.environ['AWS_SECRET_ACCESS_KEY']
    except KeyError:
        log.error("No Access Key or Secret Key found. Is your environment set up?")
        return None
    conn = boto.connect_s3(access_key, secret_key)
    log.debug("Fetching bucket...")
    return conn.get_bucket(s3_bucket_name)

def prune_logs(bucket):
    for key in bucket.list():
        if re.search('logs\/', key.name):
            today = (date.today() - relativedelta(months=1)).strftime('%Y-%m-%d')
            if key.name[5:15] < date.today().strftime('%Y-%m-%d'):
                log.debug('Deleting %s' % key.name)
                key.delete()

def retrieve_files(bucket):
    chksum_file = load_json(checksum_filename)

    keys = bucket.list()
    for key in bucket.list():
        if re.search('logs\/', key.name):
            continue

        #check etags/md5
        if key.name in chksum_file.keys() and key.etag == chksum_file[key.name]:
            continue
        else:
            log.info("checksums do not match. retrieving %s from s3..." % key.name)
            chksum_file[key.name] = key.etag

            try:
                key.get_contents_to_filename(cache_dir+'/'+key.name)
            except Exception as exc:
                log.error(key.name+": "+exc.message)
    save_json(checksum_filename, chksum_file)

def load_detailed_line_items(begin=datetime(2000,01,01)):
    lastdate, = DBSession.query(
                functions.max(AwsDetailedLineItem.usage_end_date)
            ).one()

    for fn in os.listdir(cache_dir):
        match = re.search('aws-billing-detailed-line-items-with-resources-and-tags-(\d{4})-(\d{2}).csv.zip', fn)
        if match:
            year, month = match.groups()
            filedate = datetime(int(year), int(month), 1)

            if filedate.month == datetime.today().month:
                # Skip the current month until we figure out how to deal with
                # resuming loading data later.
                continue

            if filedate > begin and (lastdate is None or filedate > lastdate):
                log.debug("newer data found: %s" % filedate)
                import_detailed_line_items(fn, filedate)

def load_cost_allocation(begin=datetime(2000,01,01)):
    lastdate, = DBSession.query(
                functions.max(AwsCostAllocation.billing_period_end_date)
            ).one()

    for fn in os.listdir(cache_dir):
        match = re.search('aws-cost-allocation-(\d{4})-(\d{2}).csv', fn)
        if match:
            year, month = match.groups()
            filedate = datetime(int(year), int(month), 1)

            if filedate.month == datetime.today().month:
                # Skip the current month until we figure out how to deal with
                # resuming loading data later.
                continue

            if filedate > begin and (lastdate is None or filedate > lastdate):
                log.debug("newer data found: %s" % filedate)
                import_cost_allocation(fn, filedate)

# Detailed Line Items w/ resources & tags
# "InvoiceID","PayerAccountId","LinkedAccountId","RecordType","RecordId","ProductName","RateId","SubscriptionId","PricingPlanId","UsageType","Operation","AvailabilityZone","ReservedInstance","ItemDescription","UsageStartDate","UsageEndDate","UsageQuantity","BlendedRate","BlendedCost","UnBlendedRate","UnBlendedCost","ResourceId"

def import_detailed_line_items(zipfilename, filedate):
    objects = []

    zfile = zipfile.ZipFile(cache_dir+'/'+zipfilename, 'r')
    zinfo, = zfile.infolist()
    with zfile.open(zinfo) as zf:
        csvfile = csv.reader(zf)
        csvfile.next() # pop the header

        # todo - figure out how to deal with incomplete month data.
        #
        # there's a running monthly total for each account that needs to be deleted/updated
        #
        # we need to store/cache the timestamp of the last lineitem we see
        # and/or develop a query to suss it out of the database on start-up
        for row in csvfile:
            if len(objects) > COMMIT_THRESHOLD:
                log.debug("bulk saving...")
                DBSession.add_all(objects)
                transaction.commit()
                del objects[:]

            line_item = AwsDetailedLineItem(
                invoice_id        = row[0],
                payer_account_id  = row[1],
                linked_account_id = row[2],
                record_type       = row[3],
                record_id         = row[4],
                product_name      = row[5],
                rate_id           = row[6],
                subscription_id   = row[7],
                pricing_plan_id   = row[8],
                usage_type        = row[9],
                operation         = row[10],
                availability_zone = row[11],
                reserved_instance = True if row[12] == 'Y' else False,
                item_description  = row[13],
                usage_start_date  = process_date(row[14], filedate),
                usage_end_date    = process_date(row[15], filedate),
                usage_quantity    = row[16],
                blended_rate      = row[17],
                blended_cost      = row[18],
                unblended_rate    = row[19],
                unblended_cost    = row[20],
                resource_id       = row[21],
            )
            if len(row) == 23:
                line_item.user_environment  = row[22]
            if len(row) == 24:
                line_item.user_node         = row[23]

            if row[3] in [ 'InvoiceTotal', 'AccountTotal', 'StatementTotal']:
                DBSession.add(AwsInvoiceLineItem (
                    invoice_id        = row[0],
                    payer_account_id  = row[1],
                    linked_account_id = row[2],
                    record_type       = row[3],
                    record_id         = row[4],
                    product_name      = row[5],
                    rate_id           = row[6],
                    subscription_id   = row[7],
                    pricing_plan_id   = row[8],
                    usage_type        = row[9],
                    operation         = row[10],
                    availability_zone = row[11],
                    reserved_instance = True if row[12] == 'Y' else False,
                    item_description  = row[13],
                    usage_start_date  = process_date(row[14], filedate),
                    usage_end_date    = process_date(row[15], filedate),
                    usage_quantity    = row[16],
                    blended_rate      = row[17],
                    blended_cost      = row[18],
                    unblended_rate    = row[19],
                    unblended_cost    = row[20],
                    resource_id       = row[21],
                ))
                transaction.commit()
            objects.append(line_item)
        log.debug("saving...")
        DBSession.add_all(objects)
        transaction.commit()

# Cost Allocation
# "InvoiceID","PayerAccountId","LinkedAccountId","RecordType","RecordID","BillingPeriodStartDate","BillingPeriodEndDate","InvoiceDate","PayerAccountName","LinkedAccountName","TaxationAddress","PayerPONumber","ProductCode","ProductName","SellerOfRecord","UsageType","Operation","AvailabilityZone","RateId","ItemDescription","UsageStartDate","UsageEndDate","UsageQuantity","BlendedRate","CurrencyCode","CostBeforeTax","Credits","TaxAmount","TaxType","TotalCost","user:environment","user:node"

def import_cost_allocation(filename, filedate):
    objects = []

    with open(cache_dir+'/'+filename, 'r') as f:
        csvfile = csv.reader(f)
        csvfile.next() # pop the header
        csvfile.next() # pop the header

        # todo - figure out how to deal with incomplete month data.
        #
        # there's a running monthly total for each account that needs to be deleted/updated
        #
        # we need to store/cache the timestamp of the last lineitem we see
        # and/or develop a query to suss it out of the database on start-up
        for row in csvfile:
            if len(objects) > COMMIT_THRESHOLD:
                log.debug("bulk saving...")
                DBSession.add_all(objects)
                transaction.commit()
                del objects[:]

            line_item = AwsCostAllocation(
                invoice_id                = row[0],
                payer_account_id          = row[1],
                linked_account_id         = row[2],
                record_type               = row[3],
                record_id                 = row[4],
                billing_period_start_date = process_date(row[5], filedate),
                billing_period_end_date   = process_date(row[6], filedate),
                invoice_date              = process_date(row[7], filedate),
                payer_account_name        = row[8],
                linked_account_name       = row[9],
                taxation_address          = row[10],
                payer_po_number           = row[11],
                product_code              = row[12],
                product_name              = row[13],
                seller_of_record          = row[14],
                usage_type                = row[15],
                operation                 = row[16],
                availability_zone         = row[17],
                rate_id                   = row[18],
                item_description          = row[19],
                usage_start_date          = process_date(row[20], filedate),
                usage_end_date            = process_date(row[21], filedate),
                usage_quantity            = row[22],
                blended_rate              = row[23],
                currency_code             = row[24],
                cost_before_tax           = row[25],
                credits                   = row[26],
                tax_amount                = row[27],
                tax_type                  = row[28],
                total_cost                = row[29],
            )
            if len(row) == 31:
                line_item.user_environment  = row[30]
            if len(row) == 32:
                line_item.user_node         = row[31]

            objects.append(line_item)
        log.debug("saving...")
        DBSession.add_all(objects)
        transaction.commit()

def process_date(datestr, default=datetime(1970,01,01,0,0,0)):
    if datestr:
        if re.match('-', datestr):
            return datetime.strptime(datestr, "%Y-%m-%d %H:%M:%S")
        elif re.match('/', datestr):
            return datetime.strptime(datestr, "%Y/%m/%d %H:%M:%S")

    return default

def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> [var=value]\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)

def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)

    config_uri = argv[1]
    options = parse_vars(argv[2:])

    setup_logging(config_uri)
    global log
    log = logging.getLogger(__name__)

    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    global cache_dir
    cache_dir = settings['cache.dir'] + "/aws"

    bucket = get_s3_bucket()
    if bucket:
        prune_logs(bucket)
        retrieve_files(bucket)

    # only import the last 6 months of data, maximum.
    min_import_date = datetime.today() - relativedelta(months=7)
    log.debug(min_import_date)
    load_detailed_line_items(min_import_date)
    log.debug("Done with detailed line items")
    load_cost_allocation(min_import_date)
    log.debug("Done with cost allocation")

if '__main__' in __name__:
    try:
        main()
    except KeyboardInterrupt:
        print "Ctrl+C detected. Exiting..."


text:
package org.camelcookbook.transactions.rollback;

import org.apache.camel.builder.RouteBuilder;

/**
 * Demonstrates the use of the markRollbackOnly statement roll back the transaction without throwing a transaction.
 */
public class RollbackMarkRollbackOnlyRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("direct:transacted")
            .transacted()
            .log("Processing message: ${body}")
            .setHeader("message", body())
            .to("sql:insert into audit_log (message) values (:#message)")
            .choice()
                .when(simple("${body} contains 'explode'"))
                    .log("Message cannot be processed further - rolling back insert")
                    .markRollbackOnly()
                .otherwise()
                    .log("Message processed successfully")
            .end()
            .to("mock:out");
    }
}


text:
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;

namespace PholioVisualisation.ServicesWeb.Helpers
{
    public interface IFileResponseBuilder
    {
        HttpResponseMessage Message { get; }

        void SetFileContent(byte[] content);

        void SetFilename(string file_name);
    }

    public class FileResponseBuilder : IFileResponseBuilder
    {
        private HttpResponseMessage _message;

        public HttpResponseMessage Message
        {
            get { return _message; }
        }

        public FileResponseBuilder()
        {
            _message = new HttpResponseMessage(HttpStatusCode.OK);
        }

        public void SetFileContent(byte[] content)
        {
            _message.Content = new ByteArrayContent(content);
            _message.Content.Headers.ContentType =
                new MediaTypeHeaderValue("application/octet-stream");
        }

        public void SetFilename(string file_name)
        {
            _message.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = file_name
            };
        }

        public static HttpResponseMessage NewMessage(byte[] bytes, string filename)
        {
            var responseBuilder = new FileResponseBuilder();
            responseBuilder.SetFileContent(bytes);
            responseBuilder.SetFilename(filename);
            return responseBuilder.Message;
        }
    }
}


text:
local MetaSchema = require "kong.db.schema.metaschema"
local socket_url = require "socket.url"
local typedefs = require "kong.db.schema.typedefs"
local Entity = require "kong.db.schema.entity"
local utils = require "kong.tools.utils"

local plugin_loader = {}

local fmt = string.format
local next = next
local type = type
local insert = table.insert
local ipairs = ipairs

--- Check if a string is a parseable URL.
-- @param v input string string
-- @return boolean indicating whether string is an URL.
local function validate_url(v)
  if v and type(v) == "string" then
    local url = socket_url.parse(v)
    if url and not url.path then
      url.path = "/"
    end
    return not not (url and url.path and url.host and url.scheme)
  end
end

--- Read a plugin schema table in the old-DAO format and produce a
-- best-effort translation of it into a plugin subschema in the new-DAO format.
-- @param name a string with the schema name.
-- @param old_schema the old-format schema table.
-- @return a table with a new-format plugin subschema; or nil and a message.
local function convert_legacy_schema(name, old_schema)
  local new_schema = {
    name = name,
    fields = {
      { config = {
        type = "record",
        required = true,
        fields = {}
      }}
    },
    entity_checks = old_schema.entity_checks,
  }

  for old_fname, old_fdata in pairs(old_schema.fields) do
    local new_fdata = {}
    local new_field = { [old_fname] = new_fdata }
    local elements = {}
    for k, v in pairs(old_fdata) do

      if k == "type" then
        if v == "url" then
          new_fdata.type = "string"
          new_fdata.custom_validator = validate_url

        elseif v == "table" then
          if old_fdata.schema and old_fdata.schema.flexible then
            new_fdata.type = "map"
          else
            new_fdata.type = "record"
            new_fdata.required = true
          end

        elseif v == "array" then
          new_fdata.type = "array"
          elements.type = "string"
          -- FIXME stored as JSON in old db

        elseif v == "timestamp" then
          new_fdata = typedefs.timestamp

        elseif v == "string" then
          new_fdata.type = v
          new_fdata.len_min = 0

        elseif v == "number"
            or v == "boolean" then
          new_fdata.type = v

        else
          return nil, "unkown legacy field type: " .. v
        end

      elseif k == "schema" then
        local rfields, err = convert_legacy_schema("fields", v)
        if err then
          return nil, err
        end
        rfields = rfields.fields[1].config.fields

        if v.flexible then
          new_fdata.keys = { type = "string" }
          new_fdata.values = {
            type = "record",
            required = true,
            fields = rfields,
          }
        else
          new_fdata.fields = rfields
          local rdefault = {}
          local has_default = false
          for _, field in ipairs(rfields) do
            local fname = next(field)
            local fdata = field[fname]
            if fdata.default then
              rdefault[fname] = fdata.default
              has_default = true
            end
          end
          if has_default then
            new_fdata.default = rdefault
          end
        end

      elseif k == "immutable" then
        -- FIXME really ignore?
        kong.log.debug("ignoring 'immutable' property")

      elseif k == "enum" then
        if old_fdata.type == "array" then
          elements.one_of = v
        else
          new_fdata.one_of = v
        end

      elseif k == "default"
          or k == "required"
          or k == "unique" then
        new_fdata[k] = v

      elseif k == "func" then
        -- FIXME some should become custom validators, some entity checks
        new_fdata.custom_validator = nil -- v

      elseif k == "new_type" then
        new_field[old_fname] = v
        break

      else
        return nil, "unknown legacy field attribute: " .. require"inspect"(k)
      end

    end
    if new_fdata.type == "array" then
      new_fdata.elements = elements
    end

    if (new_fdata.type == "map" and new_fdata.keys == nil)
       or (new_fdata.type == "record" and new_fdata.fields == nil) then
      new_fdata.type = "map"
      new_fdata.keys = { type = "string" }
      new_fdata.values = { type = "string" }
    end

    if new_fdata.type == nil then
      new_fdata.type = "string"
    end

    insert(new_schema.fields[1].config.fields, new_field)
  end

  if old_schema.no_route then
    insert(new_schema.fields, { route = typedefs.no_route })
  end
  if old_schema.no_service then
    insert(new_schema.fields, { service = typedefs.no_service })
  end
  if old_schema.no_consumer then
    insert(new_schema.fields, { consumer = typedefs.no_consumer })
  end
  return new_schema
end

function plugin_loader.load_subschema(parent_schema, plugin, errors)
  local plugin_schema = "kong.plugins." .. plugin .. ".schema"
  local ok, schema = utils.load_module_if_exists(plugin_schema)
  if not ok then
    return nil, "no configuration schema found for plugin: " .. plugin
  end

  local err
  local is_legacy = false
  if not schema.name then
    is_legacy = true
    schema, err = convert_legacy_schema(plugin, schema)
  end

  if not err then
    local err_t
    ok, err_t = MetaSchema.MetaSubSchema:validate(schema)
    if not ok then
      err = tostring(errors:schema_violation(err_t))
    end
  end

  if err then
    if is_legacy then
      err = "failed converting legacy schema for " .. plugin .. ": " .. err
    end
    return nil, err
  end

  ok, err = Entity.new_subschema(parent_schema, plugin, schema)
  if not ok then
    return nil, "error initializing schema for plugin: " .. err
  end

  return schema
end

function plugin_loader.load_entity_schema(plugin, schema_def, errors)
  local _, err_t = MetaSchema:validate(schema_def)
  if err_t then
    return nil, fmt("schema of custom plugin entity '%s.%s' is invalid: %s",
      plugin, schema_def.name, tostring(errors:schema_violation(err_t)))
  end

  local schema, err = Entity.new(schema_def)
  if err then
    return nil, fmt("schema of custom plugin entity '%s.%s' is invalid: %s",
                    plugin, schema_def.name, err)
  end

  return schema
end

function plugin_loader.load_entities(plugin, errors, loader_fn)
  local has_daos, daos_schemas = utils.load_module_if_exists("kong.plugins." .. plugin .. ".daos")
  if not has_daos then
    return {}
  end
  local iterator = daos_schemas[1] and ipairs or pairs
  local res = {}
  for name, schema_def in iterator(daos_schemas) do
    if name ~= "tables" and schema_def.name then
      local ret, err = loader_fn(plugin, schema_def, errors)
      if err then
        return nil, err
      end
      res[schema_def.name] = ret
    end
  end

  return res
end

return plugin_loader


text:
package org.apache.samza.clustermanager;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadataStore;
import org.apache.samza.config.Config;
import org.apache.samza.config.MapConfig;
import org.apache.samza.coordinator.JobModelManager;
import org.apache.samza.coordinator.JobModelManagerTestUtil;
import org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore;
import org.apache.samza.coordinator.metadatastore.CoordinatorStreamStoreTestUtil;
import org.apache.samza.testUtils.MockHttpServer;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletHolder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class TestContainerAllocatorWithoutHostAffinity {
  private final MockClusterResourceManagerCallback callback = new MockClusterResourceManagerCallback();
  private final Config config = getConfig();
  private final JobModelManager jobModelManager = JobModelManagerTestUtil.getJobModelManager(config, 1,
      new MockHttpServer("/", 7777, null, new ServletHolder(DefaultServlet.class)));

  private final SamzaApplicationState state = new SamzaApplicationState(jobModelManager);
  private final MockClusterResourceManager manager = new MockClusterResourceManager(callback, state);

  private CoordinatorStreamStore coordinatorStreamStore;
  private ContainerPlacementMetadataStore containerPlacementMetadataStore;

  private ContainerAllocator containerAllocator;
  private MockContainerRequestState requestState;
  private Thread allocatorThread;

  private Thread spyThread;
  private ContainerAllocator spyAllocator;

  @Before
  public void setup() throws Exception {
    CoordinatorStreamStoreTestUtil coordinatorStreamStoreTestUtil = new CoordinatorStreamStoreTestUtil(config);
    CoordinatorStreamStore coordinatorStreamStore = coordinatorStreamStoreTestUtil.getCoordinatorStreamStore();
    coordinatorStreamStore.init();
    containerPlacementMetadataStore = new ContainerPlacementMetadataStore(coordinatorStreamStore);
    containerPlacementMetadataStore.start();
    containerAllocator = new ContainerAllocator(manager, config, state, false,
        new ContainerManager(containerPlacementMetadataStore, state, manager, false, false));
    requestState = new MockContainerRequestState(manager, false);
    Field requestStateField = containerAllocator.getClass().getDeclaredField("resourceRequestState");
    requestStateField.setAccessible(true);
    requestStateField.set(containerAllocator, requestState);
    allocatorThread = new Thread(containerAllocator);
  }

  @After
  public void teardown() throws Exception {
    jobModelManager.stop();
    validateMockitoUsage();
  }

  private static Config getConfig() {
    Config config = new MapConfig(new HashMap<String, String>() {
      {
        put("cluster-manager.container.count", "1");
        put("cluster-manager.container.retry.count", "1");
        put("cluster-manager.container.retry.window.ms", "1999999999");
        put("cluster-manager.allocator.sleep.ms", "10");
        put("cluster-manager.container.memory.mb", "512");
        put("yarn.package.path", "/foo");
        put("task.inputs", "test-system.test-stream");
        put("systems.test-system.samza.factory", "org.apache.samza.system.MockSystemFactory");
        put("systems.test-system.samza.key.serde", "org.apache.samza.serializers.JsonSerde");
        put("systems.test-system.samza.msg.serde", "org.apache.samza.serializers.JsonSerde");
        put("job.name", "test-job");
        put("job.coordinator.system", "test-kafka");
      }
    });

    Map<String, String> map = new HashMap<>();
    map.putAll(config);
    return new MapConfig(map);
  }

  /**
   * Adds all containers returned to ANY_HOST only
   */
  @Test
  public void testAddContainer() throws Exception {
    assertNull(requestState.getResourcesOnAHost("abc"));
    assertNull(requestState.getResourcesOnAHost(ResourceRequestState.ANY_HOST));

    containerAllocator.addResource(new SamzaResource(1, 1000, "abc", "id1"));
    containerAllocator.addResource(new SamzaResource(1, 1000, "xyz", "id1"));

    assertNull(requestState.getResourcesOnAHost("abc"));
    assertNotNull(requestState.getResourcesOnAHost(ResourceRequestState.ANY_HOST));
    assertTrue(requestState.getResourcesOnAHost(ResourceRequestState.ANY_HOST).size() == 2);
  }

  /**
   * Test requestContainers
   */
  @Test
  public void testRequestContainers() throws Exception {
    Map<String, String> containersToHostMapping = new HashMap<String, String>() {
      {
        put("0", null);
        put("1", null);
        put("2", null);
        put("3", null);
      }
    };

    allocatorThread.start();

    containerAllocator.requestResources(containersToHostMapping);

    assertEquals(4, manager.resourceRequests.size());

    assertNotNull(requestState);

    assertEquals(requestState.numPendingRequests(), 4);

    // If host-affinty is not enabled, it doesn't update the requestMap
    assertNotNull(requestState.getHostRequestCounts());
    assertEquals(requestState.getHostRequestCounts().keySet().size(), 0);
  }

  /**
   * Test requestContainers with containerToHostMapping with host.affinity disabled
   */
  @Test
  public void testRequestContainersWithExistingHosts() throws Exception {
    Map<String, String> containersToHostMapping = new HashMap<String, String>() {
      {
        put("0", "prev_host");
        put("1", "prev_host");
        put("2", "prev_host");
        put("3", "prev_host");
      }
    };

    allocatorThread.start();

    containerAllocator.requestResources(containersToHostMapping);

    assertEquals(4, manager.resourceRequests.size());

    assertNotNull(requestState);

    assertEquals(4, requestState.numPendingRequests());
    assertEquals(0, requestState.numDelayedRequests());

    // If host-affinty is not enabled, it doesn't update the requestMap
    assertNotNull(requestState.getHostRequestCounts());
    assertEquals(0, requestState.getHostRequestCounts().keySet().size());

    assertNotNull(state);
    assertEquals(4, state.anyHostRequests.get());
    assertEquals(0, state.preferredHostRequests.get());
  }

  /**
   * Test request containers with no containerToHostMapping makes the right number of requests
   */
  @Test
  public void testRequestContainersWithNoMapping() throws Exception {
    int containerCount = 4;
    Map<String, String> containersToHostMapping = new HashMap<String, String>();
    for (int i = 0; i < containerCount; i++) {
      containersToHostMapping.put(String.valueOf(i), null);
    }
    allocatorThread.start();

    containerAllocator.requestResources(containersToHostMapping);

    assertNotNull(requestState);

    assertEquals(4, requestState.numPendingRequests());
    assertEquals(0, requestState.numDelayedRequests());

    // If host-affinty is not enabled, it doesn't update the requestMap
    assertNotNull(requestState.getHostRequestCounts());
    assertEquals(0, requestState.getHostRequestCounts().keySet().size());
  }

  /**
   * Extra allocated containers that are returned by the RM and unused by the AM should be released.
   * Containers are considered "extra" only when there are no more pending requests to fulfill
   * @throws Exception
   */
  @Test
  public void testAllocatorReleasesExtraContainers() throws Exception {
    final SamzaResource resource = new SamzaResource(1, 1000, "abc", "id1");
    final SamzaResource resource1 = new SamzaResource(1, 1000, "abc", "id2");
    final SamzaResource resource2 = new SamzaResource(1, 1000, "def", "id3");

    // Set up our final asserts before starting the allocator thread
    MockContainerListener listener = new MockContainerListener(3, 2, 0, 0, null, new Runnable() {
      @Override
      public void run() {

        assertTrue(manager.releasedResources.contains(resource1));
        assertTrue(manager.releasedResources.contains(resource2));

        // Test that state is cleaned up
        assertEquals(0, requestState.numPendingRequests());
        assertEquals(0, requestState.numDelayedRequests());
        assertEquals(0, requestState.getHostRequestCounts().size());
        assertNull(requestState.getResourcesOnAHost("abc"));
        assertNull(requestState.getResourcesOnAHost("def"));
      }
    }, null, null);
    requestState.registerContainerListener(listener);

    allocatorThread.start();

    containerAllocator.requestResource("0", "abc");

    containerAllocator.addResource(resource);
    containerAllocator.addResource(resource1);
    containerAllocator.addResource(resource2);

    listener.verify();
  }

  /**
   * Test the complete flow from container request creation to allocation when host affinity is disabled
   */
  @Test
  public void testRequestAllocationWithRunStreamProcessor() throws Exception {
    Map<String, String> containersToHostMapping = new HashMap<String, String>() {
      {
        put("0", "prev_host");
        put("1", "prev_host");
        put("2", "prev_host");
        put("3", "prev_host");
      }
    };

    ClusterResourceManager.Callback mockCPM = mock(ClusterResourceManager.Callback.class);
    ClusterResourceManager mockManager = new MockClusterResourceManager(mockCPM, state);
    ContainerManager spyContainerManager =
        spy(new ContainerManager(containerPlacementMetadataStore, state, mockManager, false, false));
    spyAllocator = Mockito.spy(
        new ContainerAllocator(mockManager, config, state, false, spyContainerManager));
    // Mock the callback from ClusterManager to add resources to the allocator
    doAnswer((InvocationOnMock invocation) -> {
        SamzaResource resource = (SamzaResource) invocation.getArgumentAt(0, List.class).get(0);
        spyAllocator.addResource(resource);
        return null;
      }).when(mockCPM).onResourcesAvailable(anyList());
    // Request Resources
    spyAllocator.requestResources(containersToHostMapping);
    spyThread = new Thread(spyAllocator, "Container Allocator Thread");
    // Start the container allocator thread periodic assignment
    spyThread.start();
    Thread.sleep(1000);
    // Verify that all the request that were created were "ANY_HOST" requests
    ArgumentCaptor<SamzaResourceRequest> resourceRequestCaptor = ArgumentCaptor.forClass(SamzaResourceRequest.class);
    verify(spyAllocator, times(4)).runStreamProcessor(resourceRequestCaptor.capture(), anyString());
    resourceRequestCaptor.getAllValues()
        .forEach(resourceRequest -> assertEquals(resourceRequest.getPreferredHost(), ResourceRequestState.ANY_HOST));
    assertTrue(state.anyHostRequests.get() == containersToHostMapping.size());
    // Expiry currently should not be invoked for host affinity enabled cases only
    verify(spyContainerManager, never()).handleExpiredRequest(anyString(), anyString(),
        any(SamzaResourceRequest.class), any(ContainerAllocator.class), any(ResourceRequestState.class));
    // Only updated when host affinity is enabled
    assertTrue(state.matchedResourceRequests.get() == 0);
    assertTrue(state.preferredHostRequests.get() == 0);
    spyAllocator.stop();
  }
}


text:
using Microsoft.Azure.EventHubs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Orleans.ServiceBus.Providers
{
    /// <summary>
    /// Abstraction on EventhubReceiver class, used to configure EventHubReceiver class in EventhubAdapterReceiver,
    /// also used to configure EHGeneratorReceiver in EventHubAdapterReceiver for testing purpose
    /// </summary>
    public interface IEventHubReceiver
    {
        /// <summary>
        /// Send an async message to the partition asking for more messages
        /// </summary>
        /// <param name="maxCount">Max amount of message which should be delivered in this request</param>
        /// <param name="waitTime">Wait time of this request</param>
        /// <returns></returns>
        Task<IEnumerable<EventData>> ReceiveAsync(int maxCount, TimeSpan waitTime);

        /// <summary>
        /// Send a clean up message
        /// </summary>
        /// <returns></returns>
        Task CloseAsync();
    }

    /// <summary>
    /// pass through decorator class for EventHubReceiver
    /// </summary>
    internal class EventHubReceiverProxy: IEventHubReceiver
    {
        private PartitionReceiver receiver;

        public EventHubReceiverProxy(PartitionReceiver receiver)
        {
            this.receiver = receiver;
        }

        public Task<IEnumerable<EventData>> ReceiveAsync(int maxCount, TimeSpan waitTime)
        {
            return this.receiver.ReceiveAsync(maxCount, waitTime);
        }

        public Task CloseAsync()
        {
            return this.receiver.CloseAsync();
        }
    }
}


text:
import { BasePlugin } from '../base'
import mdcTextField from './mdc-textfield.vue'

export { mdcTextField }

export default BasePlugin({
  mdcTextField
})


text:
/*
 * Minio Cloud Storage, (C) 2017 Minio, Inc.
 *
 * 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 oss

import (
	"context"
	"fmt"
	"net/http"
	"reflect"
	"testing"

	"github.com/aliyun/aliyun-oss-go-sdk/oss"

	minio "github.com/minio/minio/cmd"
)

func ossErrResponse(code string) error {
	return oss.ServiceError{
		Code: code,
	}
}

func TestOSSToObjectError(t *testing.T) {
	testCases := []struct {
		inputErr       error
		expectedErr    error
		bucket, object string
	}{
		{
			inputErr:    ossErrResponse("BucketAlreadyExists"),
			expectedErr: minio.BucketAlreadyOwnedByYou{},
		},
		{
			inputErr:    ossErrResponse("BucketNotEmpty"),
			expectedErr: minio.BucketNotEmpty{},
		},
		{
			inputErr:    ossErrResponse("InvalidBucketName"),
			expectedErr: minio.BucketNameInvalid{},
		},
		{
			inputErr:    ossErrResponse("NoSuchBucket"),
			expectedErr: minio.BucketNotFound{},
		},
		// with empty object, NoSuchKey is interpreted as BucketNotFound
		{
			inputErr:    ossErrResponse("NoSuchKey"),
			expectedErr: minio.BucketNotFound{},
		},
		{
			inputErr:    ossErrResponse("NoSuchUpload"),
			expectedErr: minio.InvalidUploadID{},
		},
		{
			inputErr:    ossErrResponse("InvalidObjectName"),
			expectedErr: minio.ObjectNameInvalid{},
		},
		{
			inputErr:    ossErrResponse("AccessDenied"),
			expectedErr: minio.PrefixAccessDenied{},
		},
		{
			inputErr:    ossErrResponse("NoSuchUpload"),
			expectedErr: minio.InvalidUploadID{},
		},
		{
			inputErr:    ossErrResponse("EntityTooSmall"),
			expectedErr: minio.PartTooSmall{},
		},
		{
			inputErr:    nil,
			expectedErr: nil,
		},
		// Special test case for NoSuchKey with object name
		{
			inputErr:    ossErrResponse("NoSuchKey"),
			expectedErr: minio.ObjectNotFound{Bucket: "bucket", Object: "object"},
			bucket:      "bucket",
			object:      "object",
		},

		// Special test case for error value that is not of
		// type (*Error)
		{
			inputErr:    fmt.Errorf("not a *Error"),
			expectedErr: fmt.Errorf("not a *Error"),
		},
	}

	for i, tc := range testCases {
		actualErr := ossToObjectError(tc.inputErr, tc.bucket, tc.object)
		if actualErr != nil && tc.expectedErr != nil && actualErr.Error() != tc.expectedErr.Error() {
			t.Errorf("Test case %d: Expected error '%v' but received error '%v'", i+1, tc.expectedErr, actualErr)
		}
	}
}

func TestS3MetaToOSSOptions(t *testing.T) {
	var err error
	var headers map[string]string

	headers = map[string]string{
		"x-amz-meta-invalid_meta": "value",
	}
	_, err = appendS3MetaToOSSOptions(context.Background(), nil, headers)
	if err != nil {
		if _, ok := err.(minio.UnsupportedMetadata); !ok {
			t.Fatalf("Test failed with unexpected error %s, expected UnsupportedMetadata", err)
		}
	}

	headers = map[string]string{
		"accept-encoding":          "gzip", // not this
		"content-encoding":         "gzip",
		"X-Amz-Meta-Hdr":           "value",
		"X-Amz-Meta-X-test-key":    "value",
		"X-Amz-Meta-X--test--key":  "value",
		"X-Amz-Meta-X-Amz-Key":     "hu3ZSqtqwn+aL4V2VhAeov4i+bG3KyCtRMSXQFRHXOk=",
		"X-Amz-Meta-X-Amz-Matdesc": "{}",
		"X-Amz-Meta-X-Amz-Iv":      "eWmyryl8kq+EVnnsE7jpOg==",
	}
	opts, err := appendS3MetaToOSSOptions(context.Background(), nil, headers)
	if err != nil {
		t.Fatalf("Test failed, with %s", err)
	}
	if len(opts) != len(headers) {
		t.Fatalf("Test failed, S3 metdata is not fully transformed. expeted: %d, actual: %d", len(headers)-1, len(opts))
	}
}

func TestOSSHeaderToS3Meta(t *testing.T) {
	meta := map[string]string{
		"x-oss-meta-first_name":       "myname",
		"X-OSS-Meta-x_test_key":       "value",
		"X-Oss-Meta-x_test__key":      "value",
		"X-Oss-Meta-x__test__key":     "value",
		"X-Oss-Meta-x____test____key": "value",
		"X-Oss-Meta-x_amz_key":        "hu3ZSqtqwn+aL4V2VhAeov4i+bG3KyCtRMSXQFRHXOk=",
		"X-Oss-Meta-x_amz_matdesc":    "{}",
		"x-oss-meta-x_amz_iv":         "eWmyryl8kq+EVnnsE7jpOg==",
	}
	header := make(http.Header)
	for k, v := range meta {
		header.Set(k, v)
	}

	expectedMeta := map[string]string{
		"X-Amz-Meta-First-Name":    "myname",
		"X-Amz-Meta-X-Test-Key":    "value",
		"X-Amz-Meta-X-Test_key":    "value",
		"X-Amz-Meta-X_test_key":    "value",
		"X-Amz-Meta-X__test__key":  "value",
		"X-Amz-Meta-X-Amz-Key":     "hu3ZSqtqwn+aL4V2VhAeov4i+bG3KyCtRMSXQFRHXOk=",
		"X-Amz-Meta-X-Amz-Matdesc": "{}",
		"X-Amz-Meta-X-Amz-Iv":      "eWmyryl8kq+EVnnsE7jpOg==",
	}
	actualMeta := ossHeaderToS3Meta(header)
	for k, v := range expectedMeta {
		if v2, ok := actualMeta[k]; !ok {
			t.Errorf("Test failed for key %s: missing key", k)
		} else if v != v2 {
			t.Errorf("Test failed for key %s, expected '%s', got '%s'", k, v, v2)
		}
	}
}

func TestOSSBuildListObjectPartsParams(t *testing.T) {
	expected := map[string]interface{}{
		"uploadId":           "test",
		"part-number-marker": "123",
		"max-parts":          "456",
	}
	actual := ossBuildListObjectPartsParams("test", 123, 456)
	if !reflect.DeepEqual(expected, actual) {
		t.Fatalf("Test failed, expected %v, got %v", expected, actual)
	}
}


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

<title>McElieceCCA2Parameters (Bouncy Castle Library 1.54 API Specification)</title>
<meta name="date" content="2015-12-29">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Overview

Package

Class

Tree

Deprecated

Index

Help

Bouncy Castle Cryptography Library 1.54

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

org.bouncycastle.pqc.crypto.mceliece

Class McElieceCCA2Parameters

java.lang.Object

org.bouncycastle.pqc.crypto.mceliece.McElieceParameters

org.bouncycastle.pqc.crypto.mceliece.McElieceCCA2Parameters

All Implemented Interfaces:

CipherParameters

public class McElieceCCA2Parameters
extends McElieceParameters

This class provides a specification for the parameters of the CCA2-secure
 variants of the McEliece PKCS that are used with
 McElieceFujisakiCipher, McElieceKobaraImaiCipher, and
 McEliecePointchevalCipher.

See Also:

McElieceFujisakiCipher,
McElieceKobaraImaiCipher,
McEliecePointchevalCipher

Field Summary

Fields

Modifier and Type
Field and Description

Digest
digest

Fields inherited from class org.bouncycastle.pqc.crypto.mceliece.McElieceParameters

DEFAULT_M, DEFAULT_T

Constructor Summary

Constructors

Constructor and Description

McElieceCCA2Parameters()

Construct the default parameters.

McElieceCCA2Parameters(Digest digest)

McElieceCCA2Parameters(int m,
                      int t)

Method Summary

Methods

Modifier and Type
Method and Description

Digest
getDigest()

Methods inherited from class org.bouncycastle.pqc.crypto.mceliece.McElieceParameters

getFieldPoly, getM, getN, getT

Methods inherited from class java.lang.Object

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

Field Detail

digest

public Digest digest

Constructor Detail

McElieceCCA2Parameters

public McElieceCCA2Parameters()

Construct the default parameters.
 The default message digest is SHA256.

McElieceCCA2Parameters

public McElieceCCA2Parameters(int m,
                      int t)

McElieceCCA2Parameters

public McElieceCCA2Parameters(Digest digest)

Method Detail

getDigest

public Digest getDigest()

Overview

Package

Class

Tree

Deprecated

Index

Help

Bouncy Castle Cryptography Library 1.54

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method


text:
/**
 * Primer Ajax Tabs
 * These are an extension of Bootstraps tab plugin. It allows tabs to ajax load content.
 * It works by setting both the data-target attribute and an href on a tab anchor link.
 */
$(function() {
	$('body').on('shown', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {

		var tab = $(this);

		// if we have a target and an href, then we will honor the target
		// and load the href
		if (typeof $(this).attr('data-target') !== 'undefined' && typeof $(this).attr('href') !== 'undefined') {

			var url = tab.attr('href');
			var tabContainer = $(tab.attr('data-target'));

			//We want to empty the content out, since the old stuff is stale
			//this is a little hack to make sure the height of the container stays the same for the moment
			tabContainer.height(tabContainer.height());
			tabContainer.html('');

			$.loadPage(url, tab.attr('data-target'), function(){
				tabContainer.css('height', '');
			});
		}
	});
});


text:
package de.alpharogroup.lang;

import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;

import java.util.Set;

import org.meanbean.factories.ObjectCreationException;
import org.meanbean.test.BeanTestException;
import org.meanbean.test.BeanTester;
import org.testng.annotations.Test;

/**
 * The unit test class for the class {@link ScanPackageExtensions}.
 *
 * @version 1.0
 * @author Asterios Raptis
 */
public class ScanPackageExtensionsTest
{

	/**
	 * Test method for {@link ScanPackageExtensions#scanClassNames(String, boolean, boolean)}.
	 *
	 * @throws Exception
	 *             is thrown if any error occurs on the execution
	 */
	@Test(enabled = false)
	public void testScanNames() throws Exception
	{
		Set<String> list = ScanPackageExtensions.scanClassNames("de.alpharogroup.lang", false,
			true);
		assertTrue("Result should contain classes from same package.",
			list.contains("de.alpharogroup.lang.PackageExtensionsTest"));
		assertFalse("Result should not contain classes from subpackages.",
			list.contains("de.alpharogroup.lang.sub.SubPackageClass"));

		list = ScanPackageExtensions.scanClassNames("de.alpharogroup.lang", true, true);
		assertTrue("Result should contain classes from subpackages.",
			list.contains("de.alpharogroup.lang.sub.SubPackageClass"));

		list = ScanPackageExtensions.scanClassNames("org.apache.commons.beanutils", false, true);
		assertTrue("Result should contain classes from same package.",
			list.contains("org.apache.commons.beanutils.BeanMap"));
		assertFalse("Result should not contain classes from subpackages.",
			list.contains("org.apache.commons.beanutils.locale.BaseLocaleConverter"));
		assertFalse("Result should not contain classes from subpackages.", list
			.contains("org.apache.commons.beanutils.locale.converters.BigDecimalLocaleConverter"));

		list = ScanPackageExtensions.scanClassNames("org.apache.commons.beanutils.locale", true,
			true);
		assertTrue("Result should contain classes from same package.",
			list.contains("org.apache.commons.beanutils.locale.BaseLocaleConverter"));
		assertTrue("Result should contain classes from subpackages.", list
			.contains("org.apache.commons.beanutils.locale.converters.BigDecimalLocaleConverter"));

		// ......
		list = ScanPackageExtensions.scanClassNames("de.alpharogroup.lang", false, false);
		assertTrue("Result should contain classes from same package.",
			list.contains("PackageExtensionsTest"));
		assertFalse("Result should not contain classes from subpackages.",
			list.contains("SubPackageClass"));

		list = ScanPackageExtensions.scanClassNames("de.alpharogroup.lang", true, false);
		assertTrue("Result should contain classes from subpackages.",
			list.contains("SubPackageClass"));

		list = ScanPackageExtensions.scanClassNames("org.apache.commons.beanutils", false, false);
		assertTrue("Result should contain classes from same package.", list.contains("BeanMap"));
		assertFalse("Result should not contain classes from subpackages.",
			list.contains("BaseLocaleConverter"));
		assertFalse("Result should not contain classes from subpackages.",
			list.contains("BigDecimalLocaleConverter"));

		list = ScanPackageExtensions.scanClassNames("org.apache.commons.beanutils.locale", true,
			false);
		assertTrue("Result should contain classes from same package.",
			list.contains("BaseLocaleConverter"));
		assertTrue("Result should contain classes from subpackages.",
			list.contains("BigDecimalLocaleConverter"));

		list = ScanPackageExtensions.scanClassNames("de.alpharogroup", true, true);
		for (final String string : list)
		{
			System.out.println("<class name=\"" + string + "\"/>");
		}

	}

	/**
	 * Test method for {@link ScanPackageExtensions}
	 */
	@Test(expectedExceptions = { BeanTestException.class, ObjectCreationException.class })
	public void testWithBeanTester()
	{
		final BeanTester beanTester = new BeanTester();
		beanTester.testBean(ScanPackageExtensions.class);
	}

}


text:
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Org\FormaBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

/**
 * Description of PartitionForm
 *
 * @author sio
 */
class PartitionForm extends \Symfony\Component\Form\AbstractType{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('motcle', 'text');
    }

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


text:
"""Meta tests for mappers.

The test checks the output of the swapper to a ground truth DAG (one for each
test/swapper) saved in as a QASM (in `test/python/qasm/`). If they need
to be regenerated, the DAG candidate is compiled and run in a simulator and
the count is checked before being saved. This happens with (in the root
directory):

> python -m  test.python.transpiler.test_mappers regenerate

To make a new swapper pass throw all the common tests, create a new class inside the file
`path/to/test_mappers.py` that:
    * the class name should start with `Tests...`.
    * inheriting from ``SwapperCommonTestCases, QiskitTestCase``
    * overwrite the required attribute ``pass_class``

For example::

    class TestsSomeSwap(SwapperCommonTestCases, QiskitTestCase):
        pass_class = SomeSwap                      # The pass class
        additional_args = {'seed_transpiler': 42}  # In case SomeSwap.__init__ requires
                                                   # additional arguments

To **add a test for all the swappers**, add a new method ``test_foo``to the
``SwapperCommonTestCases`` class:
    * defining the following required ``self`` attributes: ``self.count``,
      ``self.shots``, ``self.delta``. They are required for the regeneration of the
      ground truth.
    * use the ``self.assertResult`` assertion for comparing for regeneration of the
      ground truth.
    * explicitly set a unique ``name`` of the ``QuantumCircuit``, as it it used
      for the name of the QASM file of the ground truth.

For example::

    def test_a_common_test(self):
        self.count = {'000': 512, '110': 512}  # The expected count for this circuit
        self.shots = 1024                      # Shots to run in the backend.
        self.delta = 5                         # This is delta for the AlmostEqual during
                                               # the count check
        coupling_map = [[0, 1], [0, 2]]        # The coupling map for this specific test

        qr = QuantumRegister(3, 'q')               #
        cr = ClassicalRegister(3, 'c')             # Set the circuit to test
        circuit = QuantumCircuit(qr, cr,           # and don't forget to put a name
                                 name='some_name') # (it will be used to save the QASM
        circuit.h(qr[1])                           #
        circuit.cx(qr[1], qr[2])                   #
        circuit.measure(qr, cr)                    #

        result = transpile(circuit, self.create_backend(), coupling_map=coupling_map,
                           pass_manager=self.create_passmanager(coupling_map))
        self.assertResult(result, circuit)
```
"""

# pylint: disable=attribute-defined-outside-init

import unittest
import os
import sys

from qiskit import execute
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit, BasicAer
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import BasicSwap, LookaheadSwap, StochasticSwap, SabreSwap
from qiskit.transpiler.passes import SetLayout
from qiskit.transpiler import CouplingMap, Layout

from qiskit.test import QiskitTestCase

class CommonUtilitiesMixin:
    """Utilities for meta testing.

    Subclasses should redefine the ``pass_class`` argument, with a Swap Mapper
    class.

    Note: This class assumes that the subclass is also inheriting from
    ``QiskitTestCase``, and it uses ``QiskitTestCase`` methods directly.
    """

    regenerate_expected = False
    seed_simulator = 42
    seed_transpiler = 42
    additional_args = {}
    pass_class = None

    def create_passmanager(self, coupling_map, initial_layout=None):
        """Returns a PassManager using self.pass_class(coupling_map, initial_layout)"""
        passmanager = PassManager()
        if initial_layout:
            passmanager.append(SetLayout(Layout(initial_layout)))

        # pylint: disable=not-callable
        passmanager.append(self.pass_class(CouplingMap(coupling_map), **self.additional_args))
        return passmanager

    def create_backend(self):
        """Returns a Backend."""
        return BasicAer.get_backend("qasm_simulator")

    def generate_ground_truth(self, transpiled_result, filename):
        """Generates the expected result into a file.

        Checks if transpiled_result matches self.counts by running in a backend
        (self.create_backend()). That's saved in a QASM in filename.

        Args:
            transpiled_result (DAGCircuit): The DAGCircuit to execute.
            filename (string): Where the QASM is saved.
        """
        sim_backend = self.create_backend()
        job = execute(
            transpiled_result,
            sim_backend,
            seed_simulator=self.seed_simulator,
            seed_transpiler=self.seed_transpiler,
            shots=self.shots,
        )
        self.assertDictAlmostEqual(self.counts, job.result().get_counts(), delta=self.delta)

        transpiled_result.qasm(formatted=False, filename=filename)

    def assertResult(self, result, circuit):
        """Fetches the QASM in circuit.name file and compares it with result."""
        qasm_name = f"{type(self).__name__}_{circuit.name}.qasm"
        qasm_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "qasm")
        filename = os.path.join(qasm_dir, qasm_name)

        if self.regenerate_expected:
            # Run result in backend to test that is valid.
            self.generate_ground_truth(result, filename)

        expected = QuantumCircuit.from_qasm_file(filename)

        self.assertEqual(result, expected)

class SwapperCommonTestCases(CommonUtilitiesMixin):
    """Tests that are run in several mappers.

    The tests here will be run in several mappers. When adding a test, please
    ensure that the test:

    * defines ``self.count``, ``self.shots``, ``self.delta``.
    * uses the ``self.assertResult`` assertion for comparing for regeneration of
      the ground truth.
    * explicitly sets a unique ``name`` of the ``QuantumCircuit``.

    See also ``CommonUtilitiesMixin`` and the module docstring.
    """

    def test_a_cx_to_map(self):
        """A single CX needs to be remapped.

         q0:----------m-----
                      |
         q1:-[H]-(+)--|-m---
                  |   | |
         q2:------.---|-|-m-
                      | | |
         c0:----------.-|-|-
         c1:------------.-|-
         c2:--------------.-

         CouplingMap map: [1]<-[0]->[2]

        expected count: '000': 50%
                        '110': 50%
        """
        self.counts = {"000": 512, "110": 512}
        self.shots = 1024
        self.delta = 5
        coupling_map = [[0, 1], [0, 2]]

        qr = QuantumRegister(3, "q")
        cr = ClassicalRegister(3, "c")
        circuit = QuantumCircuit(qr, cr, name="a_cx_to_map")
        circuit.h(qr[1])
        circuit.cx(qr[1], qr[2])
        circuit.measure(qr, cr)

        result = self.create_passmanager(coupling_map).run(circuit)
        self.assertResult(result, circuit)

    def test_initial_layout(self):
        """Using a non-trivial initial_layout.

         q3:----------------m--
         q0:----------m-----|--
                      |     |
         q1:-[H]-(+)--|-m---|--
                  |   | |   |
         q2:------.---|-|-m-|--
                      | | | |
         c0:----------.-|-|-|--
         c1:------------.-|-|--
         c2:--------------.-|--
         c3:----------------.--
         CouplingMap map: [1]<-[0]->[2]->[3]

        expected count: '000': 50%
                        '110': 50%
        """
        self.counts = {"0000": 512, "0110": 512}
        self.shots = 1024
        self.delta = 5
        coupling_map = [[0, 1], [0, 2], [2, 3]]

        qr = QuantumRegister(4, "q")
        cr = ClassicalRegister(4, "c")
        circuit = QuantumCircuit(qr, cr, name="initial_layout")
        circuit.h(qr[1])
        circuit.cx(qr[1], qr[2])
        circuit.measure(qr, cr)

        layout = {qr[3]: 0, qr[0]: 1, qr[1]: 2, qr[2]: 3}

        result = self.create_passmanager(coupling_map, layout).run(circuit)
        self.assertResult(result, circuit)

    def test_handle_measurement(self):
        """Handle measurement correctly.

         q0:--.-----(+)-m-------
              |      |  |
         q1:-(+)-(+)-|--|-m-----
                  |  |  | |
         q2:------|--|--|-|-m---
                  |  |  | | |
         q3:-[H]--.--.--|-|-|-m-
                        | | | |
         c0:------------.-|-|-|-
         c1:--------------.-|-|-
         c2:----------------.-|-
         c3:------------------.-

         CouplingMap map: [0]->[1]->[2]->[3]

        expected count: '0000': 50%
                        '1011': 50%
        """
        self.counts = {"1011": 512, "0000": 512}
        self.shots = 1024
        self.delta = 5
        coupling_map = [[0, 1], [1, 2], [2, 3]]

        qr = QuantumRegister(4, "q")
        cr = ClassicalRegister(4, "c")
        circuit = QuantumCircuit(qr, cr, name="handle_measurement")
        circuit.h(qr[3])
        circuit.cx(qr[0], qr[1])
        circuit.cx(qr[3], qr[1])
        circuit.cx(qr[3], qr[0])
        circuit.measure(qr, cr)

        result = self.create_passmanager(coupling_map).run(circuit)
        self.assertResult(result, circuit)

class TestsBasicSwap(SwapperCommonTestCases, QiskitTestCase):
    """Test SwapperCommonTestCases using BasicSwap."""

    pass_class = BasicSwap

class TestsLookaheadSwap(SwapperCommonTestCases, QiskitTestCase):
    """Test SwapperCommonTestCases using LookaheadSwap."""

    pass_class = LookaheadSwap

class TestsStochasticSwap(SwapperCommonTestCases, QiskitTestCase):
    """Test SwapperCommonTestCases using StochasticSwap."""

    pass_class = StochasticSwap
    additional_args = {"seed": 0}

class TestsSabreSwap(SwapperCommonTestCases, QiskitTestCase):
    """Test SwapperCommonTestCases using SabreSwap."""

    pass_class = SabreSwap
    additional_args = {"seed": 1242}

if __name__ == "__main__":
    if len(sys.argv) >= 2 and sys.argv[1] == "regenerate":
        CommonUtilitiesMixin.regenerate_expected = True
        del sys.argv[1]
    unittest.main()


text:
package io.github.resilience4j.bulkhead.operator;

import static java.util.Objects.requireNonNull;

import java.util.concurrent.atomic.AtomicReference;

import io.github.resilience4j.adapter.Permit;
import io.github.resilience4j.bulkhead.Bulkhead;
import io.github.resilience4j.bulkhead.BulkheadFullException;
import io.reactivex.internal.subscriptions.SubscriptionHelper;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

/**
 * A RxJava {@link Subscriber} to wrap another subscriber in a bulkhead.
 *
 * @param <T> the value type of the upstream and downstream
 */
final class BulkheadSubscriber<T> extends AtomicReference<Subscription> implements Subscriber<T>, Subscription {
    private final Bulkhead bulkhead;
    private final Subscriber<? super T> childSubscriber;
    private final AtomicReference<Permit> permitted = new AtomicReference<>(Permit.PENDING);

    BulkheadSubscriber(Bulkhead bulkhead, Subscriber<? super T> childSubscriber) {
        this.bulkhead = requireNonNull(bulkhead);
        this.childSubscriber = requireNonNull(childSubscriber);
    }

    @Override
    public void onSubscribe(Subscription subscription) {
        if (SubscriptionHelper.setOnce(this, subscription)) {
            if (acquireCallPermit()) {
                childSubscriber.onSubscribe(this);
            } else {
                cancel();
                childSubscriber.onSubscribe(this);
                childSubscriber.onError(new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())));
            }
        }
    }

    @Override
    public void onNext(T event) {
        if (isInvocationPermitted()) {
            childSubscriber.onNext(event);
        }
    }

    @Override
    public void onError(Throwable e) {
        if (isInvocationPermitted()) {
            bulkhead.onComplete();
            childSubscriber.onError(e);
        }
    }

    @Override
    public void onComplete() {
        if (isInvocationPermitted()) {
            releaseBulkhead();
            childSubscriber.onComplete();
        }
    }

    @Override
    public void request(long n) {
        this.get().request(n);
    }

    @Override
    public void cancel() {
        if (SubscriptionHelper.cancel(this)) {
            releaseBulkhead();
        }
    }

    private boolean acquireCallPermit() {
        boolean callPermitted = false;
        if (permitted.compareAndSet(Permit.PENDING, Permit.ACQUIRED)) {
            callPermitted = bulkhead.isCallPermitted();
            if (!callPermitted) {
                permitted.set(Permit.REJECTED);
            }
        }
        return callPermitted;
    }

    private boolean isInvocationPermitted() {
        return !SubscriptionHelper.isCancelled(get()) && wasCallPermitted();
    }

    private boolean wasCallPermitted() {
        return permitted.get() == Permit.ACQUIRED;
    }

    private void releaseBulkhead() {
        if (wasCallPermitted()) {
            bulkhead.onComplete();
        }
    }
}


text:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">
  <class name="se.citerus.dddsample.domain.model.voyage.Voyage" table="Voyage">

    <id name="id" column="id">
      <generator class="org.hibernate.id.IdentityGenerator"/>
    </id>

    <component name="voyageNumber" unique="true" update="false">
      <property name="number" column="voyage_number"/>
    </component>

    <component name="schedule">
      <list name="carrierMovements" cascade="all-delete-orphan">
        <key column="voyage_id" foreign-key="voyage_fk"/>
        <index column="cm_index"/>
        <one-to-many class="se.citerus.dddsample.domain.model.voyage.CarrierMovement"/>
      </list>
    </component>

  </class>
</hibernate-mapping>


text:
using System.Text;

namespace Test.SimpleTcpServer.Messaging
{
    public class ByteUtil
    {
        public static byte[] GetBytes(string text)
        {
            return Encoding.UTF8.GetBytes(text);
        }

        public static string GetString(byte[] bytes)
        {
            return Encoding.UTF8.GetString(bytes);
        }
    }
}


text:
亲爱的{{htmlescape var=$customer.name}},

使用电子邮件 {{var customer.email}} 登录到我们的店铺时必须先进行邮件验证.

要验证电子邮件并立刻登录,请使用 本验证链接. 本链接仅一次有效.

                                如遇提示需登录时,请使用下列值:

                                电子邮件: {{var customer.email}}

                                密码: {{htmlescape var=$customer.password}}

如果您有任何关于账户或其他方面的问题,请随时与我们联系 {{config path='trans_email/ident_support/email'}} 或致电 {{config path='general/store_information/phone'}}.

再次向您表示感谢, {{var store.getFrontendName()}}


text:
template <typename StackType>
class LoResStackBuilder: public StackBuilder< StackType > {
  virtual string getDefaultImageLoadDir();

  virtual typename StackType::SliceType::SpacingType getOriginalSpacings();
};

template<typename StackType>
string LoResStackBuilder<StackType>::getDefaultImageLoadDir()
{ return Dirs::BlockDir(); }

template<typename StackType>
typename StackType::SliceType::SpacingType LoResStackBuilder<StackType>::getOriginalSpacings()
{ return getSpacings<2>("LoRes"); }

#endif


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/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.4"/>
<title>Member List</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>

<link href="doxygen.css" rel="stylesheet" type="text/css" />

Main Page

Related Pages

Modules

Namespaces

Classes

Files

Class List

Class Hierarchy

Class Members

tbb

flow

interface9

gfx_async_msg

tbb::flow::interface9::gfx_async_msg< T > Member List

This is the complete list of members for tbb::flow::interface9::gfx_async_msg< T >, including all inherited members.

data() (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >	inline

data() const  (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >	inline

gfx_async_msg() (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >	inline

gfx_async_msg(const T &input_data) (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >	inline

kernel_id_type typedef (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >

set_task_id(kernel_id_type id) (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >	inline

task_id() const  (defined in tbb::flow::interface9::gfx_async_msg< T >)	tbb::flow::interface9::gfx_async_msg< T >	inline

Copyright © 2005-2018 Intel Corporation.  All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are
registered trademarks or trademarks of Intel Corporation or its
subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.


text:
using System;
using System.Collections.Generic;
using Whitelog.Core.Filter;
using Whitelog.Core.Loggers;
using Whitelog.Core.Loggers.String;
using Whitelog.Core.PackageDefinitions;
using Whitelog.Core.String;
using Whitelog.Core.String.StringBuffer;

namespace Whitelog.Core.Configuration.Fluent.StringLayout
{
    class StringLayoutBuilder : IStringLayoutBuilder,IStringOutputTo, ILoggerBuilder, IFilterBuilder<IStringLayoutBuilder>
    {
        class CustomStringAppenderBuilder : IStringAppenderBuilder
        {
            private IStringAppender m_stringAppender;

            public CustomStringAppenderBuilder(IStringAppender stringAppender)
            {
                m_stringAppender = stringAppender;
            }

            public IStringAppender Build()
            {
                return m_stringAppender;
            }
        }

        private string m_layout = null;

        private List<IStringAppenderBuilder> m_stringAppenders = new List<IStringAppenderBuilder>();
        public List<IStringPackageDefinition> m_definitions = new List<IStringPackageDefinition>();
        private LayoutExtensions<IStringLayoutBuilder> m_layoutExtensions;
        private FilterBuilder<StringLayoutBuilder> m_filterBuilder;

        public StringLayoutBuilder()
        {
            m_filterBuilder = new FilterBuilder<StringLayoutBuilder>(this);
        }

        public ILogger Build()
        {
            string layout = m_layout;
            if (m_layout == null)
            {
                layout = "${longdate} ${title} ${message}";
            }
            var filter = m_filterBuilder.Build();
            var layoutLogger = new StringLayoutLogger(layout, StringBufferPool.Instance, filter);
            if (m_layoutExtensions == null)
            {
                m_layoutExtensions = new LayoutExtensions<IStringLayoutBuilder>(this);
                var t = m_layoutExtensions.All;
            }
            m_layoutExtensions.Initilze(layoutLogger);

            foreach (var stringPackageDefinition in m_definitions)
            {
                layoutLogger.RegisterDefinition(stringPackageDefinition);
            }

            foreach (var stringAppender in m_stringAppenders)
            {
                layoutLogger.AddStringAppender(stringAppender.Build());
            }
            return layoutLogger;
        }

        public IFilterBuilder<IStringLayoutBuilder> Filter { get { return this; }}

        public IStringLayoutBuilder SetLayout(string layout)
        {
            m_layout = layout;
            return this;
        }

        public ILayoutExtensions<IStringLayoutBuilder> Extensions {
            get
            {
                if (m_layoutExtensions == null)
                {
                    m_layoutExtensions = new LayoutExtensions<IStringLayoutBuilder>(this);
                }
                return m_layoutExtensions;
            }
        }

        public IStringLayoutBuilder Map<T>(Func<PackageDefinition<T>, object> define)
        {
            var packageDefinition = new PackageDefinition<T>();
            define.Invoke(packageDefinition);
            m_definitions.Add(packageDefinition);
            return this;
        }

        public IStringLayoutBuilder Map(IStringPackageDefinition definition)
        {
            m_definitions.Add(definition);
            return this;
        }

        public IStringOutputTo OutputTo { get { return this; } }

        #region Filter

        public IStringLayoutBuilder Include(params LogTitles[] logTitles)
        {
            return m_filterBuilder.Include(logTitles);
        }

        public IStringLayoutBuilder Exclude(params LogTitles[] logTitles)
        {
            return m_filterBuilder.Exclude(logTitles);
        }

        public IStringLayoutBuilder Custom(IFilter filter)
        {
            return m_filterBuilder.Custom(filter);
        }

        #endregion

        #region IStringOutputTo

        public StringOutputer Async { get { return new StringOutputer(this,builder => m_stringAppenders.Add(builder), ExecutionMode.Async); } }
        public StringOutputer Sync  { get { return new StringOutputer(this, builder => m_stringAppenders.Add(builder), ExecutionMode.Sync); } }

        #endregion
    }
}


text:
=====================
Django Correlation ID
=====================

.. image:: https://travis-ci.org/Polyconseil/django-cid.png?branch=master
    :target: https://travis-ci.org/Polyconseil/django-cid

Logging is important. Anyone who has had a call at 3am to say the site
is down knows this. Without quality logging it is almost impossible to
work out what on earth is happening.

The more you log, the harder it is to track down exactly what the
effects of a particular request are. Enter Django Correlation ID.
Incoming requests are assigned a unique identifier. This can either
happen in your public facing web server (e.g. nginx) or be applied
by Django itself.

This correlation id (also known as request id) is then available
through the Django request/response cycle and may be automatically
included in all log messages. That way, you can easily link all log
messages that relate to the same request::

    2018-10-01T08:18:39.86+00:00 correlation_id=2433d5d4-27a3-4889-b14b-107a131368a3 Call to plug from cpoint=1
    2018-10-01T08:18:39.90+00:00 correlation_id=72fbd7dd-a0ba-4f92-9ed0-0db358338e86 Call to state by cpoint=2 with {'state': {'B': 'idle', 'A': 'on_charge'}}
    2018-10-01T08:18:39.92+00:00 correlation_id=2433d5d4-27a3-4889-b14b-107a131368a3 Ended rental=7 customer="John Smith" on plug

In this example, we can see that the first and the third log messages
are tied to the same request, while the second message relates to a
distinct request.

In addition to these logs, ``django-cid`` can include the correlation
id:

- in all SQL queries (as a comment);
- in rendered templates;
- as a header in the HTTP response generated by Django;
- and possibly anywhere by using the API of ``django-cid``, for
  example as an HTTP header on a request to another internal system of
  yours, which is especially useful in service-oriented architecture.

Documentation can be found at:  https://django-correlation-id.readthedocs.org/

Sources are on GitHub: https://github.com/Polyconseil/django-cid

Supported versions
------------------

We currently support Python >= 3.6 and Django >= 2.2.

Other versions may work but are not supported.


text:
import datetime
import asyncio
import logging
import yarl

from errors import RetryRequestLater

log = logging.getLogger(__name__)

class Stream:
    __slots__ = ('url', 'viewers', 'title', 'game', 'name')

    @classmethod
    def from_twitch(cls, data):
        self = cls.__new__(cls)
        self.name = data['user_name']
        self.url = f'https://twitch.tv/{self.name}'
        self.viewers = data['viewer_count']
        self.game = data['game_id']
        self.title =  data['title']
        return self

class Twitch:
    BASE_URL = yarl.URL('https://api.twitch.tv/helix/')
    def __init__(self, session, client_id, client_secret):
        self.session = session
        self.client_id = client_id
        self.client_secret = client_secret
        self.token = None
        self.expires_in = datetime.datetime(1970, 1, 1)

    def get_ratelimit_delta(self, resp):
        reset = float(resp.headers['Ratelimit-Reset'])
        dt = datetime.datetime.fromutctimestamp(reset)
        delta = (dt - datetime.datetime.utcnow()).total_seconds()
        return delta

    async def fetch_token(self):
        params = {
            'client_id': self.client_id,
            'client_secret': self.client_secret,
            'grant_type': 'client_credentials',
        }

        for i in range(3):
            async with self.session.post('https://id.twitch.tv/oauth2/token', params=params) as resp:
                log.info('Twitch Token Retrieval responded with %d', resp.status)
                if resp.status == 429:
                    delta = self.get_ratelimit_delta(resp)
                    log.warning('Ratelimited on %s for %.2f seconds', resp.url, delta)
                    await asyncio.sleep(delta)
                    continue

                if resp.status == 503:
                    log.warning('Service unavailable (%s). Retrying in 5 seconds...', resp.url)
                    await asyncio.sleep(5)
                    continue

                resp.raise_for_status()
                data = await resp.json()
                self.token = data['access_token']
                self.expires_in = datetime.datetime.utcnow() + datetime.timedelta(seconds=data['expires_in'])
                log.info('Received token that expires at %s', self.expires_in.isoformat())
                return

    async def request(self, method, path, *, params=None):
        now = datetime.datetime.utcnow()
        if now > self.expires_in:
            await self.fetch_token()

        headers = {
            'Authorization': f'Bearer {self.token}',
            'Client-ID': self.client_id,
        }

        for i in range(3):
            async with self.session.request(method, self.BASE_URL / path, params=params, headers=headers) as resp:
                log.info('Twitch API /%s responded with %d', path, resp.status)
                if resp.status == 429:
                    delta = self.get_ratelimit_delta(resp)
                    log.warning('Ratelimited on %s for %.2f seconds', resp.url, delta)
                    await asyncio.sleep(delta)
                    continue

                if resp.status == 503:
                    log.warning('Service unavailable (%s). Retrying in 5 seconds...', resp.url)
                    await asyncio.sleep(5)
                    continue

                if resp.status == 401:
                    data = await resp.json()
                    log.error('Unauthorized response: %s', data['message'])
                    resp.raise_for_status()

                resp.raise_for_status()
                return await resp.json()

    async def paginate(self, method, path, *, params=None, headers=None):
        paginating = True
        to_send = params
        while paginating:
            resp = await self.request(method, path, params=to_send, headers=headers)
            try:
                cursor = resp['pagination']['cursor']
            except KeyError:
                paginating = False
            else:
                if isinstance(params, list):
                    to_send = params + [('after', cursor)]
                elif isinstance(params, dict):
                    to_send = params.copy()
                    to_send['after'] = cursor
            yield resp['data']

    async def get_game_ids(self, game_names):
        params = [('name', name) for name in game_names]
        data = await self.request('GET', 'games', params=params)
        if data is None:
            raise RetryRequestLater('Could not get game IDs')

        return {
            x.get('id'): x.get('name')
            for x in data.get('data', [])
        }

    async def get_streams(self, game_ids):
        params = [('game_id', game_id) for game_id in game_ids]
        params.append(('first', 100))
        data = await self.request('GET', 'streams', params=params)
        if data is None:
            raise RetryRequestLater('Could not get streams by ID')
        return [Stream.from_twitch(d) for d in data.get('data', [])]


text:
package run

import (
	"fmt"
	"strings"

	"go.chromium.org/luci/common/git/footer"
	"go.chromium.org/luci/cv/internal/changelist"
)

// ExtractOptions computes the Run Options from 1 CL.
func ExtractOptions(snapshot *changelist.Snapshot) *Options {
	byKey := make(map[string][]string, len(snapshot.GetMetadata()))
	for _, pair := range snapshot.GetMetadata() {
		k, v := pair.GetKey(), pair.GetValue()
		byKey[k] = append(byKey[k], v)
	}

	valuesOf := func(mkey, lkey string) []string {
		var out []string

		switch k := footer.NormalizeKey(mkey); {
		case mkey == "":
		case k != mkey:
			panic(fmt.Errorf("use normalized key %q not %q in CV code", k, mkey))
		default:
			out = append(out, byKey[mkey]...)
		}

		if lkey != "" {
			out = append(out, byKey[lkey]...)
		}
		return out
	}

	has := func(mkey, lkey, value string) bool {
		if l := strings.ToLower(value); l != value {
			panic(fmt.Errorf("use lowercase value %q not %q in CV code", l, value))
		}
		for _, v := range valuesOf(mkey, lkey) {
			if strings.ToLower(v) == value {
				return true
			}
		}
		return false
	}

	isTrue := func(mkey, lkey string) bool { return has(mkey, lkey, "true") }

	o := &Options{}
	if isTrue("No-Equivalent-Builders", "NO_EQUIVALENT_BUILDERS") {
		o.SkipEquivalentBuilders = true
	}
	if isTrue("Cq-Do-Not-Cancel-Tryjobs", "") {
		o.AvoidCancellingTryjobs = true
	}
	if isTrue("No-Tree-Checks", "NOTREECHECKS") {
		o.SkipTreeChecks = true
	}
	if isTrue("No-Try", "NOTRY") {
		o.SkipTryjobs = true
	}
	if isTrue("No-Presubmit", "NOPRESUBMIT") {
		o.SkipPresubmit = true
	}
	o.IncludedTryjobs = append(o.IncludedTryjobs, valuesOf("Cq-Include-Trybots", "CQ_INCLUDE_TRYBOTS")...)
	o.CustomTryjobTags = append(o.CustomTryjobTags, valuesOf("Cq-Cl-Tag", "")...)
	return o
}

// MergeOptions merges two Run Options.
//
// Does not modify the passed object, but may return either of them.
func MergeOptions(a, b *Options) *Options {
	switch {
	case a == nil:
		return b
	case b == nil:
		return a
	}
	return &Options{
		AvoidCancellingTryjobs: a.AvoidCancellingTryjobs || b.AvoidCancellingTryjobs,
		SkipTryjobs:            a.SkipTryjobs || b.SkipTryjobs,
		SkipPresubmit:          a.SkipPresubmit || b.SkipPresubmit,
		SkipEquivalentBuilders: a.SkipEquivalentBuilders || b.SkipEquivalentBuilders,
		SkipTreeChecks:         a.SkipTreeChecks || b.SkipTreeChecks,
		IncludedTryjobs:        append(a.IncludedTryjobs, b.IncludedTryjobs...),
		CustomTryjobTags:       append(a.CustomTryjobTags, b.CustomTryjobTags...),
	}
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<!--
具体使用查看该帖子
 http://blog.csdn.net/qq_27093465/article/details/48650719 -->
<tiles-definitions>
	<!-- 主布局 -->
	<definition name="classic.layout" template="/WEB-INF/tiles/mainLayout.jsp">
		<put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/tiles/pieces/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/tiles/pieces/menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/tiles/pieces/footer.jsp" />
	</definition>
	<!-- 主布局 -->
	<!-- 项目(继承布局) -->
	<definition name="myFirstTilesView" extends="classic.layout">
		<put-attribute name="title" value="my first tiles view" />
		<put-attribute name="body" value="/WEB-INF/tiles/pieces/a.jsp" />
	</definition>
	<!--项目 -->
</tiles-definitions>