text:
package eu.newsreader.result;

import eu.newsreader.util.Util;

import java.io.*;
import java.util.ArrayList;
import java.util.Date;

/**
 * Created by piek on 12/16/14.
 */
public class CollectResults {

    static double recallTotalMentions = 0;
    static double precisionTotalMentions = 0;
    static double f1TotalMentions = 0;
    static double recallTotalCoreference = 0;
    static double precisionTotalCoreference = 0;
    static double f1TotalCoreference = 0;

    static double recallTotalNoCoreference = 0;
    static double precisionTotalNoCoreference = 0;
    static double f1TotalNoCoreference = 0;

    static double recallTotalBlanc = 0;
    static double precisionTotalBlanc = 0;
    static double f1TotalBlanc = 0;

    static int totalKeyMentions = 0;
    static int totalResponseMentions = 0;

    static int totalInventedMentions = 0;
    static int totalMissedMentions = 0;

    static int totalStrictlyCorrect = 0;
    static int totalPartiallyCorrect = 0;

    static double totalCorrectCoreferences = 0;
    static double totalKeyCoreferenceSets = 0;
    static double totalResponseCoreferenceSets = 0;

    static double totalCorrectCoreferenceLinks = 0;
    static double totalKeyCoreferenceLinks = 0;
    static double totalResponseCoreferenceLinks = 0;

    static double totalCorrectNonCoreferenceLinks = 0;
    static double totalKeyNonCoreferenceLinks = 0;
    static double totalResponseNonCoreferenceLinks = 0;

    static public void main (String[] args) {
        String pathToResponseFolder = "";
        String extension = "";
        String label = "";
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.equals("--result-folder") && (args.length>(i+1))) {
                pathToResponseFolder = args[i+1];
            }
            else if (arg.equals("--extension") && (args.length>(i+1))) {
                extension = args[i+1];
            }
            else if (arg.equals("--label") && (args.length>(i+1))) {
                label = args[i+1];
            }
        }
        String pathToResultFile = new File(pathToResponseFolder).getParent()+"/"+label+".results.csv";
        ArrayList<File> resultFiles = Util.makeRecursiveFileList(new File(pathToResponseFolder), extension);
        for (int i = 0; i < resultFiles.size(); i++) {
            File resultFile = resultFiles.get(i);
            readResultFile(resultFile);
        }
        Date date = new Date();
        String str = "";
        str = new File(pathToResponseFolder).getParent()+"\t"+label+"\n";
        str += "Date\t"+date.toString()+"\n\n";
        str += "Nr. of result files\t"+resultFiles.size()+"\n";
        str +="MENTIONS (key mentions="+totalKeyMentions+")\n";
        str +="# response mentions\t"+totalResponseMentions+"\n";
        str +="# missed mentions\t"+totalMissedMentions+"\n";
        str +="# invented mentions\t"+totalInventedMentions+"\n";
        str +="# strictly correct identified mentions\t"+totalStrictlyCorrect+"\n";
        str +="# partially correct identified mentions\t"+totalPartiallyCorrect+"\n";
        double recall = (double) 100*totalStrictlyCorrect/totalKeyMentions;
        double precision = (double) 100*totalStrictlyCorrect/totalResponseMentions;
        double f1 = (double) 2*(recall*precision)/(recall+precision);
        str +=" recall\t"+recall +"%\n";
        str +=" precision\t"+precision+"%\n";
        str +=" f1\t"+f1+"%\n\n";

        str += "REFERENCE (BLANC)\n";
        str +="# reference links\t"+totalKeyCoreferenceSets+"\n";
        str +="# response reference links\t"+totalResponseCoreferenceSets+"\n";
        str +="# correct reference links\t"+ totalCorrectCoreferences+"\n";
        recall = (double) 100*totalCorrectCoreferences/(double)totalKeyCoreferenceSets;
        precision = (double) 100*totalCorrectCoreferences/(double)totalResponseCoreferenceSets;
        f1 = (double) 2*(recall*precision)/(recall+precision);
        str +=" recall\t"+recall +"%\n";
        str +=" precision\t"+precision+"%\n";
        str +=" f1\t"+f1+"%\n\n";

        str += "COREFERENCE\n";
        str +="# key coreference links\t"+totalKeyCoreferenceLinks+"\n";
        str +="# response coreference links\t"+totalResponseCoreferenceLinks+"\n";
        str +="# correct coreference links\t"+ totalCorrectCoreferenceLinks+"\n";
        recall = (double) 100*totalCorrectCoreferenceLinks/(double)totalKeyCoreferenceLinks;
        precision = (double) 100*totalCorrectCoreferenceLinks/(double)totalResponseCoreferenceLinks;
        f1 = (double) 2*(recall*precision)/(recall+precision);
        str +=" recall\t"+recall +"%\n";
        str +=" precision\t"+precision+"%\n";
        str +=" f1\t"+f1+"%\n\n";

        str += "NOREFERENCE\n";
        str +="# key non-coreference links\t"+totalKeyNonCoreferenceLinks+"\n";
        str +="# response non-coreference links\t"+totalResponseNonCoreferenceLinks+"\n";
        str +="# correct non-coreference links\t"+ totalCorrectNonCoreferenceLinks+"\n";
        recall = (double) 100*totalCorrectNonCoreferenceLinks/(double)totalKeyNonCoreferenceLinks;
        precision =  (double)100*totalCorrectNonCoreferenceLinks/(double)totalResponseNonCoreferenceLinks;
        f1 = (double) 2*(recall*precision)/(recall+precision);
        str +=" recall\t"+recall +"%\n";
        str +=" precision\t"+precision+"%\n";
        str +=" f1\t"+f1+"%\n\n";

        str += "\n";
        double mentionRecall = recallTotalMentions/resultFiles.size();
        double mentionPrecision = precisionTotalMentions/resultFiles.size();
        double mentionF = f1TotalMentions/resultFiles.size();

        double coreferenceRecall = recallTotalCoreference/resultFiles.size();
        double coreferencePrecision = precisionTotalCoreference/resultFiles.size();
        double coreferenceF = f1TotalCoreference/resultFiles.size();
        double nocoreferenceRecall = recallTotalNoCoreference/resultFiles.size();
        double nocoreferencePrecision = precisionTotalNoCoreference/resultFiles.size();
        double nocoreferenceF = f1TotalNoCoreference/resultFiles.size();

        double blancRecall = recallTotalBlanc/resultFiles.size();
        double blancPrecision = precisionTotalBlanc/resultFiles.size();
        double blancF = f1TotalBlanc/resultFiles.size();

        str += "Macro average over all result files reported by the coref scorer:\n";
        str += "Macro average identification of Mentions\n";
        str += "recall\t"+mentionRecall+"%\n";
        str += "precision\t"+mentionPrecision+"%\n";
        str += "f1\t"+mentionF+"%\n\n";
        str += "Macro average blanc\n";
        str += "recall\t"+blancRecall+"%\n";
        str += "precision\t"+blancPrecision+"%\n";
        str += "f1\t"+blancF+"%\n";
        str += "\n";

        try {
            OutputStream fos = new FileOutputStream(pathToResultFile);
            fos.write(str.getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static public void readResultFile(File file) {
        if (file.exists() ) {
            try {
                FileInputStream fis = new FileInputStream(file);
                InputStreamReader isr = new InputStreamReader(fis);
                BufferedReader in = new BufferedReader(isr);
                String inputLine;
                String currentSentence = "";
                while (in.ready()&&(inputLine = in.readLine()) != null) {
                    /**
                     * Total key mentions: 12
                     Total response mentions: 14
                     Strictly correct identified mentions: 9
                     Partially correct identified mentions: 0
                     No identified: 3
                     Invented: 5
                     Recall: (1 / 2) 50%	Precision: (1 / 4) 25%	F1: 33.33%
                     --------------------------------------------------------------------------

                     ====== TOTALS =======
                     Identification of Mentions: Recall: (9 / 12) 75%	Precision: (9 / 14) 64.28%	F1: 69.23%
                     --------------------------------------------------------------------------
                     Coreference: Recall: (1 / 2) 50%	Precision: (1 / 4) 25%	F1: 33.33%
                     --------------------------------------------------------------------------
                     */
                   // METRIC muc:
                    //METRIC bcub:
                    //METRIC ceafm:
                    //METRIC ceafe:
                    //METRIC blanc:
                    boolean READ = false;
                    if (inputLine.trim().length()>0) {
                        if (inputLine.startsWith("METRIC blanc:")) {
                            READ = true;
                        } else {
                            if (READ) {
                                if (inputLine.startsWith("Total key mentions")) {
                                    int idx = inputLine.lastIndexOf(":");
                                    if (idx > -1) {
                                        Integer cnt = null;
                                        try {
                                            cnt = Integer.parseInt(inputLine.substring(idx + 1).trim());
                                        } catch (NumberFormatException e) {
                                            e.printStackTrace();
                                        }
                                        totalKeyMentions += cnt;
                                    }
                                } else if (inputLine.startsWith("Total response mentions")) {
                                    int idx = inputLine.lastIndexOf(":");
                                    if (idx > -1) {
                                        Integer cnt = null;
                                        try {
                                            cnt = Integer.parseInt(inputLine.substring(idx + 1).trim());
                                        } catch (NumberFormatException e) {
                                            System.out.println("inputLine = " + inputLine);
                                            e.printStackTrace();
                                        }
                                        totalResponseMentions += cnt;
                                    }
                                } else if (inputLine.startsWith("No identified")) {
                                    int idx = inputLine.lastIndexOf(":");
                                    if (idx > -1) {
                                        Integer cnt = null;
                                        try {
                                            cnt = Integer.parseInt(inputLine.substring(idx + 1).trim());
                                        } catch (NumberFormatException e) {
                                            System.out.println("inputLine = " + inputLine);
                                            e.printStackTrace();
                                        }
                                        totalMissedMentions += cnt;
                                    }
                                } else if (inputLine.startsWith("Invented")) {
                                    int idx = inputLine.lastIndexOf(":");
                                    if (idx > -1) {
                                        Integer cnt = null;
                                        try {
                                            cnt = Integer.parseInt(inputLine.substring(idx + 1).trim());
                                        } catch (NumberFormatException e) {
                                            System.out.println("inputLine = " + inputLine);
                                            e.printStackTrace();
                                        }
                                        totalInventedMentions += cnt;
                                    }
                                } else if (inputLine.startsWith("Strictly correct identified mentions:")) {
                                    int idx = inputLine.lastIndexOf(":");
                                    if (idx > -1) {
                                        Integer cnt = null;
                                        try {
                                            cnt = Integer.parseInt(inputLine.substring(idx + 1).trim());
                                        } catch (NumberFormatException e) {
                                            System.out.println("inputLine = " + inputLine);
                                            e.printStackTrace();
                                        }
                                        totalStrictlyCorrect += cnt;
                                    }
                                } else if (inputLine.startsWith("Partially correct identified mentions:")) {
                                    int idx = inputLine.lastIndexOf(":");
                                    if (idx > -1) {
                                        Integer cnt = null;
                                        try {
                                            cnt = Integer.parseInt(inputLine.substring(idx + 1).trim());
                                        } catch (NumberFormatException e) {
                                            System.out.println("inputLine = " + inputLine);
                                            e.printStackTrace();
                                        }
                                        totalPartiallyCorrect += cnt;
                                    }
                                } else if (inputLine.startsWith("Identification of Mentions:")) {
                                    // Identification of Mentions: Recall: (9 / 12) 75%	Precision: (9 / 14) 64.28%	F1: 69.23%
                                    String[] fields = inputLine.split("%");
                                    if (fields.length >= 3) {
                                        int idx = fields[0].indexOf(")");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[0].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            recallTotalMentions += cnt;
                                        }
                                        idx = fields[1].indexOf(")");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[1].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            precisionTotalMentions += cnt;
                                        }
                                        idx = fields[2].lastIndexOf(":");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[2].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            f1TotalMentions += cnt;
                                        }
                                    }
                                } else if (inputLine.startsWith("Coreference:")
                                        ) {
                                    /// This format is used by other scores than BLANC
                                    //Coreference: Recall: (1 / 2) 50%	Precision: (1 / 4) 25%	F1: 33.33%
                                    String[] fields = inputLine.split("%");
                                    if (fields.length >= 3) {
                                        int idx = fields[0].indexOf(")");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[0].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            recallTotalCoreference += cnt;
                                        }
                                        int idx_s = fields[0].indexOf("(");
                                        int idx_div = fields[0].indexOf("/");
                                        if (idx > idx_div & idx_div > idx_s & idx_s > -1) {
                                            String correct = fields[0].substring(idx_s + 1, idx_div).trim();
                                            String recall = fields[0].substring(idx_div + 1, idx).trim();
                                            //System.out.println("correct = " + correct);
                                            //System.out.println("recall = " + recall);
                                            try {
                                                totalCorrectCoreferences += Integer.parseInt(correct);
                                            } catch (NumberFormatException e) {
                                                e.printStackTrace();
                                            }
                                            try {
                                                totalKeyCoreferenceSets += Integer.parseInt(recall);
                                            } catch (NumberFormatException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                        idx = fields[1].indexOf(")");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[1].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            precisionTotalCoreference += cnt;
                                        }
                                        idx_s = fields[1].indexOf("(");
                                        idx_div = fields[1].indexOf("/");
                                        if (idx > idx_div & idx_div > idx_s & idx_s > -1) {
                                            String precision = fields[1].substring(idx_div + 1, idx).trim();
                                            //System.out.println("precision = " + precision);
                                            try {
                                                totalResponseCoreferenceSets += Integer.parseInt(precision);
                                            } catch (NumberFormatException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                        idx = fields[2].lastIndexOf(":");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[2].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            f1TotalCoreference += cnt;
                                        }
                                    }
                                } else if (
                                        inputLine.startsWith("BLANC:")
                                        ) {
                                    //BLANC: Recall: (0.851851851851852 / 1) 85.18%	Precision: (0.183632543926662 / 1) 18.36%	F1: 27%

                                    String[] fields = inputLine.split("%");
                                    if (fields.length >= 3) {
                                        int idx = fields[0].indexOf(")");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[0].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            recallTotalBlanc += cnt;
                                        }
                                        idx = fields[1].indexOf(")");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[1].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            precisionTotalBlanc += cnt;
                                        }
                                        idx = fields[2].lastIndexOf(":");
                                        if (idx > -1) {
                                            Double cnt = null;
                                            try {
                                                cnt = Double.parseDouble(fields[2].substring(idx + 1).trim());
                                            } catch (NumberFormatException e) {
                                                System.out.println("inputLine = " + inputLine);
                                                e.printStackTrace();
                                            }
                                            f1TotalBlanc += cnt;
                                        }
                                    }
                                } else if (inputLine.startsWith("Coreference links:") //// IN CASE OF BLANC WE GET DIFFERENT OUTPUT
                                        ||
                                        inputLine.startsWith("Non-coreference links:")
                                        ) {
                                    //Coreference links: Recall: (1 / 1) 100%	Precision: (1 / 17) 5.88%	F1: 11.11%
                                    //Non-coreference links: Recall: (95 / 135) 70.37%	Precision: (95 / 308) 30.84%	F1: 42.88%

                                    String[] fields = inputLine.split("%");
                                    if (fields.length >= 3) {
                                        int idx = fields[0].indexOf(")");
                                        int idx_s = fields[0].indexOf("(");
                                        int idx_div = fields[0].indexOf("/");
                                        if (idx > idx_div & idx_div > idx_s & idx_s > -1) {
                                            String correct = fields[0].substring(idx_s + 1, idx_div).trim();
                                            String recall = fields[0].substring(idx_div + 1, idx).trim();
                                            //System.out.println("correct = " + correct);
                                            //System.out.println("recall = " + recall);
                                            try {
                                                totalCorrectCoreferences += Double.parseDouble(correct);
                                                if (inputLine.startsWith("Coreference links:")) {
                                                    totalCorrectCoreferenceLinks += Double.parseDouble(correct);
                                                } else if (inputLine.startsWith("Non-coreference links:")) {
                                                    totalCorrectNonCoreferenceLinks += Double.parseDouble(correct);
                                                }
                                            } catch (NumberFormatException e) {
                                                e.printStackTrace();
                                            }
                                            try {
                                                totalKeyCoreferenceSets += Double.parseDouble(recall);
                                                if (inputLine.startsWith("Coreference links:")) {
                                                    totalKeyCoreferenceLinks += Double.parseDouble(recall);
                                                } else if (inputLine.startsWith("Non-coreference links:")) {
                                                    totalKeyNonCoreferenceLinks += Double.parseDouble(recall);
                                                }
                                            } catch (NumberFormatException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                        idx = fields[1].indexOf(")");
                                        idx_s = fields[1].indexOf("(");
                                        idx_div = fields[1].indexOf("/");
                                        if (idx > idx_div & idx_div > idx_s & idx_s > -1) {
                                            String precision = fields[1].substring(idx_div + 1, idx).trim();
                                            //System.out.println("precision = " + precision);
                                            try {
                                                totalResponseCoreferenceSets += Double.parseDouble(precision);
                                                if (inputLine.startsWith("Coreference links:")) {
                                                    totalResponseCoreferenceLinks += Double.parseDouble(precision);
                                                } else if (inputLine.startsWith("Non-coreference links:")) {
                                                    totalResponseNonCoreferenceLinks += Double.parseDouble(precision);
                                                }
                                            } catch (NumberFormatException e) {
                                                e.printStackTrace();
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * version: 8.01 /Users/piek/Desktop/NWR/NWR-benchmark/coreference/reference-coreference-scorers/v8.01/lib/CorScorer.pm
     ====> (8951_World_largest_passenger_airliner_makes_first_flight);:
     File (8951_World_largest_passenger_airliner_makes_first_flight);:
     Entity 0: (5,5)
     Entity 1: (7,7) (30,30)
     Entity 2: (11,11)
     Entity 3: (27,27)
     Entity 4: (32,33) (40,40)
     Entity 5: (46,46)
     Entity 6: (50,51)
     Entity 7: (58,58)
     Entity 8: (71,71)
     Entity 9: (76,76)
     ====> (8951_World_largest_passenger_airliner_makes_first_flight);:
     File (8951_World_largest_passenger_airliner_makes_first_flight);:
     Entity 0: (4,4)
     Entity 1: (5,5) (27,27) (50,51)
     Entity 2: (7,7) (30,30) (58,58)
     Entity 3: (11,11)
     Entity 4: (32,32)
     Entity 5: (66,66)
     Entity 6: (71,71)
     Entity 7: (76,76)
     Entity 8: (80,80)
     Entity 9: (83,83)
     (8951_World_largest_passenger_airliner_makes_first_flight);:
     Total key mentions: 12
     Total response mentions: 14
     Strictly correct identified mentions: 9
     Partially correct identified mentions: 0
     No identified: 3
     Invented: 5
     Recall: (1 / 2) 50%	Precision: (1 / 4) 25%	F1: 33.33%
     --------------------------------------------------------------------------

     ====== TOTALS =======
     Identification of Mentions: Recall: (9 / 12) 75%	Precision: (9 / 14) 64.28%	F1: 69.23%
     --------------------------------------------------------------------------
     Coreference: Recall: (1 / 2) 50%	Precision: (1 / 4) 25%	F1: 33.33%
     --------------------------------------------------------------------------

     ====== TOTALS =======
     Identification of Mentions: Recall: (15 / 17) 88.23%	Precision: (15 / 26) 57.69%	F1: 69.76%
     --------------------------------------------------------------------------

     Coreference:
     Coreference links: Recall: (1 / 1) 100%	Precision: (1 / 17) 5.88%	F1: 11.11%
     --------------------------------------------------------------------------
     Non-coreference links: Recall: (95 / 135) 70.37%	Precision: (95 / 308) 30.84%	F1: 42.88%
     --------------------------------------------------------------------------
     BLANC: Recall: (0.851851851851852 / 1) 85.18%	Precision: (0.183632543926662 / 1) 18.36%	F1: 27%
     */
}


text:
package com.ovoenergy.comms.model

import com.ovoenergy.comms.KafkaMessage
import com.ovoenergy.comms.model.types.{HasMetadataV2, HasInternalMetadata}
import com.sksamuel.avro4s.AvroDoc

@KafkaMessage
case class IssuedForDeliveryV2(
    // format: off

    metadata: MetadataV2,

    internalMetadata: InternalMetadata,

    @AvroDoc("The channel the comm has been issued over")
    channel: Channel,

    @AvroDoc("The Gateway the comm is being delivered by")
    gateway: Gateway,

    @AvroDoc("The ID given to the comm by the gateway")
    gatewayMessageId: String

    // format: on
) extends LoggableEvent
    with HasMetadataV2
    with HasInternalMetadata {
  import MetadataV2._
  override def loggableString: Option[String] = prettyPrint(this)
  override def mdcMap: Map[String, String] = {
    val eventMDC =
      Map(
        "gatewayMessageId" -> gatewayMessageId,
        "gateway" -> gateway.toString,
        "channel" -> channel.toString)
    combineMDCS(metadata.mdcMap, internalMetadata.mdcMap, eventMDC)
  }
}

redpajama_set_name: RedPajamaGithub


text:
from django.template import Library, Node
from userprofile.forms import _RegistrationForm
from django.template.loader import render_to_string

register = Library()

class RegistationFormNode(Node):
    def render(self, context):
        form = _RegistrationForm()
        template = "userprofile/account/includes/registration_form.html"
        data = { 'form': form, }
        return render_to_string(template, data)

def registration_form(parser, token):
    return RegistationFormNode()
registration_form = register.tag(registration_form)


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

<TITLE>
InstantiationStrategy (Spring Framework)
</TITLE>

<META NAME="keywords" CONTENT="org.springframework.beans.factory.support.InstantiationStrategy interface">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">

      Overview
      Package
    Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV CLASS
 NEXT CLASS

  FRAMES
 NO FRAMES

  All Classes

  SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

org.springframework.beans.factory.support

Interface InstantiationStrategy

All Known Implementing Classes:
SimpleInstantiationStrategy

public interface InstantiationStrategy

Interface responsible for creating instances corresponding to a
 root bean definition.

This is pulled out into a strategy as various approaches are possible,
 including using CGLIB to create subclasses on the fly to support
 Method Injection.

Since:

1.1

Author:

Rod Johnson

Method Summary

 java.lang.Object
instantiate(RootBeanDefinition beanDefinition,
            java.lang.String beanName,
            BeanFactory owner)

          Return an instance of the bean with the given name in this factory.

 java.lang.Object
instantiate(RootBeanDefinition beanDefinition,
            java.lang.String beanName,
            BeanFactory owner,
            java.lang.reflect.Constructor ctor,
            java.lang.Object[] args)

          Return an instance of the bean with the given name in this factory,
 creating it via the given constructor.

 java.lang.Object
instantiate(RootBeanDefinition beanDefinition,
            java.lang.String beanName,
            BeanFactory owner,
            java.lang.reflect.Method factoryMethod,
            java.lang.Object[] args)

          Return an instance of the bean with the given name in this factory,
 creating it via the given factory method.

Method Detail

instantiate

public java.lang.Object instantiate(RootBeanDefinition beanDefinition,
                                    java.lang.String beanName,
                                    BeanFactory owner)

Return an instance of the bean with the given name in this factory.

Parameters:
beanDefinition - bean definition
beanName - name of the bean when it's created in this context.
 The name can be null if we're autowiring a bean that doesn't
 belong to the factory.
owner - owning BeanFactory

Returns:
a bean instance for this bean definition

instantiate

public java.lang.Object instantiate(RootBeanDefinition beanDefinition,
                                    java.lang.String beanName,
                                    BeanFactory owner,
                                    java.lang.reflect.Constructor ctor,
                                    java.lang.Object[] args)

Return an instance of the bean with the given name in this factory,
 creating it via the given constructor.

Parameters:
beanDefinition - bean definition
beanName - name of the bean when it's created in this context.
 The name can be null if we're autowiring a bean that doesn't
 belong to the factory.
owner - owning BeanFactory
ctor - the constructor to use
args - the constructor arguments to apply

Returns:
a bean instance for this bean definition

instantiate

public java.lang.Object instantiate(RootBeanDefinition beanDefinition,
                                    java.lang.String beanName,
                                    BeanFactory owner,
                                    java.lang.reflect.Method factoryMethod,
                                    java.lang.Object[] args)

Return an instance of the bean with the given name in this factory,
 creating it via the given factory method.

Parameters:
beanDefinition - bean definition
beanName - name of the bean when it's created in this context.
 The name can be null if we're autowiring a bean that doesn't
 belong to the factory.
owner - owning BeanFactory
factoryMethod - the factory method to use
args - the factory method arguments to apply

Returns:
a bean instance for this bean definition

      Overview
      Package
    Class
      Use
      Tree
      Deprecated
      Index
      Help

 PREV CLASS
 NEXT CLASS

  FRAMES
 NO FRAMES

  All Classes

  SUMMARY: NESTED | FIELD | CONSTR | METHOD

DETAIL: FIELD | CONSTR | METHOD

Copyright (C) 2003-2004 The Spring Framework Project.


text:
"""For internal use only; no backwards-compatibility guarantees."""

# pytype: skip-file

globals()['INT64_MAX'] = 2**63 - 1
globals()['INT64_MIN'] = -2**63

POWER_TEN = [
    10e-1,
    10e0,
    10e1,
    10e2,
    10e3,
    10e4,
    10e5,
    10e6,
    10e7,
    10e8,
    10e9,
    10e10,
    10e11,
    10e12,
    10e13,
    10e14,
    10e15,
    10e16,
    10e17,
    10e18
]

def get_log10_round_to_floor(element):
  power = 0
  while element >= POWER_TEN[power]:
    power += 1
  return power - 1

class DataflowDistributionCounter(object):
  """Pure python DataflowDistributionCounter in case Cython not available.

  Please avoid using python mode if possible, since it's super slow
  Cythonized DatadflowDistributionCounter defined in
  apache_beam.transforms.cy_dataflow_distribution_counter.

  Currently using special bucketing strategy suitable for Dataflow

  Attributes:
    min: minimum value of all inputs.
    max: maximum value of all inputs.
    count: total count of all inputs.
    sum: sum of all inputs.
    buckets: histogram buckets of value counts for a
    distribution(1,2,5 bucketing). Max bucket_index is 58( sys.maxint as input).
    is_cythonized: mark whether DataflowDistributionCounter cythonized.
  """
  # Assume the max input is sys.maxint, then the possible max bucket size is 59
  MAX_BUCKET_SIZE = 59

  # 3 buckets for every power of ten -> 1, 2, 5
  BUCKET_PER_TEN = 3

  def __init__(self):
    global INT64_MAX  # pylint: disable=global-variable-not-assigned
    self.min = INT64_MAX
    self.max = 0
    self.count = 0
    self.sum = 0
    self.buckets = [0] * self.MAX_BUCKET_SIZE
    self.is_cythonized = False

  def add_input(self, element):
    if element < 0:
      raise ValueError('Distribution counters support only non-negative value')
    self.min = min(self.min, element)
    self.max = max(self.max, element)
    self.count += 1
    self.sum += element
    bucket_index = self.calculate_bucket_index(element)
    self.buckets[bucket_index] += 1

  def add_input_n(self, element, n):
    if element < 0:
      raise ValueError('Distribution counters support only non-negative value')
    self.min = min(self.min, element)
    self.max = max(self.max, element)
    self.count += n
    self.sum += element * n
    bucket_index = self.calculate_bucket_index(element)
    self.buckets[bucket_index] += n

  def calculate_bucket_index(self, element):
    """Calculate the bucket index for the given element."""
    if element == 0:
      return 0
    log10_floor = get_log10_round_to_floor(element)
    power_of_ten = POWER_TEN[log10_floor]
    if element < power_of_ten * 2:
      bucket_offset = 0
    elif element < power_of_ten * 5:
      bucket_offset = 1
    else:
      bucket_offset = 2
    return 1 + log10_floor * self.BUCKET_PER_TEN + bucket_offset

  def translate_to_histogram(self, histogram):
    """Translate buckets into Histogram.

    Args:
      histogram: apache_beam.runners.dataflow.internal.clents.dataflow.Histogram
      Ideally, only call this function when reporting counter to
      dataflow service.
    """
    first_bucket_offset = 0
    last_bucket_offset = 0
    for index in range(0, self.MAX_BUCKET_SIZE):
      if self.buckets[index] != 0:
        first_bucket_offset = index
        break
    for index in range(self.MAX_BUCKET_SIZE - 1, -1, -1):
      if self.buckets[index] != 0:
        last_bucket_offset = index
        break
    histogram.firstBucketOffset = first_bucket_offset
    histogram.bucketCounts = (
        self.buckets[first_bucket_offset:last_bucket_offset + 1])

  def extract_output(self):
    global INT64_MIN  # pylint: disable=global-variable-not-assigned
    global INT64_MAX  # pylint: disable=global-variable-not-assigned
    if not INT64_MIN <= self.sum <= INT64_MAX:
      self.sum %= 2**64
      if self.sum >= INT64_MAX:
        self.sum -= 2**64
    mean = self.sum // self.count if self.count else float('nan')
    return mean, self.sum, self.count, self.min, self.max

  def merge(self, accumulators):
    raise NotImplementedError()


text:
package com.codeabovelab.dm.mail.service;

/**
 * This exception indicate that we user unknown, or some other email field has invalid value.
 */
public class MailBadMessageException extends MailSenderException {
    public MailBadMessageException(String message) {
        super(message);
    }

    public MailBadMessageException(String message, Throwable cause) {
        super(message, cause);
    }

    public MailBadMessageException(Throwable cause) {
        super(cause);
    }
}


text:
var ui = require('ui');
var hasOwn = Object.prototype.hasOwnProperty;

ui.define('class-map', {
  handler: function() {
    var self = this;
    var classMap = this.get('classMap');
    var map = {};
    var name2class = {};

    var compareProp = function(name, val) {
      if (!hasOwn.call(map, name)) return;

      var mapVal = map[name],
        add = mapVal === true ? !!val : (val + '') === mapVal,
        classVal = name2class[name];

      self.view.classList[add ? 'add' : 'remove'](classVal);
    },
    handlerMap = function() {
      Object.keys(classMap).forEach(function(key) {
        var equalIndex = key.search(/\s*=\s*/),
          originalKey = key;

        if (equalIndex === -1) {
          map[key] = true;
        } else {
          var val = key.slice(equalIndex + 1);
          key = key.slice(0, equalIndex);
          map[key] = val;
        }

        name2class[key] = classMap[originalKey];
      });
    };

    handlerMap();

    events.on(self, ui.events.propChange, function(e, data) {
      var type = data.type,
        name = data.name;

      console.log('prop change');

      switch (type) {
        case 'string':
        case 'boolean':
        case 'number': {
          compareProp(name, self.get(name));
        }
      }
    });
  },
  properties: {
    classMap: 'json'
  }
});


text:
.. highlight:: sh

*************************
Download and Installation
*************************

Overview
========

 0. Install *Python 2.5*.
 1. Download and install *Scapy*.
 2. (For non-Linux platforms): Install *libpcap and libdnet* and their Python wrappers.
 3. (Optional): Install *additional software* for special features.
 4. Run Scapy with root priviledges.

Each of these steps can be done in a different way dependent on your platform and on the version of Scapy you want to use.

At the moment, there are two different versions of Scapy:

* **Scapy v1.x**. It consists of only one file and works on Python 2.4, so it might be easier to install.
  Moreover, your OS may already have a specially prepared packages or ports for it. Last version is v1.2.2.
* **Scapy v2.x**. The current development version adds several features (e.g. IPv6). It consists of several
  files  packaged in the standard distutils way. Scapy v2 needs Python 2.5.

.. note::

   In Scapy v2 use ``from scapy.all import *`` instead of ``from scapy import *``.

Installing Scapy v2.x
=====================

The following steps describe how to install (or update) Scapy itself.
Dependent on your platform, some additional libraries might have to be installed to make it actually work.
So please also have a look at the platform specific chapters on how to install those requirements.

.. note::

   The following steps apply to Unix-like operating systems (Linux, BSD, Mac OS X).
   For Windows, see the special chapter below.

Make sure you have Python installed before you go on.

Latest release
--------------

Download the `latest version <http://scapy.net>`_ to a temporary directory and install it in the standard `distutils <http://docs.python.org/inst/inst.html>`_ way::

$ cd /tmp
$ wget scapy.net
$ unzip scapy-latest.zip
$ cd scapy-2.*
$ sudo python setup.py install

Alternatively, you can execute the zip file::

$ chmod +x scapy-latest.zip
$ sudo ./scapy-latest.zip

or::

$ sudo sh scapy-latest.zip

or::

$ mv scapy-latest.zip /usr/local/bin/scapy
$ sudo scapy

.. note::

   To make a zip executable, some bytes have been added before the zip header.
   Most zip programs handle this, but not all. If your zip program complains
   about the zip file to be corrupted, either change it, or download a
   non-executable zip at http://hg.secdev.org/scapy/archive/tip.zip

Current development version
----------------------------

.. index::
   single: Mercurial, repository

If you always want the latest version with all new features and bugfixes, use Scapy's Mercurial repository:

1. Install the `Mercurial <http://www.selenic.com/mercurial/>`_ version control system. For example, on Debian/Ubuntu use::

      $ sudo apt-get install mercurial

   or on OpenBSD::

      $ pkg_add mercurial

2. Check out a clone of Scapy's repository::

   $ hg clone http://hg.secdev.org/scapy

3. Install Scapy in the standard distutils way::

   $ cd scapy
   $ sudo python setup.py install

Then you can always update to the latest version::

$ hg pull
$ hg update
$ sudo python setup.py install

For more information about Mercurial, have a look at the `Mercurial book <http://hgbook.red-bean.com/>`_.

Installing Scapy v1.2
=====================

As Scapy v1 consists only of one single Python file, installation is easy:
Just download the last version and run it with your Python interpreter::

 $ wget http://hg.secdev.org/scapy/raw-file/v1.2.0.2/scapy.py
 $ sudo python scapy.py

.. index::
   single: scapy-bpf

On BSD systems, you can also try the latest version of `Scapy-bpf <http://hg.natisbad.org/scapy-bpf/raw-file/tip/scapy.py>`_ (`development repository <http://hg.natisbad.org/scapy-bpf/>`_). It doesn't need libpcap or libdnet.

Optional software for special features
======================================

For some special features you have to install more software.
Platform-specific instructions on how to install those packages can be found in the next chapter.
Here are the topics involved and some examples that you can use to try if your installation was successful.

.. index::
   single: plot()

* Plotting. ``plot()`` needs `Gnuplot-py <http://gnuplot-py.sourceforge.net/>`_ which needs `GnuPlot <http://www.gnuplot.info/>`_ and `NumPy <http://numpy.scipy.org/>`_.

  .. code-block:: python

     >>> p=sniff(count=50)
     >>> p.plot(lambda x:len(x))

* 2D graphics. ``psdump()`` and ``pdfdump()`` need `PyX <http://pyx.sourceforge.net/>`_ which in turn needs a `LaTeX distribution <http://www.tug.org/texlive/>`_. For viewing the PDF and PS files interactively, you also need `Adobe Reader <http://www.adobe.com/products/reader/>`_ (``acroread``) and `gv <http://wwwthep.physik.uni-mainz.de/~plass/gv/>`_ (``gv``).

  .. code-block:: python

     >>> p=IP()/ICMP()
     >>> p.pdfdump("test.pdf")

* Graphs. ``conversations()`` needs `Grapviz <http://www.graphviz.org/>`_ and `ImageMagick <http://www.imagemagick.org/>`_.

  .. code-block:: python

     >>> p=readpcap("myfile.pcap")
     >>> p.conversations(type="jpg", target="> test.jpg")

* 3D graphics. ``trace3D()`` needs `VPython <http://www.vpython.org/>`_.

  .. code-block:: python

     >>> a,u=traceroute(["www.python.org", "google.com","slashdot.org"])
     >>> a.trace3D()

.. index::
   single: WEP, unwep()

* WEP decryption. ``unwep()`` needs `PyCrypto <http://www.dlitz.net/software/pycrypto/>`_. Example using a `Weplap test file <http://weplab.sourceforge.net/caps/weplab-64bit-AA-managed.pcap>`_:

  .. code-block:: python

     >>> enc=rdpcap("weplab-64bit-AA-managed.pcap")
     >>> enc.show()
     >>> enc[0]
      >>> conf.wepkey="AA\x00\x00\x00"
      >>> dec=Dot11PacketList(enc).toEthernet()
      >>> dec.show()
      >>> dec[0]

* Fingerprinting. ``nmap_fp()`` needs `Nmap <http://nmap.org>`_. You need an `old version <http://nmap.org/dist-old/>`_ (before v4.23) that still supports first generation fingerprinting.

  .. code-block:: python

     >>> load_module("nmap")
     >>> nmap_fp("192.168.0.1")
     Begin emission:
     Finished to send 8 packets.
     Received 19 packets, got 4 answers, remaining 4 packets
     (0.88749999999999996, ['Draytek Vigor 2000 ISDN router'])

.. index::
   single: VOIP

* VOIP. ``voip_play()`` needs `SoX <http://sox.sourceforge.net/>`_.

Platform-specific instructions
==============================

Linux native
------------

Scapy can run natively on Linux, without libdnet and libpcap.

* Install `Python 2.5 <http://www.python.org>`_.
* Install `tcpdump <http://www.tcpdump.org>`_ and make sure it is in the $PATH. (It's only used to compile BPF filters (``-ddd option``))
* Make sure your kernel has Packet sockets selected (``CONFIG_PACKET``)
* If your kernel is < 2.6, make sure that Socket filtering is selected ``CONFIG_FILTER``)

Debian/Ubuntu
-------------

Just use the standard packages::

$ sudo apt-get install tcpdump graphviz imagemagick python-gnuplot python-crypto python-pyx

Fedora
------

Here's how to install Scapy on Fedora 9:

.. code-block:: text

    # yum install mercurial python-devel
    # cd /tmp
    # hg clone http://hg.secdev.org/scapy
    # cd scapy
    # python setup.py install

Some optional packages:

.. code-block:: text

    # yum install graphviz python-crypto sox PyX gnuplot numpy
    # cd /tmp
    # wget http://heanet.dl.sourceforge.net/sourceforge/gnuplot-py/gnuplot-py-1.8.tar.gz
    # tar xvfz gnuplot-py-1.8.tar.gz
    # cd gnuplot-py-1.8
    # python setup.py install

Mac OS X
--------

Here's how to install Scapy on Mac OS 10.4 (Tiger) or 10.5 (Leopard).

Set up a development environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1. Install X11.
   On the Mac OS X DVD, it is located in the "Optional Installs.mpkg" package.

2. Install SDK.
   On the Mac OS X DVD, it is located in the "Xcode Tools/Packages" directory.

3. Install Python 2.5 from Python.org.
   Using Apple's Python version will lead to some problems.
   Get it from http://www.python.org/ftp/python/2.5.2/python-2.5.2-macosx.dmg

Install using MacPorts
^^^^^^^^^^^^^^^^^^^^^^

3. Install MacPorts
   Download the dmg from macports.org and install it.

4. Update MacPorts::

   $ sudo port -d selfupdate

5. Install Scapy::

   $ sudo port install scapy

You can then update to the latest version as shown in the generic installation above.

Install from original sources
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Install libdnet and its Python wrapper::

 $ wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz
 $ tar xfz libdnet-1.12.tgz
 $ ./configure
 $ make
 $ sudo make install
 $ cd python
 $ python2.5 setup.py install

Install libpcap and its Python wrapper::

 $ wget http://dfn.dl.sourceforge.net/sourceforge/pylibpcap/pylibpcap-0.6.2.tar.gz
 $ tar xfz pylibpcap-0.6.2.tar.gz
 $ cd pylibpcap-0.6.2
 $ python2.5 setup.py install

Optionally: Install readline::

 $ python `python -c "import pimp; print pimp.__file__"` -i readline

OpenBSD
-------

Here's how to install Scapy on OpenBSD 4.3.

.. code-block:: text

 # export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/4.3/packages/i386/
 # pkg_add py-libpcap py-libdnet mercurial
 # ln -sf /usr/local/bin/python2.5 /usr/local/bin/python
 # cd /tmp
 # hg clone http://hg.secdev.org/scapy
 # cd scapy
 # python setup.py install

Optional packages
^^^^^^^^^^^^^^^^^

py-crypto

.. code-block:: text

 # pkg_add py-crypto

gnuplot and its Python binding:

.. code-block:: text

 # pkg_add gnuplot py-gnuplot

Graphviz (large download, will install several GNOME libraries)

.. code-block:: text

 # pkg_add graphviz

ImageMagick (takes long to compile)

.. code-block:: text

 # cd /tmp
 # ftp ftp://ftp.openbsd.org/pub/OpenBSD/4.3/ports.tar.gz
 # cd /usr
 # tar xvfz /tmp/ports.tar.gz
 # cd /usr/ports/graphics/ImageMagick/
 # make install

PyX (very large download, will install texlive etc.)

.. code-block:: text

 # pkg_add py-pyx

/etc/ethertypes

.. code-block:: text

 # wget http://www.secdev.org/projects/scapy/files/ethertypes -O /etc/ethertypes

python-bz2 (for UTscapy)

.. code-block:: text

 # pkg_add python-bz2

.. _windows_installation:

Windows
-------

.. sectionauthor:: Dirk Loss <mail at dirk-loss.de>

Scapy is primarily being developed for Unix-like systems and works best on those platforms. But the latest version of Scapy supports Windows out-of-the-box. So you can use nearly all of Scapy's features on your Windows machine as well.

.. note::
   If you update from Scapy-win v1.2.0.2 to Scapy v2 remember to use ``from scapy.all import *`` instead of ``from scapy import *``.

.. image:: graphics/scapy-win-screenshot1.png
   :scale: 80
   :align: center

You need the following software packages in order to install Scapy on Windows:

  * `Python <http://www.python.org>`_: `python-2.5.4.msi <http://www.python.org/ftp/python/2.5.4/python-2.5.4.msi>`_. `python-2.6.3.msi <http://www.python.org/ftp/python/2.6.3/python-2.6.3.msi>`_. After installation, add the Python installation directory and its \Scripts subdirectory to your PATH. Depending on your Python version, the defaults would be ``C:\Python25`` and ``C:\Python25\Scripts`` or ``C:\Python26`` and ``C:\Python26\Scripts`` respectively.
  * `Scapy <http://www.secdev.org/projects/scapy/>`_: `latest development version <http://hg.secdev.org/scapy/archive/tip.zip>`_ from the `Mercurial repository <http://hg.secdev.org/scapy>`_. Unzip the archive, open a command prompt in that directory and run "python setup.py install".
  * `pywin32 <http://python.net/crew/mhammond/win32/Downloads.html>`_: `pywin32-214.win32-py2.5.exe <http://surfnet.dl.sourceforge.net/sourceforge/pywin32/pywin32-214.win32-py2.5.exe>`_ `pywin32-214.win32-py2.6.exe <http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20214/pywin32-214.win32-py2.6.exe>`_
  * `WinPcap <http://www.winpcap.org/>`_: `WinPcap_4_1_1.exe <http://www.winpcap.org/install/bin/WinPcap_4_1_1.exe>`_. You might want to choose "[x] Automatically start the WinPcap driver at boot time", so that non-privileged users can sniff, especially under Vista and Windows 7. If you want to use the ethernet vendor database to resolve MAC addresses or use the ``wireshark()`` command, download `Wireshark <http://www.wireshark.org/>`_ which already includes WinPcap.
  * `pypcap <http://code.google.com/p/pypcap/>`_: `pcap-1.1-scapy-20090720.win32-py25.exe <http://www.secdev.org/projects/scapy/files/pcap-1.1-scapy-20090720.win32-py2.5.exe>`_ `pcap-1.1-scapy-20090720.win32-py2.6.exe <http://www.secdev.org/projects/scapy/files/pcap-1.1-scapy-20090720.win32-py2.6.exe>`_. This is a *special version for Scapy*, as the original leads to some timing problems. Now works on Vista and Windows 7, too. Under Vista/Win7 please right-click on the installer and choose "Run as administrator".
  * `libdnet <http://code.google.com/p/libdnet/>`_:  `dnet-1.12.win32-py2.5.exe <http://libdnet.googlecode.com/files/dnet-1.12.win32-py2.5.exe>`_ `dnet-1.12.win32-py2.6.exe <http://www.secdev.org/projects/scapy/files/dnet-1.12.win32-py2.6.exe>`_. Under Vista/Win7 please right-click on the installer and choose "Run as administrator"
  * `pyreadline <http://ipython.scipy.org/moin/PyReadline/Intro>`_: `pyreadline-1.5-win32-setup.exe <http://ipython.scipy.org/dist/pyreadline-1.5-win32-setup.exe>`_

Just download the files and run the setup program. Choosing the default installation options should be safe.

For your convenience direct links are given to the versions I used (for Python 2.5 and Python 2.6). If these links do not work or if you are using a different Python version, just visit the homepage of the respective package and look for a Windows binary. As a last resort, search the web for the filename.

After all packages are installed, open a command prompt (cmd.exe) and run Scapy by typing ``scapy``. If you have set the PATH correctly, this will find a little batch file in your ``C:\Python26\Scripts`` directory and instruct the Python interpreter to load Scapy.

If really nothing seems to work, consider skipping the Windows version and using Scapy from a Linux Live CD -- either in a virtual machine on your Windows host or by booting from CDROM: An older version of Scapy is already included in grml and BackTrack for example. While using the Live CD you can easily upgrade to the lastest Scapy version by typing ``cd /tmp && wget scapy.net``.

Optional packages
^^^^^^^^^^^^^^^^^

Plotting (``plot``)

 * `GnuPlot <http://www.gnuplot.info/>`_: `gp420win32.zip <http://downloads.sourceforge.net/gnuplot/gp420win32.zip>`_. Extract the zip file (e.g. to ``c:\gnuplot``) and add the ``gnuplot\bin`` directory to your PATH.
 * `NumPy <http://numpy.scipy.org/>`_: `numpy-1.3.0-win32-superpack-python2.5.exe <http://downloads.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0-win32-superpack-python2.5.exe>`_ `numpy-1.3.0-win32-superpack-python2.6.exe <http://downloads.sourceforge.net/project/numpy/NumPy/1.3.0/numpy-1.3.0-win32-superpack-python2.6.exe>`_. Gnuplot-py 1.8 needs NumPy.
 * `Gnuplot-py <http://gnuplot-py.sourceforge.net/>`_: `gnuplot-py-1.8.zip <http://downloads.sourceforge.net/project/gnuplot-py/Gnuplot-py/1.8/gnuplot-py-1.8.zip>`_. Extract to temp dir, open command prompt, change to tempdir and type ``python setup.py install``.

2D Graphics (``psdump``, ``pdfdump``)

 * `PyX <http://pyx.sourceforge.net/>`_: `PyX-0.10.tar.gz <http://mesh.dl.sourceforge.net/sourceforge/pyx/PyX-0.10.tar.gz>`_. Extract to temp dir, open command prompt, change to tempdir and type ``python setup.py install``
 * `MikTeX <http://miktex.org/>`_: `Basic MiKTeX 2.8 Installer <http://miktex.org/2.8/setup>`_. PyX needs a LaTeX installation. Choose an installation directory WITHOUT spaces (e.g. ``C:\MikTex2.8`` and add the ``(INSTALLDIR)\miktex\bin`` subdirectory to your PATH.

Graphs (conversations)

 * `Graphviz <http://www.graphviz.org/>`_: `graphviz-2.24.exe <http://www.graphviz.org/pub/graphviz/stable/windows/graphviz-2.24.msi>`_. Add ``(INSTALLDIR)\ATT\Graphviz\bin`` to your PATH.

3D Graphics (trace3d)

 * `VPython <http://www.vpython.org/>`_: `VPython-Win-Py2.5-3.2.11.exe <http://www.vpython.org/download/VPython-Win-Py2.5-3.2.11.exe>`_. No binary installer for Python 2.6 seems to be available yet.

WEP decryption

 * `PyCrypto <http://www.dlitz.net/software/pycrypto/>`_: `pycrypto-2.1.0.win32-py2.5.zip <http://www.voidspace.org.uk/downloads/pycrypto-2.1.0.win32-py2.5.zip>`_ `pycrypto-2.1.0.win32-py2.6.zip <http://www.voidspace.org.uk/downloads/pycrypto-2.1.0.win32-py2.6.zip>`_

Fingerprinting

  * `Nmap <http://nmap.org>`_. `nmap-4.20-setup.exe <http://download.insecure.org/nmap/dist-old/nmap-4.20-setup.exe>`_. If you use the default installation directory, Scapy should automatically find the fingerprints file.
  * Queso: `queso-980922.tar.gz <http://www.packetstormsecurity.org/UNIX/scanners/queso-980922.tar.gz>`_. Extract the tar.gz file (e.g. using `7-Zip <http://www.7-zip.org/>`_) and put ``queso.conf`` into your Scapy directory

Screenshot
^^^^^^^^^^

.. image:: graphics/scapy-win-screenshot2.png
   :scale: 80
   :align: center

Known bugs
^^^^^^^^^^

 * You may not be able to capture WLAN traffic on Windows. Reasons are explained on the Wireshark wiki and in the WinPcap FAQ. Try switching off promiscuous mode with ``conf.sniff_promisc=False``.
 * Packets cannot be sent to localhost (or local IP addresses on your own host).
 * The ``voip_play()`` functions do not work because they output the sound via ``/dev/dsp`` which is not available on Windows.


text:
package iso20022

// Choice of format for the legal framework.
type LegalFramework4Choice struct {

	// Legal framework expressed as an ISO 20022 code.
	Code *LegalFramework1Code `xml:"Cd"`

	// Legal framework expressed as a proprietary code.
	Proprietary *GenericIdentification47 `xml:"Prtry"`
}

func (l *LegalFramework4Choice) SetCode(value string) {
	l.Code = (*LegalFramework1Code)(&value)
}

func (l *LegalFramework4Choice) AddProprietary() *GenericIdentification47 {
	l.Proprietary = new(GenericIdentification47)
	return l.Proprietary
}


text:
using System.Collections.Generic;
using System.Threading.Tasks;
using Examples.ExampleDomain;
using Xunit.ScenarioReporting;

namespace Examples
{
    public class ExampleScenarioRunner : ReflectionBasedScenarioRunner<object, object, object>
    {
        public ExampleScenarioRunner()
        {
            _aggregate = new CalculatorAggregate();
        }

        private readonly CalculatorAggregate _aggregate;
        private ComputedResult _actual;

        protected override Task Given(IReadOnlyList<object> givens)
        {
            foreach (Number given in givens)
            {
                _aggregate.Enter(given);
            }
            return Task.CompletedTask;
        }

        protected override Task When(object when)
        {
            _actual = _aggregate.Compute((Operation)when);
            return Task.CompletedTask;
        }

        protected override Task<IReadOnlyList<object>> ActualResults()
        {
            return Task.FromResult((IReadOnlyList<object>)new []{_actual});
        }
    }
}


text:
module Cistern::Request
  include Cistern::HashSupport

  module ClassMethods
    # @deprecated Use {#cistern_method} instead
    def service_method(name = nil)
      Cistern.deprecation(
        '#service_method is deprecated.  Please use #cistern_method',
        caller[0]
      )
      @_cistern_method ||= name
    end

    def cistern_method(name = nil)
      @_cistern_method ||= name
    end
  end

  def self.cistern_request(cistern, klass, name)
    unless klass.name || klass.cistern_method
      fail ArgumentError, "can't turn anonymous class into a Cistern request"
    end

    method = <<-EOS
      def #{name}(*args)
        #{klass}.new(self).call(*args)
      end
    EOS

    cistern::Mock.module_eval method, __FILE__, __LINE__
    cistern::Real.module_eval method, __FILE__, __LINE__
  end

  def self.service_request(*args)
    Cistern.deprecation(
      '#service_request is deprecated.  Please use #cistern_request',
      caller[0]
    )
    cistern_request(*args)
  end

  attr_reader :cistern

  def service
    Cistern.deprecation(
      '#service is deprecated.  Please use #cistern',
      caller[0]
    )
    @cistern
  end

  def initialize(cistern)
    @cistern = cistern
  end

  def call(*args)
    dispatch(*args)
  end

  def real(*)
    raise NotImplementedError
  end

  def mock(*)
    raise NotImplementedError
  end

  protected

  # @fixme remove _{mock,real} methods and call {mock,real} directly before 3.0 release.
  def dispatch(*args)
    to = cistern.mocking? ? :mock : :real

    legacy_method = :"_#{to}"

    if respond_to?(legacy_method)
      Cistern.deprecation(
        '#_mock is deprecated.  Please use #mock and/or #call. See https://github.com/lanej/cistern#request-dispatch',
        caller[0]
      )

      public_send(legacy_method, *args)
    else
      public_send(to, *args)
    end
  end
end


text:
package ru.otus.java_2017_04.golovnin.hw16.MessageSystem;

import com.google.gson.Gson;
import ru.otus.java_2017_04.golovnin.hw16.MessageSystem.Messages.Message;

public class MessagePacker {
    private final MessageClient mc;
    private final Gson gson = new Gson();

    public MessagePacker(MessageClient messageClient){
        mc = messageClient;
    }

    public void sendMessage(Message msg){
        mc.sendMessage(gson.toJson(msg));
    }
}


text:
<?php
/**
 * Elgg 1.8.14 upgrade 2013030600
 * update_user_location
 *
 * Before Elgg 1.8, a location like "London, England" would be stored as an array.
 * This script turns that back into a string.
 */

$ia = elgg_set_ignore_access(true);
$options = array(
	'type' => 'user',
	// only grab users that have set their location
	'metadata_name' => 'location',
	'limit' => 0,
);
$batch = new ElggBatch('elgg_get_entities_from_metadata', $options);

foreach ($batch as $entity) {
	if (is_array($entity->location)) {
		$entity->location = implode(', ', $entity->location);
	}
}
elgg_set_ignore_access($ia);


text:
package org.apache.nifi;

public interface NiFiEntryPoint {

    NiFiServer getServer();

    void shutdownHook(boolean isReload);
}


text:
using DotNetEssentials.Logging;
using DotNetTor.Http;
using DotNetTor.Http.Models;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static DotNetTor.Http.Constants;

namespace System.Net.Http
{
	public static class HttpMessageHelper
	{
		public static async Task<string> ReadStartLineAsync(Stream stream, CancellationToken ctsToken = default)
		{
			// https://tools.ietf.org/html/rfc7230#section-3
			// A recipient MUST parse an HTTP message as a sequence of octets in an
			// encoding that is a superset of US-ASCII[USASCII].

			// Read until the first CRLF
			// the CRLF is part of the startLine
			// https://tools.ietf.org/html/rfc7230#section-3.5
			// Although the line terminator for the start-line and header fields is
			// the sequence CRLF, a recipient MAY recognize a single LF as a line
			// terminator and ignore any preceding CR.
			var bab = new ByteArrayBuilder();
			int read = 0;
			while (read >= 0)
			{
				read = await stream.ReadByteAsync(ctsToken).ConfigureAwait(false);
				bab.Append((byte)read);
				if (Encoding.ASCII.GetBytes(LF)[0] == (byte)read)
				{
					break;
				}
			}

			var startLine = bab.ToString(Encoding.ASCII);
			if (startLine == null || startLine == "") throw new FormatException($"{nameof(startLine)} cannot be null or empty.");
			return startLine;
		}

		public static async Task<string> ReadHeadersAsync(Stream stream, CancellationToken ctsToken = default)
		{
			var headers = "";
			var firstRead = true;
			while (true)
			{
				string header = await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken);

				if (header == null) throw new FormatException($"Malformed HTTP message: End of headers must be CRLF.");
				if (header == "")
				{
					// 2 CRLF was read in row so it's the end of the headers
					break;
				}

				if (firstRead)
				{
					// https://tools.ietf.org/html/rfc7230#section-3
					// A recipient that receives whitespace between the
					// start - line and the first header field MUST either reject the message
					// as invalid or consume each whitespace-preceded line without further
					// processing of it(i.e., ignore the entire line, along with any
					// subsequent lines preceded by whitespace, until a properly formed
					// header field is received or the header section is terminated).
					if (char.IsWhiteSpace(header[0]))
					{
						throw new FormatException($"Invalid HTTP message: Cannot be whitespace between the start line and the headers.");
					}
					firstRead = false;
				}

				headers += header + CRLF; // CRLF is part of the headerstring
			}
			if (headers == null || headers == "")
			{
				headers = "";
			}

			return headers;
		}

		private static async Task<string> ReadCRLFLineAsync(Stream stream, Encoding encoding, CancellationToken ctsToken = default)
		{
			var bab = new ByteArrayBuilder();
			while (true)
			{
				int ch = await stream.ReadByteAsync(ctsToken).ConfigureAwait(false);
				if (ch == -1) break;

				if (ch == '\r')
				{
					var ch2 = await stream.ReadByteAsync(ctsToken).ConfigureAwait(false);
					if (ch2 == '\n')
					{
						return bab.ToString(encoding);
					}
					else
					{
						bab.Append(new byte[] { (byte)ch, (byte)ch2 });
						continue;
					}
				}
				bab.Append((byte)ch);
			}
			if (bab.Length > 0)
			{
				return bab.ToString(encoding);
			}

			return null;
		}

		public static async Task<HttpContent> GetContentAsync(Stream stream, HttpRequestContentHeaders headerStruct, CancellationToken ctsToken = default)
		{
			if (headerStruct.RequestHeaders != null && headerStruct.RequestHeaders.Contains("Transfer-Encoding"))
			{
				// https://tools.ietf.org/html/rfc7230#section-4
				// All transfer-coding names are case-insensitive
				if ("chunked".Equals(headerStruct.RequestHeaders.TransferEncoding.Last().Value, StringComparison.OrdinalIgnoreCase))
				{
					return await GetDecodedChunkedContentAsync(stream, headerStruct, ctsToken).ConfigureAwait(false);
				}
				// https://tools.ietf.org/html/rfc7230#section-3.3.3
				// If a Transfer - Encoding header field is present in a response and
				// the chunked transfer coding is not the final encoding, the
				// message body length is determined by reading the connection until
				// it is closed by the server.  If a Transfer - Encoding header field
				// is present in a request and the chunked transfer coding is not
				// the final encoding, the message body length cannot be determined
				// reliably; the server MUST respond with the 400(Bad Request)
				// status code and then close the connection.
				else
				{
					return await GetContentTillEndAsync(stream, ctsToken).ConfigureAwait(false);
				}
			}
			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// 5.If a valid Content - Length header field is present without
			// Transfer - Encoding, its decimal value defines the expected message
			// body length in octets.If the sender closes the connection or
			// the recipient times out before the indicated number of octets are
			// received, the recipient MUST consider the message to be
			// incomplete and close the connection.
			else if (headerStruct.ContentHeaders.Contains("Content-Length"))
			{
				long? contentLength = headerStruct.ContentHeaders?.ContentLength;
				return await GetContentTillLengthAsync(stream, contentLength, ctsToken).ConfigureAwait(false);
			}

			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// 6.If this is a request message and none of the above are true, then
			// the message body length is zero (no message body is present).
			// 7.  Otherwise, this is a response message without a declared message
			// body length, so the message body length is determined by the
			// number of octets received prior to the server closing the
			// connection.
			return GetDummyOrNullContent(headerStruct.ContentHeaders);
		}

		public static async Task<HttpContent> GetContentAsync(Stream stream, HttpResponseContentHeaders headerStruct, HttpMethod requestMethod, StatusLine statusLine, CancellationToken ctsToken = default)
		{
			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// The length of a message body is determined by one of the following
			// (in order of precedence):
			// 1.Any response to a HEAD request and any response with a 1xx
			// (Informational), 204(No Content), or 304(Not Modified) status
			// code is always terminated by the first empty line after the
			// header fields, regardless of the header fields present in the
			// message, and thus cannot contain a message body.
			if (requestMethod == HttpMethod.Head
				|| HttpStatusCodeHelper.IsInformational(statusLine.StatusCode)
				|| statusLine.StatusCode == HttpStatusCode.NoContent
				|| statusLine.StatusCode == HttpStatusCode.NotModified)
			{
				return GetDummyOrNullContent(headerStruct.ContentHeaders);
			}
			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// 2.Any 2xx(Successful) response to a CONNECT request implies that
			// the connection will become a tunnel immediately after the empty
			// line that concludes the header fields.A client MUST ignore any
			// Content - Length or Transfer-Encoding header fields received in
			// such a message.
			else if (requestMethod == new HttpMethod("CONNECT"))
			{
				if (HttpStatusCodeHelper.IsSuccessful(statusLine.StatusCode))
				{
					return null;
				}
			}
			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// 3.If a Transfer-Encoding header field is present and the chunked
			// transfer coding(Section 4.1) is the final encoding, the message
			// body length is determined by reading and decoding the chunked
			// data until the transfer coding indicates the data is complete.
			if (headerStruct.ResponseHeaders != null && headerStruct.ResponseHeaders.Contains("Transfer-Encoding"))
			{
				// https://tools.ietf.org/html/rfc7230#section-4
				// All transfer-coding names are case-insensitive
				if ("chunked".Equals(headerStruct.ResponseHeaders.TransferEncoding.Last().Value, StringComparison.OrdinalIgnoreCase))
				{
					return await GetDecodedChunkedContentAsync(stream, headerStruct, ctsToken).ConfigureAwait(false);
				}
				// https://tools.ietf.org/html/rfc7230#section-3.3.3
				// If a Transfer - Encoding header field is present in a response and
				// the chunked transfer coding is not the final encoding, the
				// message body length is determined by reading the connection until
				// it is closed by the server.  If a Transfer - Encoding header field
				// is present in a request and the chunked transfer coding is not
				// the final encoding, the message body length cannot be determined
				// reliably; the server MUST respond with the 400(Bad Request)
				// status code and then close the connection.
				else
				{
					return await GetContentTillEndAsync(stream, ctsToken).ConfigureAwait(false);
				}
			}
			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// 5.If a valid Content - Length header field is present without
			// Transfer - Encoding, its decimal value defines the expected message
			// body length in octets.If the sender closes the connection or
			// the recipient times out before the indicated number of octets are
			// received, the recipient MUST consider the message to be
			// incomplete and close the connection.
			else if (headerStruct.ContentHeaders.Contains("Content-Length"))
			{
				long? contentLength = headerStruct.ContentHeaders?.ContentLength;

				return await GetContentTillLengthAsync(stream, contentLength, ctsToken).ConfigureAwait(false);
			}

			// https://tools.ietf.org/html/rfc7230#section-3.3.3
			// 6.If this is a request message and none of the above are true, then
			// the message body length is zero (no message body is present).
			// 7.  Otherwise, this is a response message without a declared message
			// body length, so the message body length is determined by the
			// number of octets received prior to the server closing the
			// connection.
			return await GetContentTillEndAsync(stream, ctsToken).ConfigureAwait(false);
		}

		private static async Task<HttpContent> GetDecodedChunkedContentAsync(Stream stream, HttpRequestContentHeaders headerStruct, CancellationToken ctsToken = default)
		{
			return await GetDecodedChunkedContentAsync(stream, headerStruct, null, ctsToken).ConfigureAwait(false);
		}
		private static async Task<HttpContent> GetDecodedChunkedContentAsync(Stream stream, HttpResponseContentHeaders headerStruct, CancellationToken ctsToken = default)
		{
			return await GetDecodedChunkedContentAsync(stream, null, headerStruct, ctsToken).ConfigureAwait(false);
		}
		private static async Task<HttpContent> GetDecodedChunkedContentAsync(Stream stream, HttpRequestContentHeaders requestHeaders, HttpResponseContentHeaders responseHeaders, CancellationToken ctsToken = default)
		{
			if(responseHeaders == null && requestHeaders == null)
			{
				throw new ArgumentException("Response and request headers cannot be both null.");
			}
			if (responseHeaders != null && requestHeaders != null)
			{
				throw new ArgumentException("Either response or request headers has to be null.");
			}

			// https://tools.ietf.org/html/rfc7230#section-4.1.3
			// 4.1.3.Decoding Chunked
			// A process for decoding the chunked transfer coding can be represented
			// in pseudo - code as:
			// length := 0
			// read chunk - size, chunk - ext(if any), and CRLF
			// while (chunk - size > 0)
			// {
			//   read chunk-data and CRLF
			//   append chunk-data to decoded-body
			//   length:= length + chunk - size
			//   read chunk-size, chunk - ext(if any), and CRLF
			// }
			// read trailer field
			// while (trailer field is not empty) {
			//   if (trailer field is allowed to be sent in a trailer) {
			//      append trailer field to existing header fields
			//   }
			//   read trailer-field
			// }
			// Content - Length := length
			// Remove "chunked" from Transfer-Encoding
			// Remove Trailer from existing header fields
			long length = 0;
			var firstChunkLine = await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken: ctsToken).ConfigureAwait(false);
			ParseFistChunkLine(firstChunkLine, out long chunkSize, out IEnumerable<string> chunkExtensions);
			// We will not do anything with the chunk extensions, because:
			// https://tools.ietf.org/html/rfc7230#section-4.1.1
			// A recipient MUST ignore unrecognized chunk extensions.

			var decodedBody = new List<byte>();
			// https://tools.ietf.org/html/rfc7230#section-4.1
			// The chunked transfer coding is complete
			// when a chunk with a chunk-size of zero is received, possibly followed
			// by a trailer, and finally terminated by an empty line.
			while (chunkSize > 0)
			{
				var chunkData = await ReadBytesTillLengthAsync(stream, chunkSize, ctsToken).ConfigureAwait(false);
				if (await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken).ConfigureAwait(false) != "")
				{
					throw new FormatException("Chunk does not end with CRLF.");
				}

				foreach (var b in chunkData)
				{
					decodedBody.Add(b);
				}

				length += chunkSize;

				firstChunkLine = await ReadCRLFLineAsync(stream, Encoding.ASCII, ctsToken: ctsToken).ConfigureAwait(false);
				ParseFistChunkLine(firstChunkLine, out long cs, out IEnumerable<string> ces);
				chunkSize = cs;
				chunkExtensions = ces;
			}
			// https://tools.ietf.org/html/rfc7230#section-4.1.2
			// A trailer allows the sender to include additional fields at the end
			// of a chunked message in order to supply metadata that might be
			// dynamically generated while the message body is sent
			string trailerHeaders = await ReadHeadersAsync(stream, ctsToken).ConfigureAwait(false);
			var trailerHeaderSection = HeaderSection.CreateNew(trailerHeaders);
			RemoveInvalidTrailers(trailerHeaderSection);
			if (responseHeaders != null)
			{
				var trailerHeaderStruct = trailerHeaderSection.ToHttpResponseHeaders();
				AssertValidHeaders(trailerHeaderStruct.ResponseHeaders, trailerHeaderStruct.ContentHeaders);
				// https://tools.ietf.org/html/rfc7230#section-4.1.2
				// When a chunked message containing a non-empty trailer is received,
				// the recipient MAY process the fields(aside from those forbidden
				// above) as if they were appended to the message's header section.
				CopyHeaders(trailerHeaderStruct.ResponseHeaders, responseHeaders.ResponseHeaders);

				responseHeaders.ResponseHeaders.Remove("Transfer-Encoding");
				responseHeaders.ContentHeaders.TryAddWithoutValidation("Content-Length", length.ToString());
				responseHeaders.ResponseHeaders.Remove("Trailer");
			}
			if (requestHeaders != null)
			{
				var trailerHeaderStruct = trailerHeaderSection.ToHttpRequestHeaders();
				AssertValidHeaders(trailerHeaderStruct.RequestHeaders, trailerHeaderStruct.ContentHeaders);
				// https://tools.ietf.org/html/rfc7230#section-4.1.2
				// When a chunked message containing a non-empty trailer is received,
				// the recipient MAY process the fields(aside from those forbidden
				// above) as if they were appended to the message's header section.
				CopyHeaders(trailerHeaderStruct.RequestHeaders, requestHeaders.RequestHeaders);

				requestHeaders.RequestHeaders.Remove("Transfer-Encoding");
				requestHeaders.ContentHeaders.TryAddWithoutValidation("Content-Length", length.ToString());
				requestHeaders.RequestHeaders.Remove("Trailer");
			}

			return new ByteArrayContent(decodedBody.ToArray());
		}

		public static void RemoveInvalidTrailers(HeaderSection trailerHeaderSection)
		{
			// https://tools.ietf.org/html/rfc7230#section-4.1.2
			// A sender MUST NOT generate a trailer that contains a field necessary
			// for message framing (e.g., Transfer - Encoding and Content - Length),
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Transfer-Encoding");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Length");
			// routing (e.g., Host)
			// request modifiers(e.g., controls and
			// https://tools.ietf.org/html/rfc7231#section-5.1
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Cache-Control");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Expect");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Host");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Max-Forwards");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Pragma");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Range");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "TE");
			// conditionals in Section 5 of[RFC7231]),
			// https://tools.ietf.org/html/rfc7231#section-5.2
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Match");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-None-Match");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Modified-Since");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Unmodified-Since");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "If-Range");
			// authentication(e.g., see [RFC7235]
			// https://tools.ietf.org/html/rfc7235#section-5.3
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Authorization");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Proxy-Authenticate");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Proxy-Authorization");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "WWW-Authenticate");
			// and[RFC6265]),
			// https://tools.ietf.org/html/rfc6265
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Set-Cookie");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Cookie");
			// response control data(e.g., see Section 7.1 of[RFC7231]),
			// https://tools.ietf.org/html/rfc7231#section-7.1
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Age");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Cache-Control");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Expires");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Date");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Location");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Retry-After");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Vary");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Warning");
			// or determining how to process the payload(e.g.,
			// Content - Encoding, Content - Type, Content - Range, and Trailer).
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Encoding");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Type");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Content-Range");
			trailerHeaderSection.Fields.RemoveAll(x => x.Name == "Trailer");
		}

		public static void ParseFistChunkLine(string firstChunkLine, out long chunkSize, out IEnumerable<string> chunkExtensions)
		{
			// https://tools.ietf.org/html/rfc7230#section-4.1
			// chunk          = chunk-size [ chunk-ext ] CRLF
			// https://tools.ietf.org/html/rfc7230#section-4.1.1
			// chunk-ext      = *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
			var parts = firstChunkLine.Split(";", StringSplitOptions.RemoveEmptyEntries);
			// https://tools.ietf.org/html/rfc7230#section-4.1
			// The chunk-size field is a string of hex digits indicating the size of
			// the chunk-data in octets.
			chunkSize = Convert.ToInt64(parts.First().Trim(), 16);
			chunkExtensions = null;
			if (parts.Length > 1)
			{
				chunkExtensions = parts.Skip(1);
			}
		}

		private static async Task<HttpContent> GetContentTillEndAsync(Stream stream, CancellationToken ctsToken)
		{
			var bab = new ByteArrayBuilder();
			while(true)
			{
				var read = await stream.ReadByteAsync(ctsToken).ConfigureAwait(false);
				if (read == -1) return new ByteArrayContent(bab.ToArray());
			}
		}

		private static async Task<HttpContent> GetContentTillLengthAsync(Stream stream, long? contentLength, CancellationToken ctsToken = default)
			=> new ByteArrayContent(await ReadBytesTillLengthAsync(stream, contentLength, ctsToken).ConfigureAwait(false));

		private static async Task<byte[]> ReadBytesTillLengthAsync(Stream stream, long? length, CancellationToken ctsToken)
		{
			// TODO make it work with long
			try
			{
				Convert.ToInt32(length);
			}
			catch (OverflowException ex)
			{
				throw new NotSupportedException($"Content-Length too long: {length}.", ex);
			}

			var allData = new byte[(int)length];
			var num = await stream.ReadBlockAsync(allData, 0, (int)length).ConfigureAwait(false);
			if (num < (int)length)
			{
				// https://tools.ietf.org/html/rfc7230#section-3.3.3
				// If the sender closes the connection or
				// the recipient times out before the indicated number of octets are
				// received, the recipient MUST consider the message to be
				// incomplete and close the connection.
				// https://tools.ietf.org/html/rfc7230#section-3.4
				// A client that receives an incomplete response message, which can
				// occur when a connection is closed prematurely or when decoding a
				// supposedly chunked transfer coding fails, MUST record the message as
				// incomplete.Cache requirements for incomplete responses are defined
				// in Section 3 of[RFC7234].
				throw new NotSupportedException($"Incomplete message. Expected length: {length}, actual: {num}.");
			}
			return allData;
		}

		public static void AssertValidHeaders(HttpHeaders messageHeaders, HttpContentHeaders contentHeaders)
		{
			if (messageHeaders != null && messageHeaders.Contains("Transfer-Encoding"))
			{
				if (contentHeaders != null && contentHeaders.Contains("Content-Length"))
				{
					contentHeaders.Remove("Content-Length");
				}
			}
			// Any Content-Length field value greater than or equal to zero is valid.
			if (contentHeaders.Contains("Content-Length"))
			{
				if (contentHeaders.ContentLength < 0)
					throw new HttpRequestException("Content-Length MUST be bigger than zero.");
			}
		}

		public static HttpContent GetDummyOrNullContent(HttpContentHeaders contentHeaders)
		{
			if (contentHeaders != null && contentHeaders.Count() != 0)
			{
				return new ByteArrayContent(new byte[] { }); // dummy empty content
			}
			else
			{
				return null;
			}
		}

		public static void CopyHeaders(HttpHeaders source, HttpHeaders destination)
		{
			if (source != null && source.Count() != 0)
			{
				foreach (var header in source)
				{
					destination.TryAddWithoutValidation(header.Key, header.Value);
				}
			}
		}
	}
}


text:
package com.bortbort.arduino.Model.Core;

import com.bortbort.arduino.FiloFirmata.PinCapability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;

/**
 * Created by chuck on 2/28/2016.
 * Temporary class
 */
public class AnalogPinMapper {
    private static final Logger log = LoggerFactory.getLogger(AnalogPinMapper.class);
    private static ArrayList<ArrayList<PinCapability>> pinCapabilities = null;
    private static Integer firstAnalogPinIdentifier = null;

    public static Integer getAnalogPinIdentifier(Integer digitalPinIdentifier) {
        if (pinCapabilities == null) {
            throw new RuntimeException("pinCapabilities must be populated first!");
        }

        return digitalPinIdentifier - firstAnalogPinIdentifier;
    }

    public static Integer getDigitalPinIdentifier(Integer analogPinIdentifier) {
        if (pinCapabilities == null) {
            throw new RuntimeException("pinCapabilities must be populated first!");
        }

        return firstAnalogPinIdentifier + analogPinIdentifier;
    }

    static void setPinCapabilities(ArrayList<ArrayList<PinCapability>> pinCapabilities) {
        AnalogPinMapper.pinCapabilities = pinCapabilities;

        for (int x = 0; x < pinCapabilities.size(); x++) {
            if (pinCapabilities.get(x).contains(PinCapability.ANALOG)) {
                firstAnalogPinIdentifier = x;
                break;
            }
        }

        if (firstAnalogPinIdentifier == null) {
            log.error("There are no analog pins!?");
        }
    }
}


text:
use warnings ;
use strict;
use Getopt::Long qw(:config no_ignore_case);
use Bio::EnsEMBL::Compara::DBSQL::DBAdaptor;

$| = 1;

# pretending I've got an object here
# by creating a blessed hash ref and passing it around like an object
# this is to avoid using global variables in functions, and to consolidate
# the globals into a nice '$self' package
my $self = bless {};

$self->{'scale'} = 10;

my ($help, $taxondbhost, $taxondbport, $taxondbname);
my ($lcdbhost, $lcdbport, $lcdbname, $lcdbuser, $lcdbpass);
$lcdbport='3306';

GetOptions('help'           => \$help,
           'taxon_id=i'     => \$self->{'taxon_id'},
           'name=s'         => \$self->{'scientific_name'},
           'taxondbhost=s'  => \$taxondbhost,
           'taxondbport=s'  => \$taxondbport,
           'taxondbname=s'  => \$taxondbname,
           'dbhost|lcdbhost|host|h=s'     => \$lcdbhost,
           'dbport|lcdbport|port|P=s'     => \$lcdbport,
           'dbname|lcdbname|db|D=s'     => \$lcdbname,
           'dbuser|lcdbuser|user|u=s'     => \$lcdbuser,
	   'dbpass|lcdbpass|pass|p=s'     => \$lcdbpass,
          );

#No test for lcdbname which cause other opts to get eaten!

my $state;
if($self->{'taxon_id'}) { $state = 1; }
if($self->{'scientific_name'}) { $state = 2; }
if($self->{'taxon_id'} && $lcdbname) { $state = 3; };
if($self->{'scientific_name'} && $lcdbname) { $state = 3; };

if ($self->{'taxon_id'} && $self->{'scientific_name'}) {
  print "You can't use -taxon_id and -name together. Use one or the other.\n\n";
  exit 3;
}

if ($help or !$state) { usage(); }

my $taxon_dbc     = connect_db($taxondbhost, $taxondbport, $taxondbname, "ensro");
my $lc_dbc;
if (defined $lcdbname){
	$lc_dbc = 	connect_db($lcdbhost, $lcdbport, $lcdbname, $lcdbuser, $lcdbpass);
}

Bio::EnsEMBL::Registry->no_version_check(1);

if ($state == 1) {
    fetch_by_ncbi_taxon_id($self);
}
elsif ($state == 2) {
    fetch_by_scientific_name($self);
}
elsif ($state == 3) {
    load_taxonomy_in_core($self);
}

#cleanup memory
if($self->{'root'}) {
#  print("ABOUT TO MANUALLY release tree\n");
  $self->{'root'}->release_tree;
  $self->{'root'} = undef;
#  print("DONE\n");
}

exit(0);

#######################
#
# subroutines
#
#######################

sub usage {
  print "load_taxonomy.pl [options]\n";
  print "  -help                  : print this help\n";
  print "  -taxondbhost host -taxondbport port -taxondbname dbname\n";
  print "                         : connect to taxonomy database\n";
  print "  -taxon_id <int>        : print classification by taxon_id\n";
  print "  -name <string>         : print classification by scientific name e.g. \"Homo sapiens\"\n";
  print "  -lcdbhost host -lcdbport port -lcdbname dbname -lcdbuser user -lcdbpass passwd\n";
  print "                         : the low coverage database for which you want to update the taxonomy information in the meta table\n ";
  print "                          to be used with -taxon_id or -name\n";
  print "load_taxonomy.pl v1.1\n";

  exit(1);
}

sub fetch_by_ncbi_taxon_id {
  my $self = shift;
  my $taxonDBA = $taxon_dbc->get_NCBITaxonAdaptor;
  my $node = $taxonDBA->fetch_node_by_taxon_id($self->{'taxon_id'});
  $node->no_autoload_children;
  my $root = $node->root;

#  $root->print_tree($self->{'scale'});
  if ($node->rank eq 'species') {
  #if ($node->rank eq 'species' || $node->rank eq 'subspecies') {
    print "classification: ",$node->classification,"\n";
    print "scientific name: ",$node->binomial,"\n";
    if ($node->has_tag('genbank common name')) {
      print "common name: ",$node->get_value_for_tag('genbank common name'),"\n";
    } else {
      print "no common name\n";
    }
  }
  $self->{'root'} = $root;
}

sub fetch_by_scientific_name {
  my $self = shift;
  my $taxonDBA = $taxon_dbc->get_NCBITaxonAdaptor;
  my $node = $taxonDBA->fetch_node_by_name($self->{'scientific_name'});
  $node->no_autoload_children;
  my $root = $node->root;

#  $root->print_tree($self->{'scale'});
  if ($node->rank eq 'species') {
    print "classification: ",$node->classification,"\n";
    print "scientific name: ",$node->binomial,"\n";
    if ($node->has_tag('genbank common name')) {
      print "common name: ",$node->get_value_for_tag('genbank common name'),"\n";
    } else {
      print "no common name\n";
    }
  }
  $self->{'root'} = $root;
}

sub load_taxonomy_in_core {
  my $self = shift;
  my $taxonDBA = $taxon_dbc->get_NCBITaxonAdaptor;
  my $node;
  if (defined $self->{'taxon_id'}) {
    $node = $taxonDBA->fetch_node_by_taxon_id($self->{'taxon_id'});
  } else {
    $node = $taxonDBA->fetch_node_by_name($self->{'scientific_name'});
  }

  my $match_rank = ($node->name eq 'Canis familiaris') ? 'subspecies' : 'species';
#  my $match_rank;
#  if ($node->name eq 'Canis familiaris' ||
#      $node->name eq 'Gorilla gorilla gorilla' ||
#      $node->name eq 'Mustela putorius furo'
#      $node->name eq 'Ceratotherium simum simum' ||
#      $node->name eq 'Orycteropus afer afer') {
#     ) {
#    $match_rank = 'subspecies';
#  } else {
#    $match_rank = 'species';
#  }

  if($node->rank ne $match_rank){
      print "ERROR: taxon_id=",$self->{'taxon_id'},", '",$node->name,"' is rank '",$node->rank,"'.\n";
      print "It is not a rank 'species' (subspecies for dog). So it can't be loaded.\n\n";
    exit 2;
  }

  $node->no_autoload_children;
  my $root = $node->root;

  my $mc = $lc_dbc->get_MetaContainer;
  $mc->delete_key('species.classification');
  $mc->delete_key('species.common_name');
  $mc->delete_key('species.taxonomy_id');
  $mc->store_key_value('species.taxonomy_id',$node->node_id);
  if ($node->has_tag('genbank common name')) {
    $mc->store_key_value('species.common_name',$node->get_value_for_tag('genbank common name'));
    print "Loading species.common_name = ",$node->get_value_for_tag('genbank common name'),"\n";
  }
  if ($node->has_tag('genbank common name')) {
    print "Found species.genbank_common_name = ",$node->get_tagvalue('genbank common name'),"\n";
  }
  if ($node->has_tag('scientific name')) {
    print "Found species.scientific_name = ",$node->get_tagvalue('scientific name'),"\n";
  }
  if ($node->has_tag('common name')) {
    print "Found species.common_name = ",join (',',@{$node->get_all_values_for_tag('common name')}),"\n";
  }
  if ($node->has_tag('misspelling')) {
    print "Found species.alias = ",join (',',@{$node->get_all_values_for_tag('misspelling')}),"\n";
  }
  if ($node->has_tag('synonym')) {
    print "Found species.synonym = ", join (',',@{$node->get_all_values_for_tag('synonym')}),"\n";
  }

  # It is possible to remove the subspecies from the full species.classification list by commenting out the following line in
  #ensembl-compara/modules/Bio/EnsEMBL/Compara/NCBITaxon.pm
  #sub _to_text_classification :
  # unshift @text_classification, $subspecies if (defined $subspecies);
  my @classification = split(",",$node->classification(",", 1));
  LEVEL: foreach my $level (@classification) {
    print "Loading species.classification = ",$level,"\n";
    next LEVEL if ($level =~ /\s+/);
    $mc->store_key_value('species.classification',$level);
  }
  $self->{'root'} = $root;
}

sub connect_db{
  my $host       = shift;
  my $port       = shift;
  my $dbname     = shift;
  my $user       = shift;
  my $pass       = shift;
  my $dbObj;

  if($pass){
	$dbObj      = new Bio::EnsEMBL::Compara::DBSQL::DBAdaptor(
						     -host   => $host,
						     -port   => $port,
						     -user   => $user,
						     -dbname => $dbname,
						     -pass  => $pass
						    );
  }else{
	$dbObj      = new Bio::EnsEMBL::Compara::DBSQL::DBAdaptor(
							 -host    => $host,
							 -port    => $port,
							 -user    => $user,
							 -dbname  => $dbname
							);
  }
  if(!$dbObj){
    die "\ncould not connect to \"$dbname\".\n";
  }
  return $dbObj;
}