text:
- [When will Angular 2 be released?](#when-will-angular-2-be-released)
- [Seriously though, can I get an estimate?](#seriously-though-can-i-get-an-estimate)
- [Is it ready for me?](#is-it-ready-for-me)
- [Beta](#beta)
- [Stability/Bugginess](#stabilitybugginess)
    - [Known Regressions](#known-regressions)
- [API Stability](#api-stability)
- [Documentation](#documentation)
- [Ecosystem](#ecosystem)
- [Community/Blogs/Support/Etc...](#communityblogssupportetc)
- [Do I have to use Typescript?](#do-i-have-to-use-typescript)
- [Do I have to use a build system? What build system should I use?](#do-i-have-to-use-a-build-system-what-build-system-should-i-use)
- [Router](#router)
- [Internationalization](#internationalization)
- [Animation](#animation)
- [Twitter Bootstrap/Material Design](#twitter-bootstrapmaterial-design)

# When will Angular 2 be released?

When it's ready.

# Seriously though, can I get an estimate?

Any estimate given will be wrong. A better question to ask might be 'is it ready for me?'

# Is it ready for me?

That depends. Some Google teams are already using Angular 2 in production. Let's break it down.

# Beta

The Angular 2 team has stated that what they have released is ready, and they hope to minimize any further breaking changes.
Read the release announcement: http://angularjs.blogspot.ca/2015/12/angular-2-beta.html

# Stability/Bugginess

Angular 2 is very well tested~~, and does not exhibit a lot of bugs~~. Their git hub page shows compatibility for all the browsers they support, and they do benchmarks to test that they have not slowed things down. If you were to stick with a given release of Angular 2 in beta, you could go to production with it successfully. That said, there are some known regressions.

## Known Regressions

Here are a number of known issues/regressions that the community has found affecting whether you could go to production with a given version of Angular 2

- Since Beta 1
    - Attribute and class bindings throw an error when declared inside ngForm elements in Beta.1 [6374](https://github.com/angular/angular/issues/6374)
- Since Beta 2
    - "Attempt to use a dehydrated detector" in routes, triggered by eventEmitter [#6786](https://github.com/angular/angular/issues/6786)
- Since Beta 6
    - TypeError: viewFactory_<name>0 is not a function [#7037](https://github.com/angular/angular/issues/7037)
- Since Beta 16
    - Scheduler / tick not working for code with multiple async-events [#8251](https://github.com/angular/angular/issues/8251)
    - className property binding and "complex" expressions [#8244](https://github.com/angular/angular/issues/8244)
    - When injecting a non-imported class all of them are undefined [#8245](https://github.com/angular/angular/issues/8245)
    - ngFor + ChangeDetectionStrategy.OnPush = event handler not working [#8242](https://github.com/angular/angular/issues/8242)
    -  UMD bundle missing ng.platform.common export [#8299](https://github.com/angular/angular/issues/8299)

The currently recommended beta is the latest beta (16 at the time of this update).

# API Stability

With the release of beta, the Angular 2 team is hoping not to make breaking API changes. Some are likely to happen, but hopefully it should not require sweeping changes to your app. The only known proposed api breakages at this time are the router, and the animation API, as the current animation api is said to be temporary.

# Documentation

The general documentation and guide are very good and should be required reading. The API documentation is incomplete, and some examples are out of date. Overall the documentation is viable for everyday use.

# Ecosystem

The ecosystem is still just getting started. There will likely be a fair bit of work to catch up with Angular 1. That said, Angular 2 is largely free of the 'Angularisms' that made having Angular specific plugins a necessity. In many cases you can just use a vanilla js library with a thin component or directive wrapper you write yourself.

# Community/Blogs/Support/Etc...

The Angular 2 community is thriving, and a lot of information and tutorials can be found on the internet. The major problem is a lot of content covers the earlier alpha versions, and may not be directly applicable to the beta. The concepts are consistent from alpha to beta, and in most cases the only changes are small syntax changes.

If you need support, the best place to look is the Angular 2 gitter: https://gitter.im/angular/angular. There are lots of people there who can help you out.

# Do I have to use Typescript?

Technically, no. You can use whatever you like. It is strongly recommended that you use TypeScript though.

Documentation appears to be centered on TypeScript first, and the vast majority of examples are in it as well. Most users of Angular 2 have chosen to use Typescript, and that is what they will be familiar with.

The angular team is also developing a plugin for TypeScript that will add Intellisense type hinting for Angular 2 specific constructs, for any editor that supports TypeScript integration.

# Do I have to use a build system? What build system should I use?

It is STRONGLY RECOMMENDED that you use a build system such as Webpack or SystemJs.

Using a build system is not required or critical to the functioning of your Angular 2 app, however it is the long term plan, and to get all of the benefits of Angular 2 you will need a compile step. There are lots of bootstrap templates floating around github. Start your project with one of those and you won't have too much trouble.

- Webpack Basic Starter: https://github.com/ocombe/ng2-webpack
- Webpack Advanced Starter: https://github.com/AngularClass/angular2-webpack-starter
- SystemJs Basic Starter: https://github.com/pkozlowski-opensource/ng2-play
- SystemJs Advanced Starter: https://github.com/mgechev/angular2-seed

# Router

The Angular 2 router has some serious gaps at this time. Most of them have been worked around in some fashion in the Router section of this FAQ. It is stable, though there is a Proposed API change.

# Internationalization

As stated in the beta announcement, Internationalization is not yet complete. If you need this and are not willing to write your own internationalization module and port to the released one when it is done, Angular 2 may not be ready for you yet.

# Animation

Angular 2's animation module is very rudimentary and the release version is not yet ready. You will have to write your own animations, or wait.

# Twitter Bootstrap/Material Design

The Angular 2 specific version of Material is in alpha and available here: https://github.com/angular/material2

There is not an official version of Angular 2 bootstrap, but there are some repos you can find if you search. I suggest looking at [ng-bootstrap/core](https://github.com/ng-bootstrap/core)


text:
<?php

namespace Minsal\Sipernes\NotasBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;

class EnfCtlIntervencionAdmin extends Admin
{
    /**
     * @param DatagridMapper $datagridMapper
     */
protected $datagridValues = array(
        '_page' => 1, // Display the first page (default = 1)
        '_sort_order' => 'DESC', // Descendant ordering (default = 'ASC')
        '_sort_by' => 'fechaIngresoInterven' // name of the ordered field (default = the model id field, if any)
    );
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            //->add('id')
            ->add('idSubprotocolo', null, array('label' => 'Protocolo'))
            ->add('descripcionInterven', null, array('label' => 'Intervención'))
            ->add('estadoCltInterv', null, array('label' => 'Activo'))
            ->add('usuarioInterven', null, array('label' => 'Creado por'))
            ->add('fechaIngresoInterven', null, array('label' => 'Creado el'))
            //->add('fechaModificacionInterven')
        ;
    }

    /**
     * @param ListMapper $listMapper
     */
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            //->add('id')
            ->add('idSubprotocolo', null, array('label' => 'Protocolo'))
            ->add('descripcionInterven', null, array('label' => 'Intervención'))
            ->add('estadoCltInterv', null, array('label' => 'Activo'))
            ->add('usuarioInterven', null, array('label' => 'Creado por'))
            ->add('fechaIngresoInterven', null, array('label' => 'Creado el'))
            //->add('fechaModificacionInterven')
            ->add('_action', 'actions', array(
                'actions' => array(
                    'show' => array(),
                    'edit' => array(),
                )
            ))
        ;
    }

    /**
     * @param FormMapper $formMapper
     */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            //->add('id')
            ->add('idSubprotocolo', null, array('label' => 'Protocolo', 'required' => true))
            ->add('descripcionInterven', null, array('label' => 'Digite Intervención','required' => true))
            //->add('fechaIngresoInterven')
            //->add('usuarioInterven')
            //->add('fechaModificacionInterven')
            ->add('estadoCltInterv', null, array('label' => 'Activo','required' => true))
        ;
    }

    /**
     * @param ShowMapper $showMapper
     */
    protected function configureShowFields(ShowMapper $showMapper)
    {
        $showMapper
            //->add('id')
            ->add('idSubprotocolo', null, array('label' => 'Protocolo'))
            ->add('descripcionInterven', null, array('label' => 'Intervención'))
            ->add('estadoCltInterv', null, array('label' => 'Activo'))
            ->add('usuarioInterven', null, array('label' => 'Creado por'))
            ->add('fechaIngresoInterven', null, array('label' => 'Creado el'))
            //->add('fechaModificacionInterven')

        ;
    }

     public function getTemplate($name) {
        switch ($name) {
            case 'edit':
                return 'MinsalSipernesNotasBundle:CtlIntervencionRegistro:ctlintervencion.html.twig';
                break;
            //case 'create':
            //return 'MinsalSipernesActividadBundle:ActividadRegistro:reporte_prueba1.html.twig';
            //break;
            default:
                return parent::getTemplate($name);
                break;
        }
    }

     /*
     * Método que se ejecuta antes de realizar una inserción.
     * Recibe como parámetro una entidad; en este caso de tipo EnfCtlIntervencion
     * con los valores del formulario.
     *
     */

    public function prePersist($EnfCtlIntervencion) {
        $user = $this->getConfigurationPool()->getContainer()->get('security.context')->getToken()->getUsername();
        $EnfCtlIntervencion->setusuarioInterven($user);
        $EnfCtlIntervencion->setfechaIngresoInterven(new \DateTime());
    }

     /*
     * Método que se ejecuta antes de realizar una actualización.
     * Recibe como parámetro una entidad; en este caso de tipo EnfCtlIntervencion
     * con los valores del formulario.
     *
     */
    public function preUpdate($EnfCtlIntervencion) {
        $user = $this->getConfigurationPool()->getContainer()->get('security.context')->getToken()->getUsername();
        $EnfCtlIntervencion->setusuarioInterven($user);
        $EnfCtlIntervencion->setfechaModificacionInterven(new \DateTime());
    }

}

redpajama_set_name: RedPajamaGithub


text:
test:
	python3 -m unittest discover -s tests/


text:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>box-cirrus-agent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>box-cirrus-agent</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>com.cirrus</groupId>
        <artifactId>cirrus-agents</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>com.cirrus</groupId>
            <artifactId>cirrus-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>net.box</groupId>
            <artifactId>boxjavalibv2</artifactId>
            <version>2.2.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.4.0</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Vendor>Antoine Jullien</Bundle-Vendor>
                        <Storage-Service-Name>${artifactId}</Storage-Service-Name>
                        <Storage-Service-Version>1.0</Storage-Service-Version>
                        <Storage-Service-Class>com.cirrus.server.osgi.service.box.BoxStorageService</Storage-Service-Class>
                        <Storage-Service-Vendor>Box</Storage-Service-Vendor>
                        <Storage-Service-Authentication-Mode>ACCESS_KEY_PASSWORD</Storage-Service-Authentication-Mode>
                        <Import-Package>com.cirrus.server.osgi.extension.*, com.cirrus.model.data.*,
                            com.cirrus.agent.authentication.*,com.cirrus.server.*</Import-Package>
                        <Export-Package>com.box.*</Export-Package>
                        <Embed-Dependency>*;scope=runtime;inline=true</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>


text:
import os

def snippet_exists_test():
	os.system("python regional.py example.rb")
	assert(os.path.isfile("ReopenExistingClass.snippet.rb"))

def extracts_correct_region_test():
	os.system("python regional.py example.rb")
	expected_contents = "class Doofus\n\tdef self.greet_differently\n\t\tgreet\n\t\tputs \"... my friend\"\n\tend\nend\n"
	with open("ReopenExistingClass.snippet.rb") as f:
		actual_contents = "".join(f.readlines())
	assert(expected_contents == actual_contents)

def handles_multiple_dots_test():
	os.system("python regional.py First.Next.Last.cpp")
	assert(os.path.isfile("MultipleDotsWork.snippet.cpp"))


text:
<?php

namespace SiteMap\Test\Policy;

use SiteMap\Http\Url;
use SiteMap\Policy\UniqueUrlPolicy;

class UniqueUrlPolicyTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var UniqueUrlPolicy
     */
    private $policy;

    public function testSameInstance()
    {
        $this->policy = new UniqueUrlPolicy();
        $data = $this->urlsProvider();

        foreach ($data as $toTest) {
            $newUrl = new Url($toTest[0]);
            $result = $this->policy->shouldVisit($newUrl);
            $this->assertEquals($toTest[1], $result);
        }
    }

    public function urlsProvider()
    {
        return [
            ['http://google.com', true],
            ['http://google.com', false],
            ['http://google.com', false],
            ['http://google.com', false],
            ['http://yahoo.com', true],
        ];
    }

}


text:
<?xml version="1.0" encoding="utf-8"?>
<!--
The iRemember source code (henceforth referred to as "iRemember") is
copyrighted by Mike Walker, Adam Porter, Doug Schmidt, and Jules White
at Vanderbilt University and the University of Maryland, Copyright (c)
2014, all rights reserved.  Since iRemember is open-source, freely
available software, you are free to use, modify, copy, and
distribute -perpetually and irrevocably- the source code and object code
produced from the source, as well as copy and distribute modified
versions of this software. You must, however, include this copyright
statement along with any code built using iRemember that you release. No
copyright statement needs to be provided if you just ship binary
executables of your software products.

You can use iRemember software in commercial and/or binary software
releases and are under no obligation to redistribute any of your source
code that is built using the software. Note, however, that you may not
misappropriate the iRemember code, such as copyrighting it yourself or
claiming authorship of the iRemember software code, in a way that will
prevent the software from being distributed freely using an open-source
development model. You needn't inform anyone that you're using iRemember
software in your software, though we encourage you to let us know so we
can promote your project in our success stories.

iRemember is provided as is with no warranties of any kind, including
the warranties of design, merchantability, and fitness for a particular
purpose, noninfringement, or arising from a course of dealing, usage or
trade practice.  Vanderbilt University and University of Maryland, their
employees, and students shall have no liability with respect to the
infringement of copyrights, trade secrets or any patents by DOC software
or any part thereof.  Moreover, in no event will Vanderbilt University,
University of Maryland, their employees, or students be liable for any
lost revenue or profits or other special, indirect and consequential
damages.

iRemember is provided with no support and without any obligation on the
part of Vanderbilt University and University of Maryland, their
employees, or students to assist in its use, correction, modification,
or enhancement.

The names Vanderbilt University and University of Maryland may not be
used to endorse or promote products or services derived from this source
without express written permission from Vanderbilt University or
University of Maryland. This license grants no permission to call
products or services derived from the iRemember source, nor does it
grant permission for the name Vanderbilt University or
University of Maryland to appear in their names.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/storyListViewLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- Row for Buttons -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="3dp" >

        <Button
            android:id="@+id/story_listview_create"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:onClick="createButtonClicked"
            android:text="@string/story_list_button_label_add" />

        <Button
            android:id="@+id/story_listview_refresh"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:onClick="refreshButtonClicked"
            android:text="@string/story_list_button_label_refresh" />

        <Button
            android:id="@+id/login_button"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:onClick="loginButtonClicked"
            android:text="Login" />
    </LinearLayout>

    <EditText
        android:id="@+id/story_listview_tags_filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/story_list_filter_hint" >

        <requestFocus />
    </EditText>

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>


text:
from rdflib.graph import ConjunctiveGraph
from rdflib.term import URIRef, Literal
from StringIO import StringIO
from datetime import date
#=======================================================================

testRdf = """
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
    @prefix : <tag://example.org,2007/literals-test#> .

    <http://example.org/thing>
        :plain "plain";
        :integer 1;
        :float 1.1;
        :string "string"^^xsd:string;
        :date "2007-04-28"^^xsd:date;
        rdfs:label "Thing"@en, "Sak"@sv .
"""
graph = ConjunctiveGraph()
graph.load(StringIO(testRdf), format='n3')

PROLOGUE = """
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX t: <tag://example.org,2007/literals-test#>
"""

thing = URIRef("http://example.org/thing")

SPARQL = PROLOGUE+" SELECT ?uri WHERE { ?uri %s . } "
TEST_DATA = [
    ('plain', SPARQL % 't:plain "plain"', [thing]),
    ('integer', SPARQL % 't:integer 1', [thing]),
    ('float', SPARQL % 't:float 1.1', [thing]),
    ('langlabel_en', SPARQL % 'rdfs:label "Thing"@en', [thing]),
    ('langlabel_sv', SPARQL % 'rdfs:label "Sak"@sv', [thing]),
    ('string', SPARQL % 't:string "string"^^xsd:string', [thing]),
    ('date', SPARQL % 't:date "2007-04-28"^^xsd:date', [thing]),
]

def assert_equal(name, sparql, real, expected):
    assert real == expected, 'Failed test "%s":\n%s\n, expected\n\t%s\nand got\n\t%s\n'\
            % (name, sparql, expected, real)

def test_generator():
    for name, sparql, expected in TEST_DATA:
        res = graph.query(sparql)
        #print res.serialize('json')
        yield assert_equal, name, sparql, res.selected, expected

test_generator.known_issue = True
test_generator.sparql = True

#=======================================================================

if __name__ == '__main__':
    from sys import argv
    name, sparql, expected = TEST_DATA[int(argv[1])]
    res = graph.query(sparql)
    assert_equal(name, sparql, res.selected, expected)


text:
import os
import random
import re
import shutil
import tempfile
import threading
import time

from cassandra import ConsistencyLevel
from cassandra.concurrent import execute_concurrent_with_args
from ccmlib.node import NodeError

from dtest import DISABLE_VNODES, Tester, debug, create_ks, create_cf
from tools.assertions import (assert_almost_equal, assert_bootstrap_state, assert_not_running,
                              assert_one, assert_stderr_clean)
from tools.data import query_c1c2
from tools.decorators import no_vnodes, since
from tools.intervention import InterruptBootstrap, KillOnBootstrap
from tools.misc import new_node
from tools.misc import generate_ssl_stores

class BaseBootstrapTest(Tester):
    __test__ = False

    allow_log_errors = True
    ignore_log_patterns = (
        # This one occurs when trying to send the migration to a
        # node that hasn't started yet, and when it does, it gets
        # replayed and everything is fine.
        r'Can\'t send migration request: node.*is down',
        # ignore streaming error during bootstrap
        r'Exception encountered during startup',
        r'Streaming error occurred'
    )

    def _base_bootstrap_test(self, bootstrap=None, bootstrap_from_version=None,
                             enable_ssl=None):
        def default_bootstrap(cluster, token):
            node2 = new_node(cluster)
            node2.set_configuration_options(values={'initial_token': token})
            node2.start(wait_for_binary_proto=True)
            return node2

        if bootstrap is None:
            bootstrap = default_bootstrap

        cluster = self.cluster

        if enable_ssl:
            debug("***using internode ssl***")
            generate_ssl_stores(self.test_path)
            cluster.enable_internode_ssl(self.test_path)

        tokens = cluster.balanced_tokens(2)
        cluster.set_configuration_options(values={'num_tokens': 1})

        debug("[node1, node2] tokens: %r" % (tokens,))

        keys = 10000

        # Create a single node cluster
        cluster.populate(1)
        node1 = cluster.nodelist()[0]
        if bootstrap_from_version:
            debug("starting source node on version {}".format(bootstrap_from_version))
            node1.set_install_dir(version=bootstrap_from_version)
        node1.set_configuration_options(values={'initial_token': tokens[0]})
        cluster.start(wait_other_notice=True)

        session = self.patient_cql_connection(node1)
        create_ks(session, 'ks', 1)
        create_cf(session, 'cf', columns={'c1': 'text', 'c2': 'text'})

        # record the size before inserting any of our own data
        empty_size = node1.data_size()
        debug("node1 empty size : %s" % float(empty_size))

        insert_statement = session.prepare("INSERT INTO ks.cf (key, c1, c2) VALUES (?, 'value1', 'value2')")
        execute_concurrent_with_args(session, insert_statement, [['k%d' % k] for k in range(keys)])

        node1.flush()
        node1.compact()
        initial_size = node1.data_size()
        debug("node1 size before bootstrapping node2: %s" % float(initial_size))

        # Reads inserted data all during the bootstrap process. We shouldn't
        # get any error
        reader = self.go(lambda _: query_c1c2(session, random.randint(0, keys - 1), ConsistencyLevel.ONE))

        # Bootstrapping a new node in the current version
        node2 = bootstrap(cluster, tokens[1])
        node2.compact()

        reader.check()
        node1.cleanup()
        debug("node1 size after cleanup: %s" % float(node1.data_size()))
        node1.compact()
        debug("node1 size after compacting: %s" % float(node1.data_size()))
        time.sleep(.5)
        reader.check()

        debug("node2 size after compacting: %s" % float(node2.data_size()))

        size1 = float(node1.data_size())
        size2 = float(node2.data_size())
        assert_almost_equal(size1, size2, error=0.3)
        assert_almost_equal(float(initial_size - empty_size), 2 * (size1 - float(empty_size)))

        assert_bootstrap_state(self, node2, 'COMPLETED')
        if bootstrap_from_version:
            self.assertTrue(node2.grep_log('does not support keep-alive', filename='debug.log'))

class TestBootstrap(BaseBootstrapTest):
    __test__ = True

    @no_vnodes()
    def simple_bootstrap_test_with_ssl(self):
        self._base_bootstrap_test(enable_ssl=True)

    @no_vnodes()
    def simple_bootstrap_test(self):
        self._base_bootstrap_test()

    @no_vnodes()
    def bootstrap_on_write_survey_test(self):
        def bootstrap_on_write_survey_and_join(cluster, token):
            node2 = new_node(cluster)
            node2.set_configuration_options(values={'initial_token': token})
            node2.start(jvm_args=["-Dcassandra.write_survey=true"], wait_for_binary_proto=True)

            self.assertTrue(len(node2.grep_log('Startup complete, but write survey mode is active, not becoming an active ring member.')))
            assert_bootstrap_state(self, node2, 'IN_PROGRESS')

            node2.nodetool("join")
            self.assertTrue(len(node2.grep_log('Leaving write survey mode and joining ring at operator request')))
            return node2

        self._base_bootstrap_test(bootstrap_on_write_survey_and_join)

    @since('3.10')
    @no_vnodes()
    def simple_bootstrap_test_small_keepalive_period(self):
        """
        @jira_ticket CASSANDRA-11841
        Test that bootstrap completes if it takes longer than streaming_socket_timeout_in_ms or
        2*streaming_keep_alive_period_in_secs to receive a single sstable
        """
        cluster = self.cluster
        cluster.set_configuration_options(values={'streaming_socket_timeout_in_ms': 1000,
                                                  'streaming_keep_alive_period_in_secs': 2})

        # Create a single node cluster
        cluster.populate(1)
        node1 = cluster.nodelist()[0]

        debug("Setting up byteman on {}".format(node1.name))
        # set up byteman
        node1.byteman_port = '8100'
        node1.import_config_files()

        cluster.start(wait_other_notice=True)

        # Create more than one sstable larger than 1MB
        node1.stress(['write', 'n=1K', '-rate', 'threads=8', '-schema',
                      'compaction(strategy=SizeTieredCompactionStrategy, enabled=false)'])
        cluster.flush()

        debug("Submitting byteman script to {} to".format(node1.name))
        # Sleep longer than streaming_socket_timeout_in_ms to make sure the node will not be killed
        node1.byteman_submit(['./byteman/stream_5s_sleep.btm'])

        # Bootstraping a new node with very small streaming_socket_timeout_in_ms
        node2 = new_node(cluster)
        node2.start(wait_for_binary_proto=True)

        # Shouldn't fail due to streaming socket timeout timeout
        assert_bootstrap_state(self, node2, 'COMPLETED')

        for node in cluster.nodelist():
            self.assertTrue(node.grep_log('Scheduling keep-alive task with 2s period.', filename='debug.log'))
            self.assertTrue(node.grep_log('Sending keep-alive', filename='debug.log'))
            self.assertTrue(node.grep_log('Received keep-alive', filename='debug.log'))

    def simple_bootstrap_test_nodata(self):
        """
        @jira_ticket CASSANDRA-11010
        Test that bootstrap completes if streaming from nodes with no data
        """

        cluster = self.cluster
        # Create a two-node cluster
        cluster.populate(2)
        cluster.start(wait_other_notice=True)

        # Bootstrapping a new node
        node3 = new_node(cluster)
        node3.start(wait_for_binary_proto=True, wait_other_notice=True)

        assert_bootstrap_state(self, node3, 'COMPLETED')

    def read_from_bootstrapped_node_test(self):
        """
        Test bootstrapped node sees existing data
        @jira_ticket CASSANDRA-6648
        """
        cluster = self.cluster
        cluster.populate(3)
        cluster.start()

        node1 = cluster.nodes['node1']
        node1.stress(['write', 'n=10K', 'no-warmup', '-rate', 'threads=8', '-schema', 'replication(factor=2)'])

        session = self.patient_cql_connection(node1)
        stress_table = 'keyspace1.standard1'
        original_rows = list(session.execute("SELECT * FROM %s" % (stress_table,)))

        node4 = new_node(cluster)
        node4.start(wait_for_binary_proto=True)

        session = self.patient_exclusive_cql_connection(node4)
        new_rows = list(session.execute("SELECT * FROM %s" % (stress_table,)))
        self.assertEquals(original_rows, new_rows)

    def consistent_range_movement_true_with_replica_down_should_fail_test(self):
        self._bootstrap_test_with_replica_down(True)

    def consistent_range_movement_false_with_replica_down_should_succeed_test(self):
        self._bootstrap_test_with_replica_down(False)

    def consistent_range_movement_true_with_rf1_should_fail_test(self):
        self._bootstrap_test_with_replica_down(True, rf=1)

    def consistent_range_movement_false_with_rf1_should_succeed_test(self):
        self._bootstrap_test_with_replica_down(False, rf=1)

    def _bootstrap_test_with_replica_down(self, consistent_range_movement, rf=2):
        """
        Test to check consistent bootstrap will not succeed when there are insufficient replicas
        @jira_ticket CASSANDRA-11848
        """
        cluster = self.cluster

        cluster.populate(2)
        node1, node2 = cluster.nodelist()

        node3_token = None
        # Make token assignment deterministic
        if DISABLE_VNODES:
            cluster.set_configuration_options(values={'num_tokens': 1})
            tokens = cluster.balanced_tokens(3)
            debug("non-vnode tokens: %r" % (tokens,))
            node1.set_configuration_options(values={'initial_token': tokens[0]})
            node2.set_configuration_options(values={'initial_token': tokens[2]})
            node3_token = tokens[1]  # Add node 3 between node1 and node2

        cluster.start()

        node1.stress(['write', 'n=10K', 'no-warmup', '-rate', 'threads=8', '-schema', 'replication(factor={})'.format(rf)])

        # change system_auth keyspace to 2 (default is 1) to avoid
        # "Unable to find sufficient sources for streaming" warning
        if cluster.cassandra_version() >= '2.2.0':
            session = self.patient_cql_connection(node1)
            session.execute("""
                ALTER KEYSPACE system_auth
                    WITH replication = {'class':'SimpleStrategy', 'replication_factor':2};
            """)

        # Stop node2, so node3 will not be able to perform consistent range movement
        node2.stop(wait_other_notice=True)

        successful_bootstrap_expected = not consistent_range_movement

        node3 = new_node(cluster, token=node3_token)
        node3.start(wait_for_binary_proto=successful_bootstrap_expected, wait_other_notice=successful_bootstrap_expected,
                    jvm_args=["-Dcassandra.consistent.rangemovement={}".format(consistent_range_movement)])

        if successful_bootstrap_expected:
            # with rf=1 and cassandra.consistent.rangemovement=false, missing sources are ignored
            if not consistent_range_movement and rf == 1:
                node3.watch_log_for("Unable to find sufficient sources for streaming range")
            self.assertTrue(node3.is_running())
            assert_bootstrap_state(self, node3, 'COMPLETED')
        else:
            if consistent_range_movement:
                node3.watch_log_for("A node required to move the data consistently is down")
            else:
                node3.watch_log_for("Unable to find sufficient sources for streaming range")
            assert_not_running(node3)

    @since('2.2')
    def resumable_bootstrap_test(self):
        """
        Test resuming bootstrap after data streaming failure
        """

        cluster = self.cluster
        cluster.populate(2)

        node1 = cluster.nodes['node1']
        # set up byteman
        node1.byteman_port = '8100'
        node1.import_config_files()

        cluster.start(wait_other_notice=True)
        # kill stream to node3 in the middle of streaming to let it fail
        node1.byteman_submit(['./byteman/stream_failure.btm'])
        node1.stress(['write', 'n=1K', 'no-warmup', 'cl=TWO', '-schema', 'replication(factor=2)', '-rate', 'threads=50'])
        cluster.flush()

        # start bootstrapping node3 and wait for streaming
        node3 = new_node(cluster)
        node3.start(wait_other_notice=False, wait_for_binary_proto=True)

        # wait for node3 ready to query
        node3.watch_log_for("Starting listening for CQL clients")
        mark = node3.mark_log()
        # check if node3 is still in bootstrap mode
        assert_bootstrap_state(self, node3, 'IN_PROGRESS')

        # bring back node1 and invoke nodetool bootstrap to resume bootstrapping
        node3.nodetool('bootstrap resume')

        node3.watch_log_for("Resume complete", from_mark=mark)
        assert_bootstrap_state(self, node3, 'COMPLETED')

        # cleanup to guarantee each node will only have sstables of its ranges
        cluster.cleanup()

        debug("Check data is present")
        # Let's check stream bootstrap completely transferred data
        stdout, stderr, _ = node3.stress(['read', 'n=1k', 'no-warmup', '-schema', 'replication(factor=2)', '-rate', 'threads=8'])

        if stdout is not None:
            self.assertNotIn("FAILURE", stdout)

    @since('2.2')
    def bootstrap_with_reset_bootstrap_state_test(self):
        """Test bootstrap with resetting bootstrap progress"""

        cluster = self.cluster
        cluster.set_configuration_options(values={'stream_throughput_outbound_megabits_per_sec': 1})
        cluster.populate(2).start(wait_other_notice=True)

        node1 = cluster.nodes['node1']
        node1.stress(['write', 'n=100K', '-schema', 'replication(factor=2)'])
        node1.flush()

        # kill node1 in the middle of streaming to let it fail
        t = InterruptBootstrap(node1)
        t.start()

        # start bootstrapping node3 and wait for streaming
        node3 = new_node(cluster)
        try:
            node3.start()
        except NodeError:
            pass  # node doesn't start as expected
        t.join()
        node1.start()

        # restart node3 bootstrap with resetting bootstrap progress
        node3.stop()
        mark = node3.mark_log()
        node3.start(jvm_args=["-Dcassandra.reset_bootstrap_progress=true"])
        # check if we reset bootstrap state
        node3.watch_log_for("Resetting bootstrap progress to start fresh", from_mark=mark)
        # wait for node3 ready to query
        node3.wait_for_binary_interface(from_mark=mark)

        # check if 2nd bootstrap succeeded
        assert_bootstrap_state(self, node3, 'COMPLETED')

    def manual_bootstrap_test(self):
        """
            Test adding a new node and bootstrapping it manually. No auto_bootstrap.
            This test also verify that all data are OK after the addition of the new node.
            @jira_ticket CASSANDRA-9022
        """
        cluster = self.cluster
        cluster.populate(2).start(wait_other_notice=True)
        (node1, node2) = cluster.nodelist()

        node1.stress(['write', 'n=1K', 'no-warmup', '-schema', 'replication(factor=2)',
                      '-rate', 'threads=1', '-pop', 'dist=UNIFORM(1..1000)'])

        session = self.patient_exclusive_cql_connection(node2)
        stress_table = 'keyspace1.standard1'

        original_rows = list(session.execute("SELECT * FROM %s" % stress_table))

        # Add a new node
        node3 = new_node(cluster, bootstrap=False)
        node3.start(wait_for_binary_proto=True)
        node3.repair()
        node1.cleanup()

        current_rows = list(session.execute("SELECT * FROM %s" % stress_table))
        self.assertEquals(original_rows, current_rows)

    def local_quorum_bootstrap_test(self):
        """
        Test that CL local_quorum works while a node is bootstrapping.
        @jira_ticket CASSANDRA-8058
        """

        cluster = self.cluster
        cluster.populate([1, 1])
        cluster.start()

        node1 = cluster.nodes['node1']
        yaml_config = """
        # Create the keyspace and table
        keyspace: keyspace1
        keyspace_definition: |
          CREATE KEYSPACE keyspace1 WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 1, 'dc2': 1};
        table: users
        table_definition:
          CREATE TABLE users (
            username text,
            first_name text,
            last_name text,
            email text,
            PRIMARY KEY(username)
          ) WITH compaction = {'class':'SizeTieredCompactionStrategy'};
        insert:
          partitions: fixed(1)
          batchtype: UNLOGGED
        queries:
          read:
            cql: select * from users where username = ?
            fields: samerow
        """
        with tempfile.NamedTemporaryFile(mode='w+') as stress_config:
            stress_config.write(yaml_config)
            stress_config.flush()
            node1.stress(['user', 'profile=' + stress_config.name, 'n=2M', 'no-warmup',
                          'ops(insert=1)', '-rate', 'threads=50'])

            node3 = new_node(cluster, data_center='dc2')
            node3.start(no_wait=True)
            time.sleep(3)

            out, err, _ = node1.stress(['user', 'profile=' + stress_config.name, 'ops(insert=1)',
                                        'n=500K', 'no-warmup', 'cl=LOCAL_QUORUM',
                                        '-rate', 'threads=5',
                                        '-errors', 'retries=2'])

        debug(out)
        assert_stderr_clean(err)
        regex = re.compile("Operation.+error inserting key.+Exception")
        failure = regex.search(out)
        self.assertIsNone(failure, "Error during stress while bootstrapping")

    def shutdown_wiped_node_cannot_join_test(self):
        self._wiped_node_cannot_join_test(gently=True)

    def killed_wiped_node_cannot_join_test(self):
        self._wiped_node_cannot_join_test(gently=False)

    def _wiped_node_cannot_join_test(self, gently):
        """
        @jira_ticket CASSANDRA-9765
        Test that if we stop a node and wipe its data then the node cannot join
        when it is not a seed. Test both a nice shutdown or a forced shutdown, via
        the gently parameter.
        """
        cluster = self.cluster
        cluster.populate(3)
        cluster.start(wait_for_binary_proto=True)

        stress_table = 'keyspace1.standard1'

        # write some data
        node1 = cluster.nodelist()[0]
        node1.stress(['write', 'n=10K', 'no-warmup', '-rate', 'threads=8'])

        session = self.patient_cql_connection(node1)
        original_rows = list(session.execute("SELECT * FROM {}".format(stress_table,)))

        # Add a new node, bootstrap=True ensures that it is not a seed
        node4 = new_node(cluster, bootstrap=True)
        node4.start(wait_for_binary_proto=True)

        session = self.patient_cql_connection(node4)
        self.assertEquals(original_rows, list(session.execute("SELECT * FROM {}".format(stress_table,))))

        # Stop the new node and wipe its data
        node4.stop(gently=gently)
        self._cleanup(node4)
        # Now start it, it should not be allowed to join.
        mark = node4.mark_log()
        node4.start(no_wait=True, wait_other_notice=False)
        node4.watch_log_for("A node with address /127.0.0.4 already exists, cancelling join", from_mark=mark)

    def decommissioned_wiped_node_can_join_test(self):
        """
        @jira_ticket CASSANDRA-9765
        Test that if we decommission a node and then wipe its data, it can join the cluster.
        """
        cluster = self.cluster
        cluster.populate(3)
        cluster.start(wait_for_binary_proto=True)

        stress_table = 'keyspace1.standard1'

        # write some data
        node1 = cluster.nodelist()[0]
        node1.stress(['write', 'n=10K', 'no-warmup', '-rate', 'threads=8'])

        session = self.patient_cql_connection(node1)
        original_rows = list(session.execute("SELECT * FROM {}".format(stress_table,)))

        # Add a new node, bootstrap=True ensures that it is not a seed
        node4 = new_node(cluster, bootstrap=True)
        node4.start(wait_for_binary_proto=True, wait_other_notice=True)

        session = self.patient_cql_connection(node4)
        self.assertEquals(original_rows, list(session.execute("SELECT * FROM {}".format(stress_table,))))

        # Decommission the new node and wipe its data
        node4.decommission()
        node4.stop()
        self._cleanup(node4)
        # Now start it, it should be allowed to join
        mark = node4.mark_log()
        node4.start(wait_other_notice=True)
        node4.watch_log_for("JOINING:", from_mark=mark)

    def decommissioned_wiped_node_can_gossip_to_single_seed_test(self):
        """
        @jira_ticket CASSANDRA-8072
        @jira_ticket CASSANDRA-8422
        Test that if we decommission a node, kill it and wipe its data, it can join a cluster with a single
        seed node.
        """
        cluster = self.cluster
        cluster.populate(1)
        cluster.start(wait_for_binary_proto=True)

        node1 = cluster.nodelist()[0]
        # Add a new node, bootstrap=True ensures that it is not a seed
        node2 = new_node(cluster, bootstrap=True)
        node2.start(wait_for_binary_proto=True, wait_other_notice=True)

        session = self.patient_cql_connection(node1)

        if cluster.version() >= '2.2':
            # reduce system_distributed RF to 2 so we don't require forceful decommission
            session.execute("ALTER KEYSPACE system_distributed WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':'1'};")

        session.execute("ALTER KEYSPACE system_traces WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':'1'};")

        # Decommision the new node and kill it
        debug("Decommissioning & stopping node2")
        node2.decommission()
        node2.stop(wait_other_notice=False)

        # Wipe its data
        for data_dir in node2.data_directories():
            debug("Deleting {}".format(data_dir))
            shutil.rmtree(data_dir)

        commitlog_dir = os.path.join(node2.get_path(), 'commitlogs')
        debug("Deleting {}".format(commitlog_dir))
        shutil.rmtree(commitlog_dir)

        # Now start it, it should be allowed to join
        mark = node2.mark_log()
        debug("Restarting wiped node2")
        node2.start(wait_other_notice=False)
        node2.watch_log_for("JOINING:", from_mark=mark)

    def failed_bootstrap_wiped_node_can_join_test(self):
        """
        @jira_ticket CASSANDRA-9765
        Test that if a node fails to bootstrap, it can join the cluster even if the data is wiped.
        """
        cluster = self.cluster
        cluster.populate(1)
        cluster.set_configuration_options(values={'stream_throughput_outbound_megabits_per_sec': 1})
        cluster.start(wait_for_binary_proto=True)

        stress_table = 'keyspace1.standard1'

        # write some data, enough for the bootstrap to fail later on
        node1 = cluster.nodelist()[0]
        node1.stress(['write', 'n=100K', 'no-warmup', '-rate', 'threads=8'])
        node1.flush()

        session = self.patient_cql_connection(node1)
        original_rows = list(session.execute("SELECT * FROM {}".format(stress_table,)))

        # Add a new node, bootstrap=True ensures that it is not a seed
        node2 = new_node(cluster, bootstrap=True)

        # kill node2 in the middle of bootstrap
        t = KillOnBootstrap(node2)
        t.start()

        node2.start()
        t.join()
        self.assertFalse(node2.is_running())

        # wipe any data for node2
        self._cleanup(node2)
        # Now start it again, it should be allowed to join
        mark = node2.mark_log()
        node2.start(wait_other_notice=True)
        node2.watch_log_for("JOINING:", from_mark=mark)

    @since('2.1.1')
    def simultaneous_bootstrap_test(self):
        """
        Attempt to bootstrap two nodes at once, to assert the second bootstrapped node fails, and does not interfere.

        Start a one node cluster and run a stress write workload.
        Start up a second node, and wait for the first node to detect it has joined the cluster.
        While the second node is bootstrapping, start a third node. This should fail.

        @jira_ticket CASSANDRA-7069
        @jira_ticket CASSANDRA-9484
        """

        bootstrap_error = "Other bootstrapping/leaving/moving nodes detected," \
                          " cannot bootstrap while cassandra.consistent.rangemovement is true"

        cluster = self.cluster
        cluster.populate(1)
        cluster.start(wait_for_binary_proto=True)

        node1, = cluster.nodelist()

        node1.stress(['write', 'n=500K', 'no-warmup', '-schema', 'replication(factor=1)',
                      '-rate', 'threads=10'])

        node2 = new_node(cluster)
        node2.start(wait_other_notice=True)

        node3 = new_node(cluster, remote_debug_port='2003')
        try:
            node3.start(wait_other_notice=False, verbose=False)
        except NodeError:
            pass  # node doesn't start as expected

        time.sleep(.5)
        node2.watch_log_for("Starting listening for CQL clients")

        node3.watch_log_for(bootstrap_error)

        session = self.patient_exclusive_cql_connection(node2)

        # Repeat the select count(*) query, to help catch
        # bugs like 9484, where count(*) fails at higher
        # data loads.
        for _ in xrange(5):
            assert_one(session, "SELECT count(*) from keyspace1.standard1", [500000], cl=ConsistencyLevel.ONE)

    def test_cleanup(self):
        """
        @jira_ticket CASSANDRA-11179
        Make sure we remove processed files during cleanup
        """
        cluster = self.cluster
        cluster.set_configuration_options(values={'concurrent_compactors': 4})
        cluster.populate(1)
        cluster.start(wait_for_binary_proto=True)
        node1, = cluster.nodelist()
        for x in xrange(0, 5):
            node1.stress(['write', 'n=100k', 'no-warmup', '-schema', 'compaction(strategy=SizeTieredCompactionStrategy,enabled=false)', 'replication(factor=1)', '-rate', 'threads=10'])
            node1.flush()
        node2 = new_node(cluster)
        node2.start(wait_for_binary_proto=True, wait_other_notice=True)
        event = threading.Event()
        failed = threading.Event()
        jobs = 1
        thread = threading.Thread(target=self._monitor_datadir, args=(node1, event, len(node1.get_sstables("keyspace1", "standard1")), jobs, failed))
        thread.start()
        node1.nodetool("cleanup -j {} keyspace1 standard1".format(jobs))
        event.set()
        thread.join()
        self.assertFalse(failed.is_set())

    def _monitor_datadir(self, node, event, basecount, jobs, failed):
        while True:
            sstables = [s for s in node.get_sstables("keyspace1", "standard1") if "tmplink" not in s]
            debug("---")
            for sstable in sstables:
                debug(sstable)
            if len(sstables) > basecount + jobs:
                debug("Current count is {}, basecount was {}".format(len(sstables), basecount))
                failed.set()
                return
            if event.is_set():
                return
            time.sleep(.1)

    def _cleanup(self, node):
        commitlog_dir = os.path.join(node.get_path(), 'commitlogs')
        for data_dir in node.data_directories():
            debug("Deleting {}".format(data_dir))
            shutil.rmtree(data_dir)
        shutil.rmtree(commitlog_dir)


text:
"""
REST API data sources model resource.

.. moduleauthor:: Martijn Vermaat <martijn@vermaat.name>

.. Licensed under the MIT license, see the LICENSE file.
"""

import os

from flask import current_app, g, request, send_from_directory, url_for

from ...models import DataSource, DATA_SOURCE_FILETYPES
from ..security import has_role, is_user, owns_data_source, require_user
from .base import ModelResource
from .users import UsersResource

class DataSourcesResource(ModelResource):
    """
    Data source resources model data from files that are either uploaded to
    the server by the user or generated on the server.

    The actual data is modeled by the :ref:`blob
    <api-resources-data-sources-blobs>` subresource type.
    """
    model = DataSource
    instance_name = 'data_source'
    instance_type = 'data_source'

    views = ['list', 'get', 'add', 'edit', 'delete', 'data']

    embeddable = {'user': UsersResource}
    filterable = {'user': {'type': 'user'}}
    orderable = ['name', 'filetype', 'added']

    list_ensure_conditions = [has_role('admin'), is_user]
    list_ensure_options = {'satisfy': any}

    get_ensure_conditions = [has_role('admin'), owns_data_source]
    get_ensure_options = {'satisfy': any}

    add_ensure_conditions = []
    add_schema = {'name': {'type': 'string', 'maxlength': 200, 'required': True},
                  'filetype': {'type': 'string', 'allowed': DATA_SOURCE_FILETYPES,
                               'required': True},
                  'gzipped': {'type': 'boolean'},
                  'local_file': {'type': 'string', 'maxlength': 200}}

    edit_ensure_conditions = [has_role('admin'), owns_data_source]
    edit_ensure_options = {'satisfy': any}
    edit_schema = {'name': {'type': 'string', 'maxlength': 200}}

    data_rule = '/<int:data_source>/data'
    data_ensure_conditions = [has_role('admin'), owns_data_source]
    data_ensure_options = {'satisfy': any}
    data_schema = {'data_source': {'type': 'data_source', 'id': True}}

    def register_views(self):
        super(DataSourcesResource, self).register_views()
        if 'data' in self.views:
            self.register_view('data')

    @classmethod
    def serialize(cls, instance, embed=None):
        """
        A data source is represented as an object with the following fields:

        **uri** (`uri`)
          URI for this resource.

        **added** (`string`)
          Date and time this data source was added, see :ref:`api-datetime`.

        **gzipped** (`boolean`)
          Whether or not the data is compressed using gzip.

        **name** (`string`)
          Human readable data source name.

        **filetype** (`string`)
          Data filetype. Possible values for this field are `bed`, `vcf`, and
          `csv`.

        **data** (`object`)
          :ref:`Link <api-links>` to a :ref:`blob
          <api-resources-data-sources-blobs>` resource.

        **user** (`object`)
          :ref:`Link <api-links>` to a :ref:`user
          <api-resources-users-instances>` resource (embeddable).
        """
        serialization = super(DataSourcesResource, cls).serialize(instance, embed=embed)
        serialization.update(data={'uri': url_for('.data_source_data',
                                                  data_source=instance.id)},
                             name=instance.name,
                             filetype=instance.filetype,
                             gzipped=instance.gzipped,
                             added=str(instance.added.isoformat()))
        return serialization

    @classmethod
    def list_view(cls, *args, **kwargs):
        """
        Returns a collection of data sources in the `data_source_collection`
        field.

        .. note:: Requires having the `admin` role or being the user specified
           by the `user` filter.

        **Available filters:**

        - **user** (`uri`)

        **Orderable by:** `name`, `filetype`, `added`
        """
        return super(DataSourcesResource, cls).list_view(*args, **kwargs)

    @classmethod
    def get_view(cls, *args, **kwargs):
        """
        Returns the data source representation in the `data_source` field.

        .. note:: Requires having the `admin` role or being the owner of the
           data source.
        """
        return super(DataSourcesResource, cls).get_view(*args, **kwargs)

    @classmethod
    @require_user
    def add_view(cls, *args, **kwargs):
        """
        Adds a data source resource.

        .. note:: Requires :ref:`user authentication <api-authentication>`.

        **Required request data:**

        - **name** (`string`)
        - **filetype** (`string`)

        **Accepted request data:**

        - **gzipped** (`boolean`)
        - **local_file** (`string`)
        - **data** (`file`)
        """
        # Todo: If files['data'] is missing (or non-existent file?), we crash with
        #     a data_source_not_cached error.
        # Todo: Sandbox local_path (per user).
        # Todo: Option to upload the actual data later at the /data_source/XX/data
        #     endpoint, symmetrical to the GET request.
        # Todo: Is it possible to call this without authentication?
        kwargs.update(user=g.user, upload=request.files.get('data'))
        return super(DataSourcesResource, cls).add_view(*args, **kwargs)

    @classmethod
    def edit_view(cls, *args, **kwargs):
        """
        Updates a data source resource.

        .. note:: Requires having the `admin` role or being the owner of the
           data source.

        **Accepted request data:**

        - **name** (`string`)
        """
        return super(DataSourcesResource, cls).edit_view(*args, **kwargs)

    @classmethod
    def data_view(cls, data_source):
        """
        Returns the gzipped data source data.

        .. warning:: The response body will not be a JSON document.

        .. note:: Requires having the `admin` role or being the owner of the
           data source.
        """
        path = current_app.config['DATA_DIR']
        if not os.path.isabs(path):
            path = os.path.join(os.getcwd(), path)

        return send_from_directory(path,
                                   data_source.filename,
                                   mimetype='application/x-gzip')


text:
<?xml version="1.0" encoding="UTF-8"?>
<billStatus>
  <bill>
    <titles>
      <item>
        <titleType>(Extracted from GPO) Short Titles as Introduced</titleType>
        <chamberCode />
        <title>Department of Defense Waste Reduction Act</title>
        <parentTitleType />
        <chamberName />
      </item>
      <item>
        <titleType>Short Titles as Introduced</titleType>
        <chamberCode />
        <title>Department of Defense Waste Reduction Act</title>
        <parentTitleType />
        <chamberName />
      </item>
      <item>
        <titleType>Official Title as Introduced</titleType>
        <chamberCode />
        <title>To limit the amount of authorization of appropriations for the Department of Defense unless the Secretary of Defense implements cost-saving recommendations contained in a certain study by the Defense Business Board, and for other purposes.</title>
        <parentTitleType />
        <chamberName />
      </item>
      <item>
        <titleType>Display Title</titleType>
        <chamberCode />
        <title>Department of Defense Waste Reduction Act</title>
        <parentTitleType />
        <chamberName />
      </item>
    </titles>
    <committeeReports />
    <relatedBills />
    <cosponsors>
      <item>
        <party>D</party>
        <isOriginalCosponsor>False</isOriginalCosponsor>
        <firstName>Jamie</firstName>
        <sponsorshipDate>2017-05-16</sponsorshipDate>
        <identifiers>
          <lisID>2332</lisID>
          <bioguideId>R000606</bioguideId>
          <gpoId />
        </identifiers>
        <fullName>Rep. Raskin, Jamie [D-MD-8]</fullName>
        <sponsorshipWithdrawnDate />
        <middleName />
        <district>8</district>
        <bioguideId>R000606</bioguideId>
        <lastName>Raskin</lastName>
        <state>MD</state>
      </item>
    </cosponsors>
    <constitutionalAuthorityStatementText><![CDATA[
From the Congressional Record Online through the Government Publishing Office [www.gpo.gov]By Mr. DeSAULNIER:H.R. 2367.Congress has the power to enact this legislation pursuantto the following:Article 1, Section 8.[Page H4179]
]]></constitutionalAuthorityStatementText>
    <sponsors>
      <item>
        <party>D</party>
        <fullName>Rep. DeSaulnier, Mark [D-CA-11]</fullName>
        <bioguideId>D000623</bioguideId>
        <middleName />
        <byRequestType />
        <identifiers>
          <lisID>2227</lisID>
          <bioguideId>D000623</bioguideId>
          <gpoId />
        </identifiers>
        <firstName>Mark</firstName>
        <lastName>DeSaulnier</lastName>
        <state>CA</state>
        <district>11</district>
      </item>
    </sponsors>
    <title>Department of Defense Waste Reduction Act</title>
    <laws />
    <notes />
    <createDate>2017-05-05T03:11:54Z</createDate>
    <policyArea>
      <name>Armed Forces and National Security</name>
    </policyArea>
    <introducedDate>2017-05-04</introducedDate>
    <originChamber>House</originChamber>
    <summaries>
      <billSummaries>
        <item>
          <actionDate>2017-05-04</actionDate>
          <actionDesc>Introduced in House</actionDesc>
          <lastSummaryUpdateDate>2017-10-11T18:07:00Z</lastSummaryUpdateDate>
          <name>Introduced in House</name>
          <updateDate>2017-05-04T04:00:00Z</updateDate>
          <text><![CDATA[
Department of Defense Waste Reduction Act

This bill prohibits the appropriation to the Department of Defense (DOD) of supplemental funds for FY2017 or funds for FY2018 if the total for such fiscal year exceeds the amount authorized to be appropriated for DOD by the National Defense Authorization Act for FY 2017, unless: (1) DOD certifies to the congressional defense committees that it has evaluated and is implementing each recommendation for DOD cost savings contained in the Defense Business Board study titled "Transforming Department of Defense's Core Business Processes for Revolutionary Change"; or (2) if DOD is unable to make such certification, it submits a report explaining why it is not implementing any such recommendation and 30 days elapse following the report's submission.
]]></text>
          <versionCode>00</versionCode>
        </item>
      </billSummaries>
    </summaries>
    <version>1.0.0</version>
    <recordedVotes />
    <latestAction>
      <links />
      <text>Referred to the House Committee on Armed Services.</text>
      <actionDate>2017-05-04</actionDate>
    </latestAction>
    <amendments />
    <congress>115</congress>
    <actions>
      <actionTypeCounts>
        <introducedInHouse>1</introducedInHouse>
        <billReferrals>1</billReferrals>
        <introducedInTheHouse>1</introducedInTheHouse>
      </actionTypeCounts>
      <actionByCounts>
        <houseOfRepresentatives>3</houseOfRepresentatives>
      </actionByCounts>
      <item>
        <committee>
          <systemCode>hsas00</systemCode>
          <name>Armed Services Committee</name>
        </committee>
        <text>Referred to the House Committee on Armed Services.</text>
        <type>IntroReferral</type>
        <sourceSystem>
          2
          <name>House floor actions</name>
        </sourceSystem>
        <actionCode>H11100</actionCode>
        <links />
        <actionDate>2017-05-04</actionDate>
      </item>
      <item>
        <committee />
        <text>Introduced in House</text>
        <type>IntroReferral</type>
        <sourceSystem>
          9
          <name>Library of Congress</name>
        </sourceSystem>
        <actionCode>Intro-H</actionCode>
        <links />
        <actionDate>2017-05-04</actionDate>
      </item>
      <item>
        <committee />
        <text>Introduced in House</text>
        <type>IntroReferral</type>
        <sourceSystem>
          9
          <name>Library of Congress</name>
        </sourceSystem>
        <actionCode>1000</actionCode>
        <links />
        <actionDate>2017-05-04</actionDate>
      </item>
    </actions>
    <cboCostEstimates />
    <calendarNumbers />
    <committees>
      <billCommittees>
        <item>
          <subcommittees />
          <chamber>House</chamber>
          <name>Armed Services Committee</name>
          <systemCode>hsas00</systemCode>
          <activities>
            <item>
              <date>2017-05-04T13:03:15Z</date>
              <name>Referred to</name>
            </item>
          </activities>
          <type>Standing</type>
        </item>
      </billCommittees>
    </committees>
    <billNumber>2367</billNumber>
    <billType>HR</billType>
    <subjects>
      <billSubjects>
        <legislativeSubjects>
          <item>
            <name>Appropriations</name>
          </item>
          <item>
            <name>Congressional oversight</name>
          </item>
          <item>
            <name>Defense spending</name>
          </item>
          <item>
            <name>Department of Defense</name>
          </item>
          <item>
            <name>Executive agency funding and structure</name>
          </item>
          <item>
            <name>Government studies and investigations</name>
          </item>
        </legislativeSubjects>
        <policyArea>
          <name>Armed Forces and National Security</name>
        </policyArea>
      </billSubjects>
    </subjects>
    <updateDate>2017-10-11T18:15:17Z</updateDate>
  </bill>
  <dublinCore xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:format>text/xml</dc:format>
    <dc:language>EN</dc:language>
    <dc:rights>Pursuant to Title 17 Section 105 of the United States Code, this file is not subject to copyright protection and is in the public domain.</dc:rights>
    <dc:contributor>Congressional Research Service, Library of Congress</dc:contributor>
    <dc:description>This file contains bill summaries and statuses for federal legislation. A bill summary describes the most significant provisions of a piece of legislation and details the effects the legislative text may have on current law and federal programs. Bill summaries are authored by the Congressional Research Service (CRS) of the Library of Congress. As stated in Public Law 91-510 (2 USC 166 (d)(6)), one of the duties of CRS is "to prepare summaries and digests of bills and resolutions of a public general nature introduced in the Senate or House of Representatives". For more information, refer to the User Guide that accompanies this file.</dc:description>
  </dublinCore>
</billStatus>


text:
package org.apache.flink.runtime.rest.messages;

/**
 * Tests for {@link BlobServerPortResponseBody}.
 */
public class BlobServerPortResponseTest extends RestResponseMarshallingTestBase<BlobServerPortResponseBody> {

	@Override
	protected Class<BlobServerPortResponseBody> getTestResponseClass() {
		return BlobServerPortResponseBody.class;
	}

	@Override
	protected BlobServerPortResponseBody getTestResponseInstance() throws Exception {
		return new BlobServerPortResponseBody(64);
	}
}


text:
package org.zkoss.zss.essential.advanced.db;

/**
 * A trade record
 * @author hawk
 *
 */
public class Trade {

	private Integer id;
	private String type;
	private int sale;
	private String salesPerson;

	public Trade(Integer id) {
		this.id = id;
	}

	public Trade(String type, String salesPerson, int sale){
		this.type = type;
		this.salesPerson = salesPerson;
		this.sale = sale;
	}

	/**
	 * copy constructor
	 * @param trade
	 */
	public Trade(Trade trade){
		this.id = trade.getId();
		this.type = trade.getType();
		this.sale = trade.getSale();
		this.salesPerson = trade.getSalesPerson();
	}

	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public int getSale() {
		return sale;
	}
	public void setSale(int sale) {
		this.sale = sale;
	}
	public String getSalesPerson() {
		return salesPerson;
	}
	public void setSalesPerson(String salesPerson) {
		this.salesPerson = salesPerson;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
}


text:
package org.scribe.model;

import java.io.Serializable;

/**
 * Represents an OAuth token (either request or access token) and its secret
 *
 * @author Pablo Fernandez
 */
public class Token implements Serializable
{
  private static final long serialVersionUID = 715000866082812683L;

  private final String token;
  private final String secret;
  private final String rawResponse;

  /**
   * Default constructor
   *
   * @param token token value
   * @param secret token secret
   */
  public Token(String token, String secret)
  {
    this(token, secret, null);
  }

  public Token(String token, String secret, String rawResponse)
  {
    this.token = token;
    this.secret = secret;
    this.rawResponse = rawResponse;
  }

  public String getToken()
  {
    return token;
  }

  public String getSecret()
  {
    return secret;
  }

  public String getRawResponse()
  {
    if (rawResponse == null)
    {
      throw new IllegalStateException("This token object was not constructed by scribe and does not have a rawResponse");
    }
    return rawResponse;
  }

  @Override
  public String toString()
  {
    return String.format("Token[%s , %s]", token, secret);
  }

  /**
   * Returns true if the token is empty (token = "", secret = "")
   */
  public boolean isEmpty()
  {
    return "".equals(this.token) && "".equals(this.secret);
  }

  /**
   * Factory method that returns an empty token (token = "", secret = "").
   *
   * Useful for two legged OAuth.
   */
  public static Token empty()
  {
    return new Token("","");
  }
}


text:
package de.danielbasedow.prospecter.core.schema;

import de.danielbasedow.prospecter.core.*;
import de.danielbasedow.prospecter.core.document.*;
import de.danielbasedow.prospecter.core.index.FieldIndex;
import de.danielbasedow.prospecter.core.persistence.QueryStorage;
import de.danielbasedow.prospecter.core.query.Condition;
import de.danielbasedow.prospecter.core.query.Query;
import de.danielbasedow.prospecter.core.query.QueryManager;
import de.danielbasedow.prospecter.core.query.build.AdvancedQueryBuilder;
import gnu.trove.list.TLongList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class SchemaImpl implements Schema {
    private static final Logger LOGGER = LoggerFactory.getLogger(SchemaImpl.class);

    private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
    private final Lock readLock = rwLock.readLock();
    private final Lock writeLock = rwLock.writeLock();

    protected final ConcurrentHashMap<String, FieldIndex> indices;
    protected final AdvancedQueryBuilder queryBuilder;
    protected final DocumentBuilder documentBuilder;
    protected final QueryManager queryManager;
    protected QueryStorage queryStorage;
    private boolean writeNewQueries;

    public SchemaImpl() {
        indices = new ConcurrentHashMap<String, FieldIndex>();
        queryBuilder = new AdvancedQueryBuilder(this);
        documentBuilder = new DocumentBuilder(this);
        queryManager = new QueryManager();
    }

    @Override
    public void addFieldIndex(String fieldName, FieldIndex index) throws SchemaConfigurationError {
        if (indices.containsKey(fieldName)) {
            throw new SchemaConfigurationError("Field '" + fieldName + "' is defined more than once!");
        }
        indices.put(fieldName, index);
    }

    @Override
    public void matchField(String fieldIndexName, Field field, Matcher matcher) throws UndefinedIndexFieldException {
        if (!indices.containsKey(fieldIndexName)) {
            throw new UndefinedIndexFieldException("No field named '" + fieldIndexName + "'");
        }
        indices.get(fieldIndexName).match(field, matcher);
    }

    public void addQuery(Query query) throws UndefinedIndexFieldException {
        writeLock.lock();
        try {
            Map<Condition, Long> postings = query.getPostings();
            for (Map.Entry<Condition, Long> entry : postings.entrySet()) {
                Condition condition = entry.getKey();
                Long posting = entry.getValue();

                if (!indices.containsKey(condition.getFieldName())) {
                    throw new UndefinedIndexFieldException("No field named '" + condition.getFieldName() + "'");
                }

                indices.get(condition.getFieldName()).addPosting(condition.getToken(), posting);
            }
            queryManager.addQuery(query);
        } finally {
            writeLock.unlock();
        }
    }

    @Override
    public void addQuery(String json) throws UndefinedIndexFieldException, MalformedQueryException {
        Query query = queryBuilder.buildFromJSON(json);
        if (queryStorage != null && writeNewQueries) {
            queryStorage.addQuery(query.getQueryId(), json);
        }
        addQuery(query);
    }

    @Override
    public Matcher matchDocument(Document doc) {
        return matchDocument(doc, getMatcher());
    }

    @Override
    public Matcher matchDocument(Document doc, Matcher matcher) {
        readLock.lock();
        try {
            FieldIterator fields = doc.getFields();
            while (fields.hasNext()) {
                Field field = fields.next();
                try {
                    matchField(field.getName(), field, matcher);
                } catch (UndefinedIndexFieldException e) {
                    e.printStackTrace();
                }
            }
        } finally {
            readLock.unlock();
        }
        return matcher;
    }

    @Override
    public int getFieldCount() {
        return indices.size();
    }

    @Override
    public FieldIndex getFieldIndex(String name) {
        return indices.get(name);
    }

    @Override
    public AdvancedQueryBuilder getQueryBuilder() {
        return queryBuilder;
    }

    @Override
    public DocumentBuilder getDocumentBuilder() {
        return documentBuilder;
    }

    @Override
    public Matcher getMatcher() {
        return new Matcher(queryManager);
    }

    @Override
    public QueryManager getQueryManager() {
        return queryManager;
    }

    @Override
    public void setQueryStorage(QueryStorage queryStorage) {
        this.queryStorage = queryStorage;
    }

    @Override
    public void close() {
        this.queryStorage.close();
    }

    @Override
    public void init() {
        //Disable persistence for new queries so we don't try updating every single query
        writeNewQueries = false;
        if (queryStorage != null) {
            LOGGER.info("initializing schema with stored queries");
            int loadedQueries = 0;
            try {
                for (Map.Entry<Integer, String> entry : queryStorage.getAllQueries()) {
                    addQuery(entry.getValue());
                    loadedQueries++;
                }
            } catch (Exception e) {
                LOGGER.error("problem loading stored queries", e);
            }
            LOGGER.info("done loading " + String.valueOf(loadedQueries) + " queries");
        }
        trim();
        writeNewQueries = true;
    }

    @Override
    public void deleteQuery(Integer queryId) {
        writeLock.lock();
        try {
            String rawQuery = queryStorage.getRawQuery(queryId);
            if (rawQuery != null) {
                try {
                    Query query = queryBuilder.buildFromJSON(rawQuery);
                    removePostings(query);
                } catch (MalformedQueryException e) {
                    LOGGER.warn("Error parsing query", e);
                }
            }
            queryManager.deleteQuery(queryId);
            queryStorage.deleteQuery(queryId);
        } finally {
            writeLock.unlock();
        }
    }

    private void removePostings(Query query) {
        Map<Condition, Long> postings = query.getPostings();
        for (Map.Entry<Condition, Long> entry : postings.entrySet()) {
            Condition condition = entry.getKey();
            Long posting = entry.getValue();

            indices.get(condition.getFieldName()).removePosting(condition.getToken(), posting);
        }
        queryManager.addQuery(query);
    }

    @Override
    public void trim() {
        writeLock.lock();
        try {
            for (FieldIndex field : indices.values()) {
                field.trim();
            }
        } finally {
            writeLock.unlock();
        }
    }
}


text:
'use strict';

var converter = require('./converter.js');

exports.extractNumberSymbols = extractNumberSymbols;
exports.extractCurrencySymbols = extractCurrencySymbols;
exports.extractDateTimeSymbols = extractDateTimeSymbols;
exports.pluralExtractor = pluralExtractor;
exports.outputLocale = outputLocale;
exports.correctedLocaleId = correctedLocaleId;
exports.findLocaleId = findLocaleId;
exports.serializeContent = serializeContent;

var goog = { provide: function() {},
  require: function() {},
  i18n: {currency: {}, pluralRules: {}} };

function findLocaleId(str, type) {
  if (type === 'num') {
    return (str.match(/^NumberFormatSymbols_(.+)$/) || [])[1];
  }

  if (type != 'datetime') { throw new Error('unknown type in findLocaleId: ' + type); }

  return (str.match(/^DateTimeSymbols_(.+)$/) || [])[1];
}

function getInfoForLocale(localeInfo, localeID) {
  if (!localeInfo[localeID]) {
    localeInfo[localeID] = {};
    //localeIds.push(localeID);
  }
  return localeInfo[localeID];
}

function extractNumberSymbols(content, localeInfo, currencySymbols) {
  //eval script in the current context so that we get access to all the symbols
  eval(content.toString());
  for (var propName in goog.i18n) {
    var localeID = findLocaleId(propName, 'num');
    if (localeID) {
      var info = getInfoForLocale(localeInfo, localeID);
      info.NUMBER_FORMATS =
          converter.convertNumberData(goog.i18n[propName], currencySymbols);
    }
  }
}

function extractCurrencySymbols(content) {
  //eval script in the current context so that we get access to all the symbols
  eval(content.toString());
  // var currencySymbols = goog.i18n.currency.CurrencyInfo;
  // currencySymbols.__proto__ = goog.i18n.currency.CurrencyInfoTier2;

  return Object.assign({}, goog.i18n.currency.CurrencyInfoTier2, goog.i18n.currency.CurrencyInfo);
}

function extractDateTimeSymbols(content, localeInfo) {
  //eval script in the current context so that we get access to all the symbols
  eval(content.toString());
  for (var propName in goog.i18n) {
    var localeID = findLocaleId(propName, 'datetime');
    if (localeID) {
      var info = getInfoForLocale(localeInfo, localeID);
      localeInfo[localeID].DATETIME_FORMATS =
          converter.convertDatetimeData(goog.i18n[propName]);
    }
  }
}

function pluralExtractor(content, localeInfo) {
  var contentText = content.toString();
  var localeIds = Object.keys(localeInfo);
  for (var i = 0; i < localeIds.length; i++) {
    //We don't need to care about country ID because the plural rules in more specific id are
    //always the same as those in its language ID.
    // e.g. plural rules for en_SG is the same as those for en.
    goog.LOCALE = localeIds[i].match(/[^_]+/)[0];
    try {
      eval(contentText);
    } catch (e) {
      console.log("Error in eval(contentText): " + e.stack);
    }
    if (!goog.i18n.pluralRules.select) {
      console.log('No select for lang [' + goog.LOCALE + ']');
      continue;
    }
    var temp = goog.i18n.pluralRules.select.toString().
        replace(/function\s+\(/g, 'function(').
        replace(/goog\.i18n\.pluralRules\.Keyword/g, 'PLURAL_CATEGORY').
        replace(/goog\.i18n\.pluralRules\.get_vf_/g, 'getVF').
        replace(/goog\.i18n\.pluralRules\.get_wt_/g, 'getWT').
        replace(/goog\.i18n\.pluralRules\.decimals_/g, 'getDecimals').
        replace(/\n/g, '');

    ///@@ is a crazy place holder to be replaced before writing to file
    localeInfo[localeIds[i]].pluralCat = "@@" + temp + "@@";
  }
}

function correctedLocaleId(localeID) {
// e.g. from zh_CN to zh-CN, from en_US to en-US
  return localeID.replace(/_/g, '-').toLowerCase();
}

function canonicalizeForJsonStringify(unused_key, object) {
  // This function is intended to be called as the 2nd argument to
  // JSON.stringify.  The goal here is to ensure that the generated JSON has
  // objects with their keys in ascending order.  Without this, it's much
  // harder to diff the generated files in src/ngLocale as the order isn't
  // exactly consistent.  We've gotten lucky in the past.
  //
  // Iteration order, for string keys, ends up being the same as insertion
  // order.  Refer :-
  //    1. http://ejohn.org/blog/javascript-in-chrome/
  //       (search for "for loop order").
  //       Currently all major browsers loop over the properties of an object
  //       in the order in which they were defined.
  //         - John Resig
  //    2. https://code.google.com/p/v8/issues/detail?id=164
  //       ECMA-262 does not specify enumeration order. The de facto standard
  //       is to match insertion order, which V8 also does ...
  if (typeof object != "object" || Object.prototype.toString.apply(object) === '[object Array]') {
    return object;
  }
  var result = {};
  Object.keys(object).sort().forEach(function(key) {
    result[key] = object[key];
  });
  return result;
}

function serializeContent(localeObj) {
  return JSON.stringify(localeObj, canonicalizeForJsonStringify, '  ')
    .replace(new RegExp('[\\u007f-\\uffff]', 'g'), function(c) { return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4); })
    .replace(/"@@|@@"/g, '');
}

function outputLocale(localeInfo, localeID) {
  var fallBackID = localeID.match(/[A-Za-z]+/)[0],
      localeObj = localeInfo[localeID],
      fallBackObj = localeInfo[fallBackID];

  // fallBack to language formats when country format is missing
  // e.g. if NUMBER_FORMATS of en_xyz is not present, use the NUMBER_FORMATS of en instead
  if (!localeObj.NUMBER_FORMATS) {
    localeObj.NUMBER_FORMATS = fallBackObj.NUMBER_FORMATS;
  }

  // datetimesymbolsext.js provides more top level locales than the other
  // files.  We process datetimesymbolsext.js because we want the country
  // specific formats that are missing from datetimesymbols.js.  However, we
  // don't want to write locale files that only have dateformat (i.e. missing
  // number formats.)  So we skip them.
  if (!localeObj.NUMBER_FORMATS) {
    console.log("Skipping locale %j: Don't have any number formats", localeID);
    return null;
  }

  if (!localeObj.DATETIME_FORMATS) {
    localeObj.DATETIME_FORMATS = fallBackObj.DATETIME_FORMATS;
  }
  localeObj.localeID = localeID;
  localeObj.id = correctedLocaleId(localeID);

  var getDecimals = [
    'function getDecimals(n) {',
    '  n = n + \'\';',
    '  var i = n.indexOf(\'.\');',
    '  return (i == -1) ? 0 : n.length - i - 1;',
    '}', '', ''
  ].join('\n');

  var getVF = [
    'function getVF(n, opt_precision) {',
    '  var v = opt_precision;', '',
    '  if (undefined === v) {',
    '    v = Math.min(getDecimals(n), 3);',
    '  }', '',
    '  var base = Math.pow(10, v);',
    '  var f = ((n * base) | 0) % base;',
    '  return {v: v, f: f};',
    '}', '', ''
  ].join('\n');

  var getWT =
  [
    'function getWT(v, f) {',
    '  if (f === 0) {',
    '    return {w: 0, t: 0};',
    '  }', '',
    '  while ((f % 10) === 0) {',
    '    f /= 10;',
    '    v--;',
    '  }', '',
    '  return {w: v, t: f};',
    '}', '', ''
  ].join('\n');

  localeObj = {
    DATETIME_FORMATS: localeObj.DATETIME_FORMATS,
    NUMBER_FORMATS: localeObj.NUMBER_FORMATS,
    pluralCat: localeObj.pluralCat,
    id: localeObj.id,
    localeID: localeID
  };

  var content = serializeContent(localeObj);
  if (content.indexOf('getVF(') < 0) {
    getVF = '';
  }
  if (content.indexOf('getWT(') < 0) {
    getWT = '';
  }
  if (!getVF && content.indexOf('getDecimals(') < 0) {
    getDecimals = '';
  }

  var prefix =
      "'use strict';\n" +
      'angular.module("ngLocale", [], ["$provide", function($provide) {\n' +
          'var PLURAL_CATEGORY = {' +
          'ZERO: "zero", ONE: "one", TWO: "two", FEW: "few", MANY: "many", OTHER: "other"' +
          '};\n' +
          getDecimals + getVF + getWT +
          '$provide.value("$locale", ';

  var suffix = ');\n}]);\n';

  return prefix + content + suffix;
}


text:
<?= apine_app_translator()->translate('register','title'); ?>

			<?php if ($this->_params->get_item('error_code')) :?>

				<button type="button" class="close" data-dismiss="alert">×</button>

 <?= apine_app_translator()->translate('form','warning'); ?>

				<?php echo $this->_params->get_item('error_message'); ?>

			<?php endif;?>

				<form id="content" action="<?= apine_url_helper()->path("register");?>"
					method="post">

						<?= apine_app_translator()->translate('register','username'); ?>
						<input class="form-control" type="text" name="user" placeholder="<?= apine_app_translator()->translate('register','username'); ?>" required />

						<?= apine_app_translator()->translate('register','password'); ?>
						<input class="form-control" type="password" name="pwd" placeholder="<?= apine_app_translator()->translate('register','password'); ?>" required />

						<?= apine_app_translator()->translate('register','password_confirm'); ?>
						<input class="form-control" type="password" name="pwd_confirm" placeholder="<?= apine_app_translator()->translate('register','password'); ?>" required />

						<?= apine_app_translator()->translate('register','email'); ?>
						<input class="form-control" type="email" name="email" placeholder="example@example.com"/>

					<button type="submit" class="btn btn-primary pull-right"> <?= apine_app_translator()->translate('register','submit'); ?></button>
				</form>


text:
package chillverse.dtalk.websocket.client.jetty;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import chillverse.dtalk.DTalkBaseConnection;
import chillverse.dtalk.DTalkConnectionRegistry;
import chillverse.net.nsd.NsdServiceInfo;

@WebSocket
public class DTalkClientConnection extends DTalkBaseConnection {
  private static final Logger LOG = LoggerFactory.getLogger(DTalkClientConnection.class);

  protected static URI mkDTalkUri(NsdServiceInfo service) throws URISyntaxException {
    return new URI("ws://" + service.getHost().getHostName() + ":" + service.getPort() + "/dtalksrv");
  }

  private final NsdServiceInfo service;
  private final WebSocketClient client;

  private Session session;

  public DTalkClientConnection(NsdServiceInfo service) {
    this.service = service;
    this.client = new WebSocketClient();

    try {
      client.start();
      client.connect(this, mkDTalkUri(service), new ClientUpgradeRequest());
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        client.stop();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }

  @OnWebSocketConnect
  public void onConnect(Session session) {
    LOG.trace("Got connect: {}", session);
    this.session = session;

    // register connection...
    DTalkConnectionRegistry.getInstance().register(service.getServiceName(), this);
  }

  @OnWebSocketClose
  public void onClose(int statusCode, String reason) {
    LOG.trace(">>> onClose: [{}] {}", statusCode, reason);

    session = null;

    // unregister connection...
    DTalkConnectionRegistry.getInstance().remove(service.getServiceName());
  }

  @Override
  @OnWebSocketMessage
  public void onMessage(String msg) {
    LOG.trace(">>> onMessage: {}", msg);
    super.onMessage(msg);
  }

  @Override
  public boolean isOpen() {
    return session != null ? session.isOpen() : false;
  }

  @Override
  public void close() {
    if (session != null && session.isOpen()) {
      session.close();
    }
  }

  @Override
  public boolean send(String msg) {
    if (isOpen()) {
      try {
        session.getRemote().sendString(msg);
        return true;
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    return false;
  }

}


text:
from django import template
from django.template import Context, loader, Template

register = template.Library()

@register.simple_tag
def is_active_tab(url, tab, cls=None):
    """
    Usage:
        In your Master Template:

                  About us

        In your template:
            {% include "site/menu.html" with tab='about_us' %}

    url :: Is the Name that you want to use to refer your page
    tab :: Is the Name that pass when you include the menu
    cls :: Is the Classes which your
 shoud have
    """
    template = Template('')
    context = Context({
        'cls': cls or '',
        'is_active': 'active' if url == tab else ''
    })
    if any([url, tab, cls]):
        template = Template("class=\"{{ is_active }}{{ cls }}\"")
    return template.render(context)


text:
package org.n52.sos.exception.ows;

/**
 * @author Christian Autermann <c.autermann@52north.org>
 * @author Eike Hinderk
 *         Jürrens
 *
 * @since 4.0.0
 */
public class VersionNegotiationFailedException extends CodedOwsException {
    private static final long serialVersionUID = 3626112515127914596L;

    public VersionNegotiationFailedException() {
        super(OwsExceptionCode.VersionNegotiationFailed);
        setStatus(org.n52.sos.util.http.HTTPStatus.BAD_REQUEST);
    }
}


text:
* File names should be lower case with dashes (-) i.e. `content-box.less`

 * Local variables should be prefixed with @`component-name`

 * Using BEM (Block, Element, Modifier) to keep nested selectors low, for components
    - `text-box` block
    - `text-box__header` - element
    - `text-box__content` - element
    - `text-box__footer` - element
    - `text-box__footer--active` - modifier

 * Use mixins to describe common properties

 * Be semantic in class names, i.e.
    - `input-toggle` instead of `box 16wide blue`
    - instead, mix in these properties in less, with `.blue`, `.16wide` and `box`

 * Try to put the most generic selectors as close to the top of the file as possible, or mimic the visual structure
   ( `__header` above `__footer` )

## Component structure

    .component {

        .some-mixin;
        some: property;

        &__header,
        &__content,
        &__footer {
            // shared between header, content and footer
        }
        &__header {
            // specific for header
        }

        &__content {
            // specific for content
        }

        &__footer {
            // specific for footer
            &--active {
                // in the active state
            }
        }
    }

## HTML Example

Using BEM means you have to type a little bit more in HTML, but it's a tradeoff

And when the footer is active


text:
package de.dominikmuench.twintowns;

import processing.core.PApplet;
import processing.data.Table;
import processing.data.TableRow;

public class TwinTownTable extends Table {

	private final static String DATA_FILENAME = "TwinTowns_clean.csv";
	private final static String COL_MUNICIPALITY = "municipality";
	private final static String COL_LAT = "latitude";
	private final static String COL_LNG = "longitude";
	private final static String COL_STATE = "bundesland";
	private final static String COL_PARTNER_MUNICIPALITY = "partnergemeinde";
	private final static String COL_PARTNER_COUNTRY = "country";
	private final static String COL_PARTNER_CONTINENT = "continent";
	private final static String COL_PARTNER_LAT = "partner_latitude";
	private final static String COL_PARTNER_LNG = "partner_longitude";
	private final static String COL_SINCE = "seit";
	private final static String COL_FORM = "form";

	private PApplet pa;
	private Table table;

	public TwinTownTable(PApplet pa) {
		this.pa = pa;
		this.table = this.pa.loadTable(DATA_FILENAME, "header");
	}

	public Iterable<TableRow> rows() {
		return this.table.rows();
	}

	/**
	 * Gets the municipality name for a given row.
	 *
	 * @param row
	 * @return
	 */
	public String getMunicipality(TableRow row) {
		return row.getString(COL_MUNICIPALITY);
	}

	/**
	 * Gets the latitude for a given row.
	 *
	 * @param row
	 * @return
	 */
	public float getLatitude(TableRow row) {
		return row.getFloat(COL_LAT);
	}

	/**
	 * Gets the longitude for a given row.
	 *
	 * @param row
	 * @return
	 */
	public float getLongitude(TableRow row) {
		return row.getFloat(COL_LNG);
	}

	/**
	 * Gets the municipality's state for a given row.
	 *
	 * @param row
	 * @return
	 */
	public String getState(TableRow row) {
		return row.getString(COL_STATE);
	}

	/**
	 * Gets the partner municipality for a given row.
	 *
	 * @param row
	 * @return
	 */
	public String getPartnerMunicipality(TableRow row) {
		return row.getString(COL_PARTNER_MUNICIPALITY);
	}

	/**
	 * Gets the latitude of the partner municipality for a given row.
	 *
	 * @param row
	 * @return
	 */
	public float getPartnerLatitude(TableRow row) {
		return row.getFloat(COL_PARTNER_LAT);
	}

	/**
	 * Gets the longitude of the partner municipality for a given row.
	 *
	 * @param row
	 * @return
	 */
	public float getPartnerLongitude(TableRow row) {
		return row.getFloat(COL_PARTNER_LNG);
	}

	/**
	 * Gets the country of the partner municipality for a given row.
	 *
	 * @param row
	 * @return
	 */
	public String getPartnerCountry(TableRow row) {
		return row.getString(COL_PARTNER_COUNTRY);
	}

	/**
	 * Gets the continent of the partner municipality for a given row.
	 *
	 * @param row
	 * @return
	 */
	public String getPartnerContinent(TableRow row) {
		return row.getString(COL_PARTNER_CONTINENT);
	}

	public String getForm(TableRow row) {
		return row.getString(COL_FORM);
	}

	public Integer getYear(TableRow row) {
		return row.getInt(COL_SINCE);
	}

}


text:
@interface PodsDummy_Pods_Gatling_Tests : NSObject
@end
@implementation PodsDummy_Pods_Gatling_Tests
@end