text:
package org.apache.hadoop.fs.viewfs;

import java.net.URI;
import java.util.List;
import java.util.function.Function;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsConstants;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * Unit test of nested mount point support in INodeTree
 */
public class TestNestedMountPoint {
  private InodeTree inodeTree;
  private Configuration conf;
  private String mtName;
  private URI fsUri;

  static class TestNestMountPointFileSystem {
    public URI getUri() {
      return uri;
    }

    private URI uri;

    TestNestMountPointFileSystem(URI uri) {
      this.uri = uri;
    }
  }

  static class TestNestMountPointInternalFileSystem extends TestNestMountPointFileSystem {
    TestNestMountPointInternalFileSystem(URI uri) {
      super(uri);
    }
  }

  private static final URI LINKFALLBACK_TARGET = URI.create("hdfs://nn00");
  private static final URI NN1_TARGET = URI.create("hdfs://nn01/a/b");
  private static final URI NN2_TARGET = URI.create("hdfs://nn02/a/b/e");
  private static final URI NN3_TARGET = URI.create("hdfs://nn03/a/b/c/d");
  private static final URI NN4_TARGET = URI.create("hdfs://nn04/a/b/c/d/e");
  private static final URI NN5_TARGET = URI.create("hdfs://nn05/b/c/d/e");
  private static final URI NN6_TARGET = URI.create("hdfs://nn06/b/c/d/e/f");

  @Before
  public void setUp() throws Exception {
    conf = new Configuration();
    mtName = TestNestedMountPoint.class.getName();
    ConfigUtil.setIsNestedMountPointSupported(conf, true);
    ConfigUtil.addLink(conf, mtName, "/a/b", NN1_TARGET);
    ConfigUtil.addLink(conf, mtName, "/a/b/e", NN2_TARGET);
    ConfigUtil.addLink(conf, mtName, "/a/b/c/d", NN3_TARGET);
    ConfigUtil.addLink(conf, mtName, "/a/b/c/d/e", NN4_TARGET);
    ConfigUtil.addLink(conf, mtName, "/b/c/d/e", NN5_TARGET);
    ConfigUtil.addLink(conf, mtName, "/b/c/d/e/f", NN6_TARGET);
    ConfigUtil.addLinkFallback(conf, mtName, LINKFALLBACK_TARGET);

    fsUri = new URI(FsConstants.VIEWFS_SCHEME, mtName, "/", null, null);

    inodeTree = new InodeTree<TestNestedMountPoint.TestNestMountPointFileSystem>(conf,
        mtName, fsUri, false) {
      @Override
      protected Function<URI, TestNestedMountPoint.TestNestMountPointFileSystem> initAndGetTargetFs() {
        return new Function<URI, TestNestMountPointFileSystem>() {
          @Override
          public TestNestedMountPoint.TestNestMountPointFileSystem apply(URI uri) {
            return new TestNestMountPointFileSystem(uri);
          }
        };
      }

      // For intenral dir fs
      @Override
      protected TestNestedMountPoint.TestNestMountPointInternalFileSystem getTargetFileSystem(
          final INodeDir<TestNestedMountPoint.TestNestMountPointFileSystem> dir) {
        return new TestNestMountPointInternalFileSystem(fsUri);
      }

      @Override
      protected TestNestedMountPoint.TestNestMountPointInternalFileSystem getTargetFileSystem(
          final String settings, final URI[] mergeFsURIList) {
        return new TestNestMountPointInternalFileSystem(null);
      }
    };
  }

  @After
  public void tearDown() throws Exception {
    inodeTree = null;
  }

  @Test
  public void testPathResolveToLink() throws Exception {
    // /a/b/c/d/e/f resolves to /a/b/c/d/e and /f
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/e/f", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b/c/d/e", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());

    // /a/b/c/d/e resolves to /a/b/c/d/e and /
    InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d/e", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
    Assert.assertEquals("/a/b/c/d/e", resolveResult2.resolvedPath);
    Assert.assertEquals(new Path("/"), resolveResult2.remainingPath);
    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult2.isLastInternalDirLink());

    // /a/b/c/d/e/f/g/h/i resolves to /a/b/c/d/e and /f/g/h/i
    InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/e/f/g/h/i", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
    Assert.assertEquals("/a/b/c/d/e", resolveResult3.resolvedPath);
    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToLinkNotResolveLastComponent() throws Exception {
    // /a/b/c/d/e/f resolves to /a/b/c/d/e and /f
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/e/f", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b/c/d/e", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());

    // /a/b/c/d/e resolves to /a/b/c/d and /e
    InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d/e", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
    Assert.assertEquals("/a/b/c/d", resolveResult2.resolvedPath);
    Assert.assertEquals(new Path("/e"), resolveResult2.remainingPath);
    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult2.isLastInternalDirLink());

    // /a/b/c/d/e/f/g/h/i resolves to /a/b/c/d/e and /f/g/h/i
    InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/e/f/g/h/i", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
    Assert.assertEquals("/a/b/c/d/e", resolveResult3.resolvedPath);
    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN4_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToDirLink() throws Exception {
    // /a/b/c/d/f resolves to /a/b/c/d, /f
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/f", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b/c/d", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());

    // /a/b/c/d resolves to /a/b/c/d and /
    InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
    Assert.assertEquals("/a/b/c/d", resolveResult2.resolvedPath);
    Assert.assertEquals(new Path("/"), resolveResult2.remainingPath);
    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult2.isLastInternalDirLink());

    // /a/b/c/d/f/g/h/i resolves to /a/b/c/d and /f/g/h/i
    InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/f/g/h/i", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
    Assert.assertEquals("/a/b/c/d", resolveResult3.resolvedPath);
    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToDirLinkNotResolveLastComponent() throws Exception {
    // /a/b/c/d/f resolves to /a/b/c/d, /f
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c/d/f", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b/c/d", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());

    // /a/b/c/d resolves to /a/b and /c/d
    InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b/c/d", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
    Assert.assertEquals("/a/b", resolveResult2.resolvedPath);
    Assert.assertEquals(new Path("/c/d"), resolveResult2.remainingPath);
    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult2.isLastInternalDirLink());

    // /a/b/c/d/f/g/h/i resolves to /a/b/c/d and /f/g/h/i
    InodeTree.ResolveResult resolveResult3 = inodeTree.resolve("/a/b/c/d/f/g/h/i", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult3.kind);
    Assert.assertEquals("/a/b/c/d", resolveResult3.resolvedPath);
    Assert.assertEquals(new Path("/f/g/h/i"), resolveResult3.remainingPath);
    Assert.assertTrue(resolveResult3.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN3_TARGET, ((TestNestMountPointFileSystem) resolveResult3.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult3.isLastInternalDirLink());
  }

  @Test
  public void testMultiNestedMountPointsPathResolveToDirLink() throws Exception {
    // /a/b/f resolves to /a/b and /f
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/f", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());

    // /a/b resolves to /a/b and /
    InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult2.kind);
    Assert.assertEquals("/a/b", resolveResult2.resolvedPath);
    Assert.assertEquals(new Path("/"), resolveResult2.remainingPath);
    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult2.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult2.isLastInternalDirLink());
  }

  @Test
  public void testMultiNestedMountPointsPathResolveToDirLinkNotResolveLastComponent() throws Exception {
    // /a/b/f resolves to /a/b and /f
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/f", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/f"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());

    // /a/b resolves to /a and /b
    InodeTree.ResolveResult resolveResult2 = inodeTree.resolve("/a/b", false);
    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult2.kind);
    Assert.assertEquals("/a", resolveResult2.resolvedPath);
    Assert.assertEquals(new Path("/b"), resolveResult2.remainingPath);
    Assert.assertTrue(resolveResult2.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult2.targetFileSystem).getUri());
    Assert.assertFalse(resolveResult2.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToDirLinkLastComponentInternalDir() throws Exception {
    // /a/b/c resolves to /a/b and /c
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/c"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToDirLinkLastComponentInternalDirNotResolveLastComponent() throws Exception {
    // /a/b/c resolves to /a/b and /c
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/b/c", false);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a/b", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/c"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(NN1_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertTrue(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToLinkFallBack() throws Exception {
    // /a/e resolves to linkfallback
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/e", true);
    Assert.assertEquals(InodeTree.ResultKind.EXTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/a/e"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointFileSystem);
    Assert.assertEquals(LINKFALLBACK_TARGET, ((TestNestMountPointFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertFalse(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testPathNotResolveToLinkFallBackNotResolveLastComponent() throws Exception {
    // /a/e resolves to internalDir instead of linkfallback
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/a/e", false);
    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/a", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/e"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertFalse(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToInternalDir() throws Exception {
    // /b/c resolves to internal dir
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/b/c", true);
    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/b/c", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertFalse(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testPathResolveToInternalDirNotResolveLastComponent() throws Exception {
    // /b/c resolves to internal dir
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/b/c", false);
    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/b", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/c"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
    Assert.assertEquals(fsUri, ((TestNestMountPointInternalFileSystem) resolveResult.targetFileSystem).getUri());
    Assert.assertFalse(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testSlashResolveToInternalDir() throws Exception {
    // / resolves to internal dir
    InodeTree.ResolveResult resolveResult = inodeTree.resolve("/", true);
    Assert.assertEquals(InodeTree.ResultKind.INTERNAL_DIR, resolveResult.kind);
    Assert.assertEquals("/", resolveResult.resolvedPath);
    Assert.assertEquals(new Path("/"), resolveResult.remainingPath);
    Assert.assertTrue(resolveResult.targetFileSystem instanceof TestNestMountPointInternalFileSystem);
    Assert.assertFalse(resolveResult.isLastInternalDirLink());
  }

  @Test
  public void testInodeTreeMountPoints() throws Exception {
    List<InodeTree.MountPoint<FileSystem>> mountPoints = inodeTree.getMountPoints();
    Assert.assertEquals(6, mountPoints.size());
  }
}


text:
package org.endeavourhealth.dbpatcher.helpers;

import java.net.MalformedURLException;
import java.net.URL;

public abstract class JdbcHelper {

    public static String getDatabaseName(String connectString) throws MalformedURLException {
        String cleanedString = null;
        int schemeEndOffset = connectString.indexOf("://");

        if (schemeEndOffset == -1)
            cleanedString = "http://" + connectString;
        else
            cleanedString = "http" + connectString.substring(schemeEndOffset);

        URL connectUrl = new URL(cleanedString);
        String databaseName = connectUrl.getPath();

        if (null == databaseName)
            return null;

        while (databaseName.startsWith("/"))
            databaseName = databaseName.substring(1);

        return databaseName;
    }
}

redpajama_set_name: RedPajamaGithub


text:
namespace app {
namespace Uno {

::uDelegateType* Predicate__Fuse_Drawing_Tesselation_HalfEdge__typeof();

}}

#endif


text:
package com.javarush.task.task38.task3801;

public class NameChecker {
    private static final int MAX_NUMBER_OF_CHARACTERS = 100500;
    public static int getNumberOfCharacters(String name) throws Exception {
        if (name == null)
            throw new NameIsNullException();
        else if (name.isEmpty())
            throw new NameIsEmptyException();

        int length = name.length();
        if (length > MAX_NUMBER_OF_CHARACTERS)
            throw new Exception("Слишком длинное имя");
        return length;
    }
}


text:
var express       = require('express'),
    exphbs        = require('express-handlebars'),
    http          = require('http'),
    mongoose      = require('mongoose'),
    twitter       = require('twitter'),
    routes        = require('./routes'),
    config        = require('./config'),
    streamHandler = require('./utils/streamHandler');

// Create express instance, set a port variable
var app = express();
var port = process.env.PORT || 8080;

// Set handlebars as the templating engine
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');

// Disable etag headers on responses - I think this prevents stale data? Not sure.
app.disable('etag');

// Connect to the Mongo database
mongoose.connect('mongodb://localhost/twitter-stream');

// Create new nTwitter instance
var twit = new twitter(config.twitter);

// Routes
app.get('/', routes.index);
app.get('/page/:page/:skip', routes.page);

// Use 'public/' as the static content directory
app.use('/', express.static(__dirname + '/public/'));

// Start server
var server = http.createServer(app).listen(port, function() {
    console.log('Express server listening on port ' + port);
});

// Initialize Socket.io
var io = require('socket.io').listen(server);

// Set a stream listener for tweets matching tracking keywords

twit.stream('statuses/filter', {track: '#hello, #world'}, function(stream) {
    streamHandler(stream, io);
});


text:
Using Firebase with Fuse can be a little daunting to set up at first as there appears to be a lot of moving parts. However it's not to bad once you have run through the process once so what we will do is take the included example and go through setting it up with your own firebase account.

## The Goal

We are going to set up the example app which will Authenticate on both iOS and Android using Google, Facebook and Email login providers

## And so it starts..

You can find the example in the `AuthExample` folder. It contains:

- AuthExample.unoproj - Our project file
- MainView.js - The JS for the app
- MainView.ux - The Super basic UI for our app
- AndroidImpl.uxl - A little bootstrapping to get some files into the correct place in the build

At this point it will not build, as we are missing a bunch of config files from firebase. We will have those soon :)

## Some basic concepts for our library

Firebase's client API allows only one user to be logged in at a time, so rather than have some kind of handle to the user that could expire we have a single static user that may or may not be authenticated.

Firebase's authentication api has a number of 'providers', we current support 3 of them: Google, Facebook & Email

Google and Facebook authentication involves using the facebook/google apis to authenticate the user, this then returns a token that is then used to authenticate against firebase. If you quit your app the token is maintain so that you will be automatically logged in when you next load the app.

Email authentication is provided by Firebase themselves and as such there is no 2 stage login or token. There is also no automatic reauthentication when returning to the app.

If you want an overview of the JS API see [this wiki page](https://github.com/cbaggers/Fuse.Firebase/wiki/Javascript-API)

## Kicking off the Firebase bit

- Make yourself a Firebase account

- Go to [the Firebase console](https://console.firebase.google.com/)
![](wikiResources/0.jpeg)

- Create yourself a new project, name it `AuthExample`

## Add Android App

- Click 'Add Firebase to your Android app' button

![](wikiResources/1.jpeg)

- Set the package name to `com.apps.authexample`
![](wikiResources/2.jpeg)

- Set the 'Debug signing certificate SHA-1' to the debug sha1 you get from running:
  - in osx: `keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore`
  - in windows: `keytool -exportcert -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore`
- Save the config file & copy to your project directory next to the `unoproj`

![](wikiResources/3.jpeg)
- don't worry about the 'Add to build.gradle' step, we do that for you

## Add iOS App

- Click the `Add App` button and then the `Add Firebase to your iOS app` button
- Set the 'iOS bundle ID' to `com.apps.authexample`

![](wikiResources/4.jpeg)
- unless you already have one then ignore the `App Store ID` section
- save the config file & copy to your project directory next to the `unoproj`

![](wikiResources/5.jpeg)
- add `"GoogleService-Info.plist:ObjCSource:iOS"` to the `"Includes"` of your `unoproj` file
- Dont worry about the `Install pod` and `Add initialization code` sections, we handle this for you

## Useful Authentication Defaults

We are going to allow multiple accounts with the same email address for now. We do this to make testing easy for ourselves as we probably dont have 100 different emails hanging around for this kind of testing.

- Go to the `Auth` section of the Firebase Console
- Go to the `Sign-in method` tab
- Click the `CHANGE` button in the `One account per email address` section
- In the window that opened, click the radio button to `Allow creation of multiple accounts with the same email address`

![](wikiResources/6.jpeg)

## Email Authentication Setup

- Go to the `Auth` section of the Firebase Console
- Go to the `Sign-in method` tab
- Click on the `Email/Password` row in the `Sign-in providers` table
- In the window that opened move the `Enable` switch to the on position
- Save

![](wikiResources/7.jpeg)

## Google Authentication Setup

- Go to the `Auth` section of the Firebase Console
- Go to the `Sign-in method` tab
- Click on the `Google` row in the `Sign-in providers` table
- In the window that opened move the `Enable` switch to the on position
- Save

![](wikiResources/8.jpeg)

- Open your GoogleService-Info.plist file and copy the string paired to `REVERSED_CLIENT_ID`
- Paste this as your `iOS->PList->UriSchemes` value in your `unoproj` file
- Open your `google-services.json` file
- Copy your `client->client_id` value (the one with `client_type: 3`
- Paste this as your `Google->RequestID` value in your `unoproj` file

## Facebook Authentication Setup
- Go to [https://developers.facebook.com/](https://developers.facebook.com/) and create a new app (you will of course need an account)

![](wikiResources/9.jpeg)
- Click iOS
- Give your app a name (for sanity reasons we will use the lowercase version of your app name) `authexample`
- On the next page ignore `is this a test version of another app` and fill in your contact email and category
- Click `Create App ID`

![](wikiResources/10.jpeg)
- You will now be taken to the quick start documentation, click the `Skip Quickstart` button ![](wikiResources/11.jpeg)
- You should now be in the dashboard
- Copy the `App ID` and `App Secret` as we will need those soon

![](wikiResources/12.jpeg)
- Add the `App ID` to your `unoproj` under the `Facebook->AppID` key
- Back in the facebook dashboard navigate to Settings->Basic and click on the `Add Platform` button.

![](wikiResources/13.jpeg)
- Choose `Android`
- Enter `com.apps.authexample` name as both the `Class Name` and the `Google Play Package Name`. It is not a valid `Google Play Package Name` but it serves well as a placeholder during development
- Enter your `Key Hashes`. If you dont have release hashes yet use `keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64` to get your debug key hash. **WARNING** test your password on the `keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore` portion first as if you enter the wrong password you will get the hash of the 'you entered and incorrect password' message :)
- You can also turn on `Single Sign On` if you like (We do in the example).

![](wikiResources/14.jpeg)
- When you save your will be warned that `There was a problem verifying the package name com.apps.authexample on Google Play` you can safely ignore this error and click the `use this name` button if you are currently in the developement stage.

![](wikiResources/15.jpeg)
- Back in the Firebase Console return to the `Sign-in Method` tab in the `Auth` section
- Click on the `Facebook` row in the `Sign-in providers` table
- In the window that opened move the `Enable` switch to the on position
- Paste your facebook `App ID` and `App Secret` into the boxes.
- Copy the `OAuth redirect URI`
- Click the `Save` button

![](wikiResources/16.jpeg)
- Back in your Facebook Console click the `Add Product` button in the sidebar
- Click `Get Started` on the `Facebook Login` row

![](wikiResources/17.jpeg)
- Paste your Firebase `OAuth redirect URI` in the `Valid OAuth redirect URIs` box
- Click the `Embedded Browser OAuth Login` switch so it says `Yes`
- Click the `Save Changes` button

![](wikiResources/18.jpeg)

## Running the Sample

### Build for Android

Use: `fuse build -t=android -r`

### Build for iOS

Use: `fuse build -t=iOS -DCOCOAPODS -d`

`Warning!`: The first build may take a crazy long time because of cocoapods.
Trying building with `fuse build -t=iOS -DCOCOAPODS -vv` and you will probably see it is sitting at `Setting up CocoaPods master rep`. If so see this link for details http://stackoverflow.com/questions/21022638/pod-install-is-staying-on-setting-up-cocoapods-master-repo


text:
<?php
/**
 * profile list module class
 *
 * @package munkireport
 * @author
 **/
class Profile_controller extends Module_controller
{

	/*** Protect methods with auth! ****/
	function __construct()
	{
		// Store module path
        $this->module_path = dirname(__FILE__) .'/';
        $this->view_path = $this->module_path . 'views/';
	}
	/**
	 * Default method
	 *
	 * @author
	 **/
	function index()
	{
		echo "You've loaded the profile module!";
	}

	function items($name='', $payload='')
    {
        // Protect this handler
        if( ! $this->authorized())
        {
            redirect('auth/login');
        }

        $data['profile_items'] = array();
        $data['name'] = 'No item';

        if ($name)
        {
            $name = rawurldecode($name);
            $profile_item_obj = new Profile_model();
            $data['profile_name'] = $name;
            if ($payload)
            {
                $payload = rawurldecode($payload);
                $items = $profile_item_obj->retrieve_many(
                    'payload_name = ? GROUP BY serial_number', array($payload));
                    $data['name'] = $payload;
            } else {
                $items = $profile_item_obj->retrieve_many(
                    'profile_name = ? GROUP BY serial_number', array($name));
                    $data['name'] = $name;
            }

            foreach ($items as $item)
            {
                $machine = new Machine_model($item->serial_number);

                // Check if authorized for this serial
                if( ! $machine->id )
                {
                    continue;
                }

                $instance['serial'] = $item->serial_number;
                $instance['hostname'] = $machine->computer_name;
                $instance['payload'] = $item->profile_name;
                $data['profile_items'][] = $instance;
            }

        }

        $obj = new View();
        $obj->view('profileitem_detail', $data, $this->view_path);
    }

} // END class default_module


text:
"""A utility to convert from Backus-Naur form to Chomsky Normal Form.

Backus-Naur Form (BNF) is a more natural way to encode the grammars for
docstrings.  However, the CYK parsing algorithm (in its simplest form)
Chomsky Normal From (CNF).  This utility, intended for use during
development, converts BNF grammars to CNF grammars, using the algorithm
outlined in the Wikipedia page on CNF:
https://en.wikipedia.org/wiki/Chomsky_normal_form.

The general plan here is to parse the BNF, manipulate the tree, then
produce the CNF of the grammar from the modified tree.

"""
import re
from typing import (
    List,
)

from .node import (
    Node,
    NodeType,
)

class ValidationError(Exception):
    pass

class Validator(object):
    """Validates a CNF production.

    For now, because it's simple, this validator operates
    on a string representation of the production.  In the
    future, we should probably move it to validate the tree.

    """

    def __init__(self, raise_exception: bool = False):
        """Create a new Validator.

        Args:
            raise_exception: If False, this validation returns
                whether the production is valid or not.  If true,
                then it raises an exception with an explanation of
                why.

        """
        self.raise_exception = raise_exception

    def _wrap(self, reason: str) -> bool:
        if self.raise_exception:
            raise ValidationError(reason)
        return False

    def _validate_sequence(self, sequence: Node) -> bool:
        assert sequence.node_type == NodeType.SEQUENCE, (
            f'"{sequence}" is not a Sequence'
        )
        assert len(sequence.children) > 0
        if len(sequence.children) == 1:
            if sequence.children[0].node_type != NodeType.TERMINAL:
                return self._wrap(
                    f'"{sequence}" has only one node: it should be terminal.'
                )
        elif len(sequence.children) == 2:
            if not all([
                x.node_type == NodeType.SYMBOL
                for x in sequence.children
            ]):
                return self._wrap(
                    f'"{sequence}" has two nodes: they should '
                    f'be non-terminals.'
                )
        else:
            return self._wrap(f'"{sequence} has more than 3 token on the RHS.')
        return True

    def _validate_production(self, production: Node) -> bool:
        assert production.node_type == NodeType.PRODUCTION
        for sequence in production.children[1].children:
            if not self._validate_sequence(sequence):
                return False
        return True

    def _validate_import(self, _import: Node) -> bool:
        assert _import.node_type == NodeType.IMPORT

        # There should be a value, if there is an import.
        return _import.value is not None

    def _validate_name(self, name: Node) -> bool:
        name_pattern = re.compile(r'\w+')
        if name.value is None:
            return False
        return name_pattern.fullmatch(name.value) is not None

    def validate(self, grammar: Node) -> bool:
        """Validate that the given production is in CNF.

        Args:
            grammar: The grammar to validate.

        Throws:
            ValidationError: If the grammar was not valid
                and raise_exception is True.

        Returns:
            Whether the grammar is valid or not.

        """
        assert grammar.node_type == NodeType.GRAMMAR

        for _import in grammar.filter(Node.is_import):
            if not self._validate_import(_import):
                return False
        for name in grammar.filter(Node.is_name):
            if not self._validate_name(name):
                return False
        for production in grammar.filter(Node.is_production):
            if not self._validate_production(production):
                return False
        return True


text:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import codecs
import collections
import gzip
import io
import itertools
import json
import logging
import os
import sys

# Add tracing/ to the path.
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import six
from tracing_build import html2trace, trace2html

try:
  StringTypes = six.string_types # pylint: disable=invalid-name
except NameError:
  StringTypes = str

GZIP_FILENAME_SUFFIX = '.gz'
HTML_FILENAME_SUFFIX = '.html'

# Relevant trace event phases. See
# https://code.google.com/p/chromium/codesearch#chromium/src/base/trace_event/common/trace_event_common.h.
METADATA_PHASE = 'M'
MEMORY_DUMP_PHASE = 'v'
BEGIN_PHASE = 'B'
END_PHASE = 'E'
CLOCK_SYNC_EVENT_PHASE = 'c'

# Minimum gap between two consecutive merged traces in microseconds.
MIN_TRACE_GAP_IN_US = 1000000

# Rule for matching IDs in an IdMap. For a given level, |match| should be a
# named tuple class where its fields determine the importance of |entry._items|
# for the purposes of matching pairs of IdMap entries.
IdMapLevel = collections.namedtuple('IdMapLevel', ['name', 'match'])

class IdMap(object):
  """Abstract class for merging and mapping IDs from multiple sources."""

  # Sub-classes must provide a tuple of |IdMapLevel| objects.
  LEVELS = NotImplemented

  def __init__(self, depth=0):
    assert 0 <= depth <= len(self.LEVELS)
    self._depth = depth

    if depth > 0:
      # Non-root node.
      self._canonical_id = None
      self._items = collections.defaultdict(set)
      self._sources = set()

    if depth < len(self.LEVELS):
      # Non-leaf node.
      self._entry_map = {}  # (Source, Entry ID) -> Entry.

  @property
  def max_mapped_id(self):
    """The maximum mapped ID of this map's entries."""
    if not self._entry_map:
      return 0
    return max(e._canonical_id for e in self._entry_map.values())

  def AddEntry(self, source, path, **items):
    """Add a source-specific entry path to the map.

    Args:
      source: The source of the entry (e.g. trace filename).
      path: A path of source-specific entry IDs in the map (e.g. [PID, TID]).
      **items: Dictionary of items (or sets of items) to be appended to the
          target entry's |_items|.
    """
    if path:
      return self._GetSubMapEntry(source, path[0]).AddEntry(source, path[1:],
                                                            **items)
    assert 'id' not in items  # ID is set according to the path.
    for key, value in items.items():
      value_set = self._items[key]
      if (isinstance(value, collections.abc.Iterable) and
          not isinstance(value, StringTypes)):
        value_set.update(value)
      else:
        value_set.add(value)
    return None

  def MapEntry(self, source, path):
    """Map an source-specific entry ID path to a canonical entry ID path.

    Args:
      source: The source of the entry (e.g. trace filename).
      path: A path of source-specific entry IDs in the map (e.g. [PID, TID]).

    Returns:
      A path of canonical entry IDs in the map to which the provided path of
      source-specific entry IDs is mapped.
    """
    if not path:
      return ()
    entry = self._entry_map[(source, path[0])]
    return (entry._canonical_id,) + entry.MapEntry(source, path[1:])

  def MergeEntries(self):
    """Recursively merge the entries in this map.

    Example: Suppose that the following entries were added to the map:

      map.AddEntry(source='trace_A.json', path=[10], name='Browser')
      map.AddEntry(source='trace_A.json', path=[20], name='Renderer')
      map.AddEntry(source='trace_B.json', path=[30], name='Browser')

    Before merging, |map._entry_map| will contain three separate items:

      ('trace_A.json', 10) -> IdMap(_items={id: {10}, name: {'Browser'}},
                                    _sources={'trace_A.json'})
      ('trace_A.json', 20) -> IdMap(_items={id: {20}, name: {'Renderer'}},
                                    _sources={'trace_A.json'})
      ('trace_B.json', 30) -> IdMap(_items={id: {30}, name: {'Browser'}},
                                    _sources={'trace_B.json'})

    Since the first two entries come from the same source, they cannot be
    merged. On the other hand, the third entry could be merged with either of
    the first two. Since it has a common name with the first entry, it will be
    merged with it in this method:

      ('trace_A.json', 10) -> IdMap(_items={id: {10, 30}, name: {'Browser'}},
                                    _sources={'trace_A.json', 'trace_B.json'})
      ('trace_A.json', 20) -> IdMap(_items={id: {20}, name: {Renderer}},
                                    _sources={'trace_A.json'})
      ('trace_B.json', 30) -> <same IdMap as ('trace_A.json', 10)>

    Pairs of entries will be merged in a descending order of sizes of
    pair-wise intersections of |entry._items| until there are no two entries
    such that (1) they have at least one value in |entry._items| in common and
    (2) they are mergeable (i.e. have no common source). Afterwards, unique IDs
    are assigned to the resulting "canonical" entries and their sub-entries are
    merged recursively.
    """
    # pylint: disable=unsubscriptable-object
    if self._depth == len(self.LEVELS):
      return

    logging.debug('Merging %r entries in %s...', self.LEVELS[self._depth].name,
                  self)

    canonical_entries = self._CanonicalizeEntries()
    self._AssignIdsToCanonicalEntries(canonical_entries)

    for entry in canonical_entries:
      entry.MergeEntries()

  def _GetSubMapEntry(self, source, entry_id):
    full_id = (source, entry_id)
    entry = self._entry_map.get(full_id)
    if entry is None:
      entry = type(self)(self._depth + 1)
      entry._sources.add(source)
      entry._items['id'].add(entry_id)
      self._entry_map[full_id] = entry
    return entry

  def _CalculateUnmergeableMapFromEntrySources(self):
    entry_ids_by_source = collections.defaultdict(set)
    for entry_id, entry in self._entry_map.items():
      for source in entry._sources:
        entry_ids_by_source[source].add(entry_id)

    unmergeable_map = collections.defaultdict(set)
    for unmergeable_set in entry_ids_by_source.values():
      for entry_id in unmergeable_set:
        unmergeable_map[entry_id].update(unmergeable_set - {entry_id})

    return unmergeable_map

  def _IsMergeableWith(self, other):
    return self._sources.isdisjoint(other._sources)

  def _GetMatch(self, other):
    # pylint: disable=unsubscriptable-object
    match_cls = self.LEVELS[self._depth - 1].match
    return match_cls(*(self._items[f] & other._items[f]
                       for f in match_cls._fields))

  def _MergeFrom(self, source):
    if self._depth > 0:
      # This is NOT a ROOT node, so we need to merge fields and sources from
      # the source node.
      for key, values in source._items.items():
        self._items[key].update(values)
      self._sources.update(source._sources)

    if self._depth < len(self.LEVELS):
      # This is NOT a LEAF node, so we need to copy over entries from the
      # source node's entry map.
      assert not set(self._entry_map) & set(source._entry_map)
      self._entry_map.update(source._entry_map)

  def _CanonicalizeEntries(self):
    canonical_entries = self._entry_map.copy()

    # {ID1, ID2} -> Match between the two entries.
    matches = {frozenset([full_id1, full_id2]): entry1._GetMatch(entry2)
               for full_id1, entry1 in canonical_entries.items()
               for full_id2, entry2 in canonical_entries.items()
               if entry1._IsMergeableWith(entry2)}

    while matches:
      # Pop the maximum match from the dictionary.
      max_match_set, max_match = max(
          list(matches.items()), key=lambda pair: [len(v) for v in pair[1]])
      del matches[max_match_set]
      canonical_full_id, merged_full_id = max_match_set

      # Skip pairs of entries that have nothing in common.
      if not any(max_match):
        continue

      # Merge the entries and update the map to reflect this.
      canonical_entry = canonical_entries[canonical_full_id]
      merged_entry = canonical_entries.pop(merged_full_id)
      logging.debug('Merging %s into %s [match=%s]...', merged_entry,
                    canonical_entry, max_match)
      canonical_entry._MergeFrom(merged_entry)
      del merged_entry
      self._entry_map[merged_full_id] = canonical_entry

      for match_set in matches.keys():
        if merged_full_id in match_set:
          # Remove other matches with the merged entry.
          del matches[match_set]
        elif canonical_full_id in match_set:
          [other_full_id] = match_set - {canonical_full_id}
          other_entry = canonical_entries[other_full_id]
          if canonical_entry._IsMergeableWith(other_entry):
            # Update other matches with the canonical entry which are still
            # mergeable.
            matches[match_set] = canonical_entry._GetMatch(other_entry)
          else:
            # Remove other matches with the canonical entry which have become
            # unmergeable.
            del matches[match_set]

    return list(canonical_entries.values())

  def _AssignIdsToCanonicalEntries(self, canonical_entries):
    assigned_ids = set()
    canonical_entries_without_assigned_ids = set()

    # Try to assign each canonical entry to one of the IDs from which it was
    # merged.
    for canonical_entry in canonical_entries:
      candidate_ids = canonical_entry._items['id']
      try:
        assigned_id = next(candidate_id for candidate_id in candidate_ids
                           if candidate_id not in assigned_ids)
      except StopIteration:
        canonical_entries_without_assigned_ids.add(canonical_entry)
        continue
      assigned_ids.add(assigned_id)
      canonical_entry._canonical_id = assigned_id

    # For canonical entries where this cannot be done (highly unlikely), scan
    # from the minimal merged ID upwards for the first unassigned ID.
    for canonical_entry in canonical_entries_without_assigned_ids:
      assigned_id = next(candidate_id for candidate_id in
                         itertools.count(min(canonical_entry._items['id']))
                         if candidate_id not in assigned_ids)
      assigned_ids.add(assigned_id)
      canonical_entry._canonical_id = assigned_id

  def __repr__(self):
    # pylint: disable=unsubscriptable-object
    cls_name = type(self).__name__
    if self._depth == 0:
      return '%s root' % cls_name
    return '%s %s entry(%s)' % (cls_name, self.LEVELS[self._depth - 1].name,
                                self._items)

class ProcessIdMap(IdMap):
  """Class for merging and mapping PIDs and TIDs from multiple sources."""

  LEVELS = (
      IdMapLevel(name='process',
                 match=collections.namedtuple('ProcessMatch',
                                              ['name', 'id', 'label'])),
      IdMapLevel(name='thread',
                 match=collections.namedtuple('ThreadMatch', ['name', 'id']))
  )

def LoadTrace(filename):
  """Load a trace from a (possibly gzipped) file and return its parsed JSON."""
  logging.info('Loading trace %r...', filename)
  if filename.endswith(HTML_FILENAME_SUFFIX):
    return LoadHTMLTrace(filename)
  if filename.endswith(GZIP_FILENAME_SUFFIX):
    with gzip.open(filename, 'rb') as f:
      return json.load(f)
  with open(filename, 'r') as f:
    return json.load(f)

def LoadHTMLTrace(filename):
  """Load a trace from a vulcanized HTML trace file."""
  trace_components = collections.defaultdict(list)

  with io.open(filename, 'r', encoding='utf-8') as file_handle:
    for sub_trace in html2trace.ReadTracesFromHTMLFile(file_handle):
      for name, component in TraceAsDict(sub_trace).items():
        trace_components[name].append(component)

  trace = {}
  for name, components in trace_components.items():
    if len(components) == 1:
      trace[name] = components[0]
    elif all(isinstance(component, list) for component in components):
      trace[name] = [e for component in components for e in component]
    else:
      trace[name] = components[0]
      logging.warning(
          'Values of repeated trace component %r in HTML trace %r are not '
          'lists. The first defined value of the component will be used.',
          filename, name)

  return trace

def SaveTrace(trace, filename):
  """Save a JSON trace to a (possibly gzipped) file."""
  if filename is None:
    logging.info('Dumping trace to standard output...')
    print(json.dumps(trace))
  else:
    logging.info('Saving trace %r...', filename)
    if filename.endswith(HTML_FILENAME_SUFFIX):
      with codecs.open(filename, mode='w', encoding='utf-8') as f:
        trace2html.WriteHTMLForTraceDataToFile([trace], 'Merged trace', f)
    elif filename.endswith(GZIP_FILENAME_SUFFIX):
      with gzip.open(filename, 'wb') as f:
        json.dump(trace, f)
    else:
      with open(filename, 'w') as f:
        json.dump(trace, f)

def TraceAsDict(trace):
  """Ensure that a trace is a dictionary."""
  if isinstance(trace, list):
    return {'traceEvents': trace}
  return trace

def MergeTraceFiles(input_trace_filenames, output_trace_filename):
  """Merge a collection of input trace files into an output trace file."""
  logging.info('Loading %d input traces...', len(input_trace_filenames))
  input_traces = collections.OrderedDict()
  for input_trace_filename in input_trace_filenames:
    input_traces[input_trace_filename] = LoadTrace(input_trace_filename)

  logging.info('Merging traces...')
  output_trace = MergeTraces(input_traces)

  logging.info('Saving output trace...')
  SaveTrace(output_trace, output_trace_filename)

  logging.info('Finished.')

def MergeTraces(traces):
  """Merge a collection of JSON traces into a single JSON trace."""
  trace_components = collections.defaultdict(collections.OrderedDict)

  for filename, trace in traces.items():
    for name, component in TraceAsDict(trace).items():
      trace_components[name][filename] = component

  merged_trace = {}
  for component_name, components_by_filename in trace_components.items():
    logging.info('Merging %d %r components...', len(components_by_filename),
                 component_name)
    merged_trace[component_name] = MergeComponents(component_name,
                                                   components_by_filename)

  return merged_trace

def MergeComponents(component_name, components_by_filename):
  """Merge a component of multiple JSON traces into a single component."""
  if component_name == 'traceEvents':
    return MergeTraceEvents(components_by_filename)
  return MergeGenericTraceComponents(component_name, components_by_filename)

def MergeTraceEvents(events_by_filename):
  """Merge trace events from multiple traces into a single list of events."""
  # Remove strings from the list of trace events
  # (https://github.com/catapult-project/catapult/issues/2497).
  events_by_filename = collections.OrderedDict(
      (filename, [e for e in events if not isinstance(e, StringTypes)])
      for filename, events in events_by_filename.items())

  timestamp_range_by_filename = _AdjustTimestampRanges(events_by_filename)
  process_map = _CreateProcessMapFromTraceEvents(events_by_filename)
  merged_events = _CombineTraceEvents(events_by_filename, process_map)
  _RemoveSurplusClockSyncEvents(merged_events)
  merged_events.extend(
      _BuildInjectedTraceMarkerEvents(timestamp_range_by_filename, process_map))
  return merged_events

def _RemoveSurplusClockSyncEvents(events):
  """Remove all clock sync events except for the first one."""
  # TODO(petrcermak): Figure out how to handle merging multiple clock sync
  # events.
  clock_sync_event_indices = [i for i, e in enumerate(events)
                              if e['ph'] == CLOCK_SYNC_EVENT_PHASE]
  # The indices need to be traversed from largest to smallest (hence the -1).
  for i in clock_sync_event_indices[:0:-1]:
    del events[i]

def _AdjustTimestampRanges(events_by_filename):
  logging.info('Adjusting timestamp ranges of traces...')

  previous_trace_max_timestamp = 0
  timestamp_range_by_filename = collections.OrderedDict()

  for index, (filename,
              events) in enumerate(list(events_by_filename.items()), 1):
    # Skip metadata events, the timestamps of which are always zero.
    non_metadata_events = [e for e in events if e['ph'] != METADATA_PHASE]
    if not non_metadata_events:
      logging.warning('Trace %r (%d/%d) only contains metadata events.',
                      filename, index, len(events_by_filename))
      timestamp_range_by_filename[filename] = None
      continue

    min_timestamp = min(e['ts'] for e in non_metadata_events)
    max_timestamp = max(e['ts'] for e in non_metadata_events)

    # Determine by how much the timestamps should be shifted.
    injected_timestamp_shift = max(
        previous_trace_max_timestamp + MIN_TRACE_GAP_IN_US - min_timestamp, 0)
    logging.info('Injected timestamp shift in trace %r (%d/%d): %d ms '
                 '[min=%d, max=%d, duration=%d].', filename, index,
                 len(events_by_filename), injected_timestamp_shift,
                 min_timestamp, max_timestamp, max_timestamp - min_timestamp)

    if injected_timestamp_shift > 0:
      # Shift the timestamps.
      for event in non_metadata_events:
        event['ts'] += injected_timestamp_shift

      # Adjust the range.
      min_timestamp += injected_timestamp_shift
      max_timestamp += injected_timestamp_shift

    previous_trace_max_timestamp = max_timestamp

    timestamp_range_by_filename[filename] = min_timestamp, max_timestamp

  return timestamp_range_by_filename

def _CreateProcessMapFromTraceEvents(events_by_filename):
  logging.info('Creating process map from trace events...')

  process_map = ProcessIdMap()
  for filename, events in events_by_filename.items():
    for event in events:
      pid, tid = event['pid'], event['tid']
      process_map.AddEntry(source=filename, path=(pid, tid))
      if event['ph'] == METADATA_PHASE:
        if event['name'] == 'process_name':
          process_map.AddEntry(source=filename, path=(pid,),
                               name=event['args']['name'])
        elif event['name'] == 'process_labels':
          process_map.AddEntry(source=filename, path=(pid,),
                               label=event['args']['labels'].split(','))
        elif event['name'] == 'thread_name':
          process_map.AddEntry(source=filename, path=(pid, tid),
                               name=event['args']['name'])

  process_map.MergeEntries()
  return process_map

def _CombineTraceEvents(events_by_filename, process_map):
  logging.info('Combining trace events from all traces...')

  type_name_event_by_pid = {}
  combined_events = []

  for index, (filename,
              events) in enumerate(list(events_by_filename.items()), 1):
    for event in events:
      if _UpdateTraceEventForMerge(event, process_map, filename, index,
                                   type_name_event_by_pid):
        combined_events.append(event)

  return combined_events

def _UpdateTraceEventForMerge(event, process_map, filename, index,
                              type_name_event_by_pid):
  pid, tid = process_map.MapEntry(source=filename,
                                  path=(event['pid'], event['tid']))
  event['pid'], event['tid'] = pid, tid

  if event['ph'] == METADATA_PHASE:
    # Update IDs in 'stackFrames' and 'typeNames' metadata events.
    if event['name'] == 'stackFrames':
      _UpdateDictIds(index, event['args'], 'stackFrames')
      for frame in event['args']['stackFrames'].values():
        _UpdateFieldId(index, frame, 'parent')
    elif event['name'] == 'typeNames':
      _UpdateDictIds(index, event['args'], 'typeNames')
      existing_type_name_event = type_name_event_by_pid.get(pid)
      if existing_type_name_event is None:
        type_name_event_by_pid[pid] = event
      else:
        existing_type_name_event['args']['typeNames'].update(
            event['args']['typeNames'])
        # Don't add the event to the merged trace because it has been merged
        # into an existing 'typeNames' metadata event for the given process.
        return False

  elif event['ph'] == MEMORY_DUMP_PHASE:
    # Update stack frame and type name IDs in heap dump entries in process
    # memory dumps.
    for heap_dump in event['args']['dumps'].get('heaps', {}).values():
      for heap_entry in heap_dump['entries']:
        _UpdateFieldId(index, heap_entry, 'bt', ignored_values=[''])
        _UpdateFieldId(index, heap_entry, 'type')

  return True  # Events should be added to the merged trace by default.

def _ConvertId(index, original_id):
  return '%d#%s' % (index, original_id)

def _UpdateDictIds(index, parent_dict, key):
  parent_dict[key] = {
      _ConvertId(index, original_id): value
      for original_id, value in parent_dict[key].items()}

def _UpdateFieldId(index, parent_dict, key, ignored_values=()):
  original_value = parent_dict.get(key)
  if original_value is not None and original_value not in ignored_values:
    parent_dict[key] = _ConvertId(index, original_value)

def _BuildInjectedTraceMarkerEvents(timestamp_range_by_filename, process_map):
  logging.info('Building injected trace marker events...')

  injected_pid = process_map.max_mapped_id + 1

  # Inject a mock process with a thread.
  injected_events = [
      {
          'pid': injected_pid,
          'tid': 0,
          'ph': METADATA_PHASE,
          'ts': 0,
          'name': 'process_sort_index',
          'args': {'sort_index': -1000}  # Show the process at the top.
      },
      {
          'pid': injected_pid,
          'tid': 0,
          'ph': METADATA_PHASE,
          'ts': 0,
          'name': 'process_name',
          'args': {'name': 'Merged traces'}
      },
      {
          'pid': injected_pid,
          'tid': 0,
          'ph': METADATA_PHASE,
          'ts': 0,
          'name': 'thread_name',
          'args': {'name': 'Trace'}
      }
  ]

  # Inject slices for each sub-trace denoting its beginning and end.
  for index, (filename, timestamp_range) in enumerate(
      list(timestamp_range_by_filename.items()), 1):
    if timestamp_range is None:
      continue
    min_timestamp, max_timestamp = timestamp_range
    name = 'Trace %r (%d/%d)' % (filename, index,
                                 len(timestamp_range_by_filename))
    slice_id = 'INJECTED_TRACE_MARKER_%d' % index
    injected_events.extend([
        {
            'pid': injected_pid,
            'tid': 0,
            'ph': BEGIN_PHASE,
            'cat': 'injected',
            'name': name,
            'id': slice_id,
            'ts': min_timestamp
        },
        {
            'pid': injected_pid,
            'tid': 0,
            'ph': END_PHASE,
            'cat': 'injected',
            'name': name,
            'id': slice_id,
            'ts': max_timestamp
        }
    ])

  return injected_events

def MergeGenericTraceComponents(component_name, components_by_filename):
  """Merge a generic component of multiple JSON traces into a single component.

  This function is only used for components that don't have a component-specific
  merging function (see MergeTraceEvents). It just returns the component's first
  provided value (in some trace).
  """
  components = list(components_by_filename.values())
  first_component = next(iter(components))
  if not all(c == first_component for c in components):
    logging.warning(
        'Values of trace component %r differ across the provided traces. '
        'The first defined value of the component will be used.',
        component_name)
  return first_component

def Main(argv):
  parser = argparse.ArgumentParser(description='Merge multiple traces.',
                                   add_help=False)
  parser.add_argument('input_traces', metavar='INPUT_TRACE', nargs='+',
                      help='Input trace filename.')
  parser.add_argument('-h', '--help', action='help',
                      help='Show this help message and exit.')
  parser.add_argument('-o', '--output_trace', help='Output trace filename. If '
                      'not provided, the merged trace will be written to '
                      'the standard output.')
  parser.add_argument('-v', '--verbose', action='count', dest='verbosity',
                      help='Increase verbosity level.')
  args = parser.parse_args(argv[1:])

  # Set verbosity level.
  if args.verbosity >= 2:
    logging_level = logging.DEBUG
  elif args.verbosity == 1:
    logging_level = logging.INFO
  else:
    logging_level = logging.WARNING
  logging.getLogger().setLevel(logging_level)

  try:
    MergeTraceFiles(args.input_traces, args.output_trace)
    return 0
  except Exception:  # pylint: disable=broad-except
    logging.exception('Something went wrong:')
    return 1
  finally:
    logging.warning('This is an EXPERIMENTAL TOOL! If you encounter any '
                    'issues, please file a Catapult bug '
                    '(https://github.com/catapult-project/catapult/issues/new) '
                    'with your current Catapult commit hash, a description of '
                    'the problem and any error messages, attach the input '
                    'traces and notify petrcermak@chromium.org. Thank you!')


text:
<?php

declare(strict_types=1);

namespace Atk4\Core;

use Atk4\Core\Translator\Translator;

/**
 * If a class use this trait, string can be translated calling method translate.
 */
trait TranslatableTrait
{
    /**
     * Translates the given message.
     *
     * @param string               $message    The message to be translated
     * @param array<string, mixed> $parameters Array of parameters used to translate message
     * @param string|null          $domain     The domain for the message or null to use the default
     * @param string|null          $locale     The locale or null to use the default
     *
     * @return string The translated string
     */
    public function _(string $message, array $parameters = [], string $domain = null, string $locale = null): string
    {
        if (TraitUtil::hasAppScopeTrait($this) && $this->issetApp() && method_exists($this->getApp(), '_')) {
            return $this->getApp()->_($message, $parameters, $domain, $locale);
        }

        return Translator::instance()->_($message, $parameters, $domain, $locale);
    }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!--
   Copyright 2008 University of Rochester

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 -->

<!--
    Document   : ivysettings.xml
    Created on : November 23, 2008, 1:48 AM
    Author     : Nathan Sarr
    Description:
        Purpose of the document follows.
-->

<ivysettings>
 <settings defaultResolver="default" />
 <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
 <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>

 <resolvers>
     <chain name="public">
         <!-- official maven2 repo -->
         <ibiblio name="maven2" m2compatible="true" />

     </chain>

 </resolvers>
 <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
 <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
</ivysettings>


text:
<?php

class Vizualizer_Json_UploadImage
{
    /**
     * ファイルアップロード処理のメインクラス
     */
    public function execute()
    {
        if(!empty($_FILES)){
            $result = array();
            $tmpName = $_FILES["file"]['tmp_name'];
            $result["tmp_name"] = $tmpName;
            if(!is_dir(Vizualizer_Configure::get("upload_root"))){
                mkdir(Vizualizer_Configure::get("upload_root"));
            }
            $destName = date("Ym");
            if(!is_dir(Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName)){
                mkdir(Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName);
            }
            $destName .= DIRECTORY_SEPARATOR . date("d");
            if(!is_dir(Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName)){
                mkdir(Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName);
            }
            $result["dest_dir"] = $destName;
            $path = pathinfo($_FILES["file"]['name']);
            $fileName = $path["filename"]."_".date("His").".".$path["extension"];
            $result["dest_file"] = $fileName;
            if (move_uploaded_file($tmpName, Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName.DIRECTORY_SEPARATOR.$fileName)) {
                switch($path["extension"]){
                    case "jpg":
                    case "jpeg":
                        if(Vizualizer_Configure::get("jpegoptim") !== null){
                            exec(Vizualizer_Configure::get("jpegoptim")." -m100 -o -p --strip-all ".Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName.DIRECTORY_SEPARATOR.$fileName);
                        }
                        break;
                    case "png":
                        if(Vizualizer_Configure::get("optipng") !== null){
                            exec(Vizualizer_Configure::get("optipng")." ".Vizualizer_Configure::get("upload_root").DIRECTORY_SEPARATOR.$destName.DIRECTORY_SEPARATOR.$fileName);
                        }
                        break;
                }
                $result["filename"] = $destName.DIRECTORY_SEPARATOR.$fileName;
            }else{
                $result["error"] = "Upload Failed.";
            }
            return $result;
        }
    }
}


text:
/**
 * @provides phui-lightbox-css
 */

.lightbox-attached {
  overflow: hidden;
}

.lightbox-attachment {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  overflow-y: auto;
}

.lightbox-attachment .lightbox-image-frame {
  position: absolute;
  top: 44px;
  right: 0;
  bottom: 0;
  left: 0;
  text-align: center;
}

.lightbox-attachment.comment-panel-open .lightbox-image-frame {
  right: 360px;
}

.lightbox-attachment .lightbox-image-frame img {
  max-width: calc(100% - 40px);
  max-height: calc(100% - 24px);
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
}

.lightbox-comment-frame {
  position: absolute;
  top: -19999px;
  right: 0;
  opacity: 0;
  transition: all 0.3s;
}

.lightbox-attachment .lightbox-icon-frame {
  top: 44%;
  left: calc(50% - 160px);
  position: fixed;
  display: block;
  height: 120px;
  width: 320px;
  color: {$darkbluetext};
}

.lightbox-attachment .lightbox-icon-frame:hover,
.lightbox-attachment .lightbox-icon-frame:hover .phui-icon-view {
  color: {$anchor};
  text-decoration: none;
}

.lightbox-attachment.comment-panel-open .lightbox-icon-frame {
  left: calc(50% - 340px);
}

.lightbox-attachment .phui-lightbox-file-icon {
  font-size: 64px;
  color: {$darkbluetext};
}

.comment-panel-open .lightbox-comment-frame {
  position: fixed;
  top: 44px;
  bottom: 0;
  right: 0;
  width: 360px;
  overflow-y: auto;
  background: #fff;
  opacity: 1;
}

.device-phone .comment-panel-open .lightbox-comment-frame {
  width: auto;
  left: 0;
}

.jx-mask + .lightbox-attachment {
  background: {$lightgreybackground};
}

.lightbox-attachment .attachment-name {
  line-height: 32px;
  font-size: {$biggerfontsize};
  text-align: center;
}

.lightbox-attachment .lightbox-status {
  background: #fff;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  padding: 0 20px;
  line-height: 44px;
  border-bottom: 1px solid {$thinblueborder};
  color: {$greytext};
}

.device-phone .lightbox-attachment .lightbox-status {
  padding: 0 12px;
}

.lightbox-attachment .lightbox-status .lightbox-download {
  float: right;
}

.lightbox-attachment .lightbox-status-txt a {
  color: #000;
  margin-right: 12px;
  font-size: {$biggerfontsize};
}

.lightbox-attachment .lightbox-status .phui-icon-view {
  height: 18px;
  width: 24px;
  font-size: 14px;
  line-height: 23px;
  display: block;
}

.lightbox-attachment .lightbox-status .lightbox-download
  .lightbox-download-form {
    display: inline;
}

.lightbox-attachment a.lightbox-download,
.lightbox-attachment a.lightbox-comment,
.lightbox-attachment a.lightbox-close {
  float: right;
  margin: 9px 0 0 8px;
}

.lightbox-attachment.comment-panel-open .lightbox-comment.phui-icon-circle,
.lightbox-attachment.comment-panel-open .lightbox-comment .phui-icon-view {
  color: {$sky};
  border-color: {$sky};
}

.lightbox-attachment .lightbox-left {
  top: 46%;
  left: 12px;
  position: fixed;
  display: block;
  height: 40px;
  width: 40px;
}

.lightbox-attachment .lightbox-left .phui-icon-view {
  font-size: 40px;
}

.lightbox-attachment .lightbox-left:hover .phui-icon-view {
  color: {$sky};
}

.lightbox-attachment .lightbox-right .phui-icon-view {
  top: 46%;
  right: 12px;
  position: fixed;
  display: block;
  height: 38px;
  width: 21px;
}

.lightbox-attachment.comment-panel-open .lightbox-right .phui-icon-view {
  right: 362px;
}

.lightbox-attachment .lightbox-right .phui-icon-view {
  font-size: 40px;
}

.lightbox-attachment .lightbox-right:hover .phui-icon-view {
  color: {$sky};
}


text:
Spree::LineItem.class_eval do
  # attr_accessible :parent_id #removed for rails 4 compatibility
  belongs_to :parent, :class_name => "Spree::LineItem", :foreign_key => :parent_id
  has_many :children, :class_name => "Spree::LineItem", :foreign_key => :parent_id, :dependent => :destroy
end


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Schlechtendalia 4: 19 (2000)

#### Original name
Uncinula delavayi Pat.

### Remarks
null


text:
"""
OpenStack base command
"""

from cliff.command import Command

class OpenStackCommand(Command):
    """Base class for OpenStack commands
    """

    api = None

    def run(self, parsed_args):
        if not self.api:
            return
        else:
            return super(OpenStackCommand, self).run(parsed_args)

    def get_data(self, parsed_args):
        pass

    def take_action(self, parsed_args):
        return self.get_data(parsed_args)


text:
.chart div {
  font: 10px sans-serif;
  background-color: steelblue;
  text-align: left;
  horizontal-align:center;
  float: left;
  padding: 5px;
  margin: 5px;
  color: white;
  width: 98%;
}

div.main_entry {

  horizontal-align:center;
  text-align: left;
}

div.entries {

 float: left;
 background-color: lightblue;
 horizontal-align:center;

}
p.title {
 float: left;
 padding: 3px;
 margin: 1px;
 background-color: darkblue;
}

p.non_entries {
 float: left;
 padding: 3px;
 margin: 1px;
 background-color: grey;
}

p.entries_pend {
 float: left;
 padding: 3px;
 margin: 1px;
 background-color: lightgreen;
}

p.entries {
 float: left;
 padding: 3px;
 margin: 1px;
 background-color: green;
}

.tablemanage {margin:0px;width:100%;;box-shadow: 4px 4px 2px #cccccc}


text:
QUnit.begin = function () {
  console.log("Starting test suite")
  console.log("================================================\n")
}

QUnit.moduleDone = function (opts) {
  if (opts.failed === 0) {
    console.log("\u2714 All tests passed in '" + opts.name + "' module")
  } else {
    console.log("\u2716 " + opts.failed + " tests failed in '" + opts.name + "' module")
  }
}

QUnit.done = function (opts) {
  console.log("\n================================================")
  console.log("Tests completed in " + opts.runtime + " milliseconds")
  console.log(opts.passed + " tests of " + opts.total + " passed, " + opts.failed + " failed.")
}