text:
#pragma once
#include <aws/drs/Drs_EXPORTS.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/core/utils/memory/stl/AWSMap.h>
#include <utility>

namespace Aws
{
namespace Utils
{
namespace Json
{
  class JsonValue;
  class JsonView;
} // namespace Json
} // namespace Utils
namespace drs
{
namespace Model
{

  /**
   *
Properties of a conversion job

See Also:
   AWS
   * API Reference

   */
  class AWS_DRS_API ConversionProperties
  {
  public:
    ConversionProperties();
    ConversionProperties(Aws::Utils::Json::JsonView jsonValue);
    ConversionProperties& operator=(Aws::Utils::Json::JsonView jsonValue);
    Aws::Utils::Json::JsonValue Jsonize() const;

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline const Aws::String& GetDataTimestamp() const{ return m_dataTimestamp; }

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline bool DataTimestampHasBeenSet() const { return m_dataTimestampHasBeenSet; }

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline void SetDataTimestamp(const Aws::String& value) { m_dataTimestampHasBeenSet = true; m_dataTimestamp = value; }

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline void SetDataTimestamp(Aws::String&& value) { m_dataTimestampHasBeenSet = true; m_dataTimestamp = std::move(value); }

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline void SetDataTimestamp(const char* value) { m_dataTimestampHasBeenSet = true; m_dataTimestamp.assign(value); }

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline ConversionProperties& WithDataTimestamp(const Aws::String& value) { SetDataTimestamp(value); return *this;}

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline ConversionProperties& WithDataTimestamp(Aws::String&& value) { SetDataTimestamp(std::move(value)); return *this;}

    /**
     *
The timestamp of when the snapshot being converted was taken

     */
    inline ConversionProperties& WithDataTimestamp(const char* value) { SetDataTimestamp(value); return *this;}

    /**
     *
Whether the volume being converted uses UEFI or not

     */
    inline bool GetForceUefi() const{ return m_forceUefi; }

    /**
     *
Whether the volume being converted uses UEFI or not

     */
    inline bool ForceUefiHasBeenSet() const { return m_forceUefiHasBeenSet; }

    /**
     *
Whether the volume being converted uses UEFI or not

     */
    inline void SetForceUefi(bool value) { m_forceUefiHasBeenSet = true; m_forceUefi = value; }

    /**
     *
Whether the volume being converted uses UEFI or not

     */
    inline ConversionProperties& WithForceUefi(bool value) { SetForceUefi(value); return *this;}

    /**
     *
The root volume name of a conversion job

     */
    inline const Aws::String& GetRootVolumeName() const{ return m_rootVolumeName; }

    /**
     *
The root volume name of a conversion job

     */
    inline bool RootVolumeNameHasBeenSet() const { return m_rootVolumeNameHasBeenSet; }

    /**
     *
The root volume name of a conversion job

     */
    inline void SetRootVolumeName(const Aws::String& value) { m_rootVolumeNameHasBeenSet = true; m_rootVolumeName = value; }

    /**
     *
The root volume name of a conversion job

     */
    inline void SetRootVolumeName(Aws::String&& value) { m_rootVolumeNameHasBeenSet = true; m_rootVolumeName = std::move(value); }

    /**
     *
The root volume name of a conversion job

     */
    inline void SetRootVolumeName(const char* value) { m_rootVolumeNameHasBeenSet = true; m_rootVolumeName.assign(value); }

    /**
     *
The root volume name of a conversion job

     */
    inline ConversionProperties& WithRootVolumeName(const Aws::String& value) { SetRootVolumeName(value); return *this;}

    /**
     *
The root volume name of a conversion job

     */
    inline ConversionProperties& WithRootVolumeName(Aws::String&& value) { SetRootVolumeName(std::move(value)); return *this;}

    /**
     *
The root volume name of a conversion job

     */
    inline ConversionProperties& WithRootVolumeName(const char* value) { SetRootVolumeName(value); return *this;}

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& GetVolumeToConversionMap() const{ return m_volumeToConversionMap; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline bool VolumeToConversionMapHasBeenSet() const { return m_volumeToConversionMapHasBeenSet; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline void SetVolumeToConversionMap(const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap = value; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline void SetVolumeToConversionMap(Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>&& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap = std::move(value); }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& WithVolumeToConversionMap(const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& value) { SetVolumeToConversionMap(value); return *this;}

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& WithVolumeToConversionMap(Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>&& value) { SetVolumeToConversionMap(std::move(value)); return *this;}

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& AddVolumeToConversionMap(const Aws::String& key, const Aws::Map<Aws::String, Aws::String>& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap.emplace(key, value); return *this; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& AddVolumeToConversionMap(Aws::String&& key, const Aws::Map<Aws::String, Aws::String>& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap.emplace(std::move(key), value); return *this; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& AddVolumeToConversionMap(const Aws::String& key, Aws::Map<Aws::String, Aws::String>&& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap.emplace(key, std::move(value)); return *this; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& AddVolumeToConversionMap(Aws::String&& key, Aws::Map<Aws::String, Aws::String>&& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap.emplace(std::move(key), std::move(value)); return *this; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& AddVolumeToConversionMap(const char* key, Aws::Map<Aws::String, Aws::String>&& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap.emplace(key, std::move(value)); return *this; }

    /**
     *
A mapping between the volumes being converted and the converted snapshot
     * ids

     */
    inline ConversionProperties& AddVolumeToConversionMap(const char* key, const Aws::Map<Aws::String, Aws::String>& value) { m_volumeToConversionMapHasBeenSet = true; m_volumeToConversionMap.emplace(key, value); return *this; }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline const Aws::Map<Aws::String, long long>& GetVolumeToVolumeSize() const{ return m_volumeToVolumeSize; }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline bool VolumeToVolumeSizeHasBeenSet() const { return m_volumeToVolumeSizeHasBeenSet; }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline void SetVolumeToVolumeSize(const Aws::Map<Aws::String, long long>& value) { m_volumeToVolumeSizeHasBeenSet = true; m_volumeToVolumeSize = value; }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline void SetVolumeToVolumeSize(Aws::Map<Aws::String, long long>&& value) { m_volumeToVolumeSizeHasBeenSet = true; m_volumeToVolumeSize = std::move(value); }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline ConversionProperties& WithVolumeToVolumeSize(const Aws::Map<Aws::String, long long>& value) { SetVolumeToVolumeSize(value); return *this;}

    /**
     *
A mapping between the volumes and their sizes

     */
    inline ConversionProperties& WithVolumeToVolumeSize(Aws::Map<Aws::String, long long>&& value) { SetVolumeToVolumeSize(std::move(value)); return *this;}

    /**
     *
A mapping between the volumes and their sizes

     */
    inline ConversionProperties& AddVolumeToVolumeSize(const Aws::String& key, long long value) { m_volumeToVolumeSizeHasBeenSet = true; m_volumeToVolumeSize.emplace(key, value); return *this; }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline ConversionProperties& AddVolumeToVolumeSize(Aws::String&& key, long long value) { m_volumeToVolumeSizeHasBeenSet = true; m_volumeToVolumeSize.emplace(std::move(key), value); return *this; }

    /**
     *
A mapping between the volumes and their sizes

     */
    inline ConversionProperties& AddVolumeToVolumeSize(const char* key, long long value) { m_volumeToVolumeSizeHasBeenSet = true; m_volumeToVolumeSize.emplace(key, value); return *this; }

  private:

    Aws::String m_dataTimestamp;
    bool m_dataTimestampHasBeenSet = false;

    bool m_forceUefi;
    bool m_forceUefiHasBeenSet = false;

    Aws::String m_rootVolumeName;
    bool m_rootVolumeNameHasBeenSet = false;

    Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>> m_volumeToConversionMap;
    bool m_volumeToConversionMapHasBeenSet = false;

    Aws::Map<Aws::String, long long> m_volumeToVolumeSize;
    bool m_volumeToVolumeSizeHasBeenSet = false;
  };

} // namespace Model
} // namespace drs
} // namespace Aws


text:
<!DOCTYPE html>

  <meta charset="utf-8">
  <title>wCMF 4.0: Cache Interface Reference</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="A MDSD framework for building reliable, maintainable and extendable web applications with PHP">
  <meta name="keywords" content="PHP, web application framework, model driven development">
  <meta name="author" content="wemove digital solutions">
  <link rel="shortcut icon" href="theme/images/favicon.ico">

  <link href="theme/css/doxstyles.css" rel="stylesheet">

  <link href="theme/bootstrap3/css/bootstrap.min.css" rel="stylesheet">
  <link href="theme/bootstrap3/css/font-awesome.min.css" rel="stylesheet">

  <link href="theme/js/tocify/jquery.tocify.css" rel="stylesheet">

  <link href="theme/css/syntax.css" rel="stylesheet">
  <link href="theme/css/style.css" rel="stylesheet">

          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".menu-navbar-collapse">
            Toggle navigation
          </button>
          wCMF 4.0

 Guides

Getting started

Architecture

Model

Persistence

Presentation

Configuration

Security

I18n & l10n

Tests

 API

 Code

 Support

                <input id="MSearchField" type="text" class="form-control" placeholder="Search API" name="query" onkeyup="searchBox.OnSearchFieldChange(event)">

wcmf

lib

io

Cache

Public Member Functions |
List of all members

Cache Interface Reference

Detailed Description

Cache defines the interface for cache implementations.

Caches are divided into different sections, which store key value pairs.

Author

ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 21 of file Cache.php.

   Inheritance diagram for Cache:

This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.

Public Member Functions

 	exists ($section, $key)

 	get ($section, $key)

 	put ($section, $key, $value)

 	clear ($section)

 	clearAll ()

Member Function Documentation

          exists
          (

          $section,

          $key

          )

Check if a key exists in the specified cache.

Parameters

$section	The caching section

$key	The cache key

Returns

boolean

Implemented in FileCache, and NullCache.

          get
          (

          $section,

          $key

          )

Get a value from the specified cache.

Parameters

$section	The caching section

$key	The cache key

Returns

Mixed

Implemented in FileCache, and NullCache.

          put
          (

          $section,

          $key,

          $value

          )

Store a value in the specified cache.

Parameters

$section	The caching section

$key	The key

$value	The value

Implemented in FileCache, and NullCache.

          clear
          (

          $section	)

Clear the given cache section.

The wildcard char '*' may be added to the section name in order to clear all matching sections.

Parameters

$section	The caching section

Implemented in FileCache, and NullCache.

          clearAll
          (
          	)

Clear all cache sections.

Implemented in FileCache, and NullCache.

        © 2016 wemove digital solutions

          Generated on Fri Jul 15 2016 22:20:43 for wCMF by  doxygen 1.8.10

redpajama_set_name: RedPajamaGithub


text:
<resources>
    <dimen name="textHeaderSize">32sp</dimen>
    <dimen name="gridViewImageViewHeight">250dp</dimen>
    <dimen name="gridViewTextViewSize">18sp</dimen>
</resources>


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

using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;

namespace PocketGov.Tests
{
    public class HomePage : BasePage
    {
        protected Query titleBar;
        protected Query fab;
        readonly Query flyoutMenuButton;
        readonly Query loginButton;
        readonly Query logoutButton;

        public HomePage()
        {
            if(OnAndroid)
            {
                titleBar = x => x.Marked("Pocketgov Denver");
                fab = x => x.Class("FormsImageView");
                flyoutMenuButton = x => x.Marked("OK");
                loginButton = x => x.Marked("Login");
                logoutButton = x => x.Marked("Logout");
            }
        }

        public void WaitToLoad()
        {
            Wait(titleBar);
            App.Screenshot("Loaded Main Page");
        }

        public void TapFloatingActionButton()
        {
            App.Tap(fab);
        }

        //Flyout Menu Navigation
        public void OpenFlyoutMenu()
        {
            App.Tap(flyoutMenuButton);
            App.Screenshot("Open Sidebar");
        }

        public void TapLoginButton()
        {
            App.Tap(loginButton);
            App.Screenshot("Select Login Option");
        }

        public void TapLogoutButton()
        {
            App.Tap(logoutButton);
        }
    }
}


text:
package io.gatling.http.check.body

import io.gatling.commons.util.StringHelper._
import io.gatling.commons.validation._
import io.gatling.core.check._
import io.gatling.core.check.extractor.css.{ CssCheckType, CssSelectors }
import io.gatling.http.check.HttpCheck
import io.gatling.http.check.HttpCheckBuilders._
import io.gatling.http.response.Response

import jodd.lagarto.dom.NodeSelector

class HttpBodyCssProvider(selectors: CssSelectors) extends CheckProtocolProvider[CssCheckType, HttpCheck, Response, NodeSelector] {

  override val specializer: Specializer[HttpCheck, Response] = StringBodySpecializer

  private val ErrorMapper = "Could not parse response into a Jodd NodeSelector: " + _

  override val preparer: Preparer[Response, NodeSelector] = response =>
    safely(ErrorMapper) {
      selectors.parse(response.body.string.unsafeChars).success
    }
}


text:
package org.apache.hadoop.hbase.index.mapreduce;

import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import junit.framework.Assert;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.LargeTests;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.index.ColumnQualifier.ValueType;
import org.apache.hadoop.hbase.index.IndexSpecification;
import org.apache.hadoop.hbase.index.IndexedHTableDescriptor;
import org.apache.hadoop.hbase.index.coprocessor.master.IndexMasterObserver;
import org.apache.hadoop.hbase.index.coprocessor.regionserver.IndexRegionObserver;
import org.apache.hadoop.hbase.index.coprocessor.wal.IndexWALObserver;
import org.apache.hadoop.hbase.mapreduce.TableInputFormat;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(LargeTests.class)
public class TestIndexMapReduceUtil {

  private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
  private HBaseAdmin admin;
  private Configuration conf;
  private String tableName;

  @BeforeClass
  public static void setupBeforeClass() throws Exception {
    Configuration conf = UTIL.getConfiguration();
    conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, IndexMasterObserver.class.getName());
    conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, IndexRegionObserver.class.getName());
    conf.set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY, IndexWALObserver.class.getName());
    conf.setBoolean("hbase.use.secondary.index", true);
    UTIL.startMiniCluster(1);
  }

  @AfterClass
  public static void tearDownAfterClass() throws Exception {
    UTIL.shutdownMiniCluster();
  }

  @Before
  public void setUp() throws Exception {
    admin = UTIL.getHBaseAdmin();
    conf = UTIL.getConfiguration();
  }

  @After
  public void tearDown() throws Exception {
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
  }

  @Test(timeout = 180000)
  public void testShouldAbleReturnTrueForIndexedTable() throws Exception {
    tableName = "testShouldAbleReturnTrueForIndexedTable";
    IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(tableName);
    HColumnDescriptor hcd = new HColumnDescriptor("col");
    IndexSpecification iSpec = new IndexSpecification("ScanIndexf");
    iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
    ihtd.addFamily(hcd);
    ihtd.addIndex(iSpec);
    admin.createTable(ihtd);
    Assert.assertTrue(IndexMapReduceUtil.isIndexedTable(tableName, conf));
  }

  @Test(timeout = 180000)
  public void testShouldAbleReturnFalseForNonIndexedTable() throws Exception {
    tableName = "testShouldAbleReturnFalseForNonIndexedTable";
    HTableDescriptor ihtd = new HTableDescriptor(tableName);
    HColumnDescriptor hcd = new HColumnDescriptor("col");
    ihtd.addFamily(hcd);
    admin.createTable(ihtd);
    Assert.assertFalse(IndexMapReduceUtil.isIndexedTable(tableName, conf));
  }

  @Test(timeout = 180000)
  public void testShouldReturnStartKeyBesedOnTheRowKeyFromPreSplitRegion() throws Exception {

    tableName = "testShouldReturnStartKeyBesedOnTheRowKeyFromPreSplitRegion";
    HTable table =
        UTIL.createTable(tableName.getBytes(), new byte[][] { "families".getBytes() }, 3,
          "0".getBytes(), "9".getBytes(), 5);

    assertStartKey(conf, tableName, table, "3");
    assertStartKey(conf, tableName, table, "0");
    assertStartKey(conf, tableName, table, "25");
    assertStartKey(conf, tableName, table, "AAAAA123");
    assertStartKey(conf, tableName, table, "63");
    assertStartKey(conf, tableName, table, "");
    assertStartKey(conf, tableName, table, "9222");
  }

  @Test(timeout = 180000)
  public void testShouldReturnStartKeyBesedOnTheRowKey() throws Exception {

    tableName = "testShouldReturnStartKeyBesedOnTheRowKey";
    HTable table = UTIL.createTable(tableName.getBytes(), new byte[][] { "families".getBytes() });

    assertStartKey(conf, tableName, table, "3");
    assertStartKey(conf, tableName, table, "0");
    assertStartKey(conf, tableName, table, "25");
    assertStartKey(conf, tableName, table, "AAAAA123");
    assertStartKey(conf, tableName, table, "");
  }

  @Test(timeout = 180000)
  public void testShouldFormIndexPutsAndIndexDeletes() throws Exception {
    tableName = "testShouldFormIndexPutsAndIndexDeletes";
    IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(tableName);
    HColumnDescriptor hcd = new HColumnDescriptor("col");
    IndexSpecification iSpec = new IndexSpecification("ScanIndexf");
    iSpec.addIndexColumn(hcd, "q1", ValueType.String, 10);
    iSpec.addIndexColumn(hcd, "q2", ValueType.String, 10);
    ihtd.addFamily(hcd);
    ihtd.addIndex(iSpec);
    admin.getConfiguration().set(TableInputFormat.INPUT_TABLE, tableName);
    admin.createTable(ihtd);
    HTable mainTable = new HTable(conf, Bytes.toBytes(tableName));
    Put put = new Put(Bytes.toBytes("r1"));
    put.add(hcd.getName(), Bytes.toBytes("q1"), Bytes.toBytes("v1"));
    mainTable.put(put);
    put = new Put(Bytes.toBytes("r2"));
    put.add(hcd.getName(), Bytes.toBytes("q1"), Bytes.toBytes("v1"));
    mainTable.put(put);
    put = new Put(Bytes.toBytes("r3"));
    put.add(hcd.getName(), Bytes.toBytes("q1"), Bytes.toBytes("v1"));
    put.add(hcd.getName(), Bytes.toBytes("q2"), Bytes.toBytes("v2"));
    mainTable.put(put);
    put = new Put(Bytes.toBytes("r4"));
    put.add(hcd.getName(), Bytes.toBytes("q1"), Bytes.toBytes("v1"));
    mainTable.put(put);
    put = new Put(Bytes.toBytes("r5"));
    put.add(hcd.getName(), Bytes.toBytes("q1"), Bytes.toBytes("v1"));
    mainTable.put(put);
    mainTable.flushCommits();
    admin.flush(tableName);
    Delete del = new Delete(Bytes.toBytes("r3"));
    del.deleteFamily(hcd.getName());
    mainTable.delete(del);
    List<Delete> indexDelete = IndexMapReduceUtil.getIndexDelete(del, admin.getConfiguration());
    assertTrue(indexDelete.size() == 0);
    admin.flush(tableName);
    del = new Delete(Bytes.toBytes("r5"));
    del.deleteColumns(hcd.getName(), Bytes.toBytes("q1"));
    mainTable.delete(del);
    indexDelete = IndexMapReduceUtil.getIndexDelete(del, admin.getConfiguration());
    Map<byte[], List<KeyValue>> familyMap = ((Delete) indexDelete.get(0)).getFamilyMap();
    Set<Entry<byte[], List<KeyValue>>> entrySet = familyMap.entrySet();
    for (Entry<byte[], List<KeyValue>> entry : entrySet) {
      List<KeyValue> value = entry.getValue();
      assertTrue(!value.get(0).isDeleteFamily());
    }

  }

  private void assertStartKey(Configuration conf, String tableName, HTable table, String rowKey)
      throws IOException {
    byte[] startKey = IndexMapReduceUtil.getStartKey(conf, tableName, Bytes.toBytes(rowKey));
    Assert.assertEquals("Fetching wrong start key for " + rowKey,
      Bytes.toString(table.getRegionLocation(rowKey).getRegionInfo().getStartKey()),
      Bytes.toString(startKey));
  }
}


text:
layout: post
title:  "Node Servers"
date:   2017-08-20 14:59:30 -0700
permalink: /blog/:title
comments: true
---

In the process of learning the MEAN stack, I've come across several tutorials that use Node functions and libraries but never explain how they work. Kind of like, here's a Node function and you use it this way in this particular use case, just trust that it works and let's move on. This way of learning has never really worked for me and usually leads me to only be able to use what's being taught in the exact scenarios that it's being introduced in. So I decided I needed to start from the ground up in Node specifically, learning how and why everything works.

### De-Mystifying Node

I started the [Understand Nodejs course](https://www.udemy.com/understand-nodejs/learn/v4/overview) from Udemy and so far it's been exactly what I needed. The instructor is fantastic and really makes you understand the core functionality of Node and explains what's actually happening under the hood. It has totally demystified many core concepts within Node for me and I am gaining an understanding of how to use the Node core libraries to build custom and tailored applications. I am about 2/3rds of the way through the course now and just finished the section dealing with creating servers.

### Servers

This is such a core concept in Node that I thought I would go through my learning process and include code samples with detailed comments that really helped  me understand what was going on. I've tried to be painfully detailed in the comments to really break down what's happening at each step. We started with a very basic server that returned plain text in its response.

<script src="https://gist.github.com/natmegs/81f11655d0ed7c22cd0cf924f5465707.js"></script>

We then moved on and created another simple server that returned HTML content in the response.

<script src="https://gist.github.com/natmegs/8c55b8373c88a2103c21fef4bb0546e6.js"></script>
<script src="https://gist.github.com/natmegs/87a499a71fa9c1f6621151ea26fdc366.js"></script>

Next we created an HTML file that we wanted to have dynamic content. We wanted to replace {Message} with with a message variable.

<script src="https://gist.github.com/natmegs/ec842c1bd51f8225691e9d5424846301.js"></script>
<script src="https://gist.github.com/natmegs/080ee6b8f3e98537000160d6e559d4e3.js"></script>

Finally, we went back to the original server returning HTML and took out the synchronous readFileSync operation and replaced it with streams.

<script src="https://gist.github.com/natmegs/66fb99138e6977424355f5e3333b3eb5.js"></script>

These exercises really helped me understand the basics of building Node servers and maybe it will be helpful to others getting started with Node. If anything is unclear or you have any suggestions or input, I would love to hear your feedback!


text:
import pickle

import retino
from retino.plot import *
from retino.utils import *

sns.set_style("ticks")

def plot_axon_growth_direction_algorithm(origin, end, target, ax):
    a_origin = origin
    a_end = end

    desired_direction_weight = 1.1
    momentum_direction_weight = 1

    desired_direction = get_unit_direction_vector(a_end, target)
    momentum_direction = get_unit_direction_vector(a_origin, a_end)

    desired_and_momentum = desired_direction_weight * desired_direction + momentum_direction_weight * momentum_direction
    desired_and_momentum = get_unit_vector(desired_and_momentum)

    prenoise_pol = cart_to_pol(desired_and_momentum)[1]
    results = []
    for i in range(100):
        r = np.random.normal(2.0, 1.0, size=1)[0]
        noise = np.random.normal(0, .4, size=1)[0]
        theta = prenoise_pol + noise
        cart_result = pol_to_cart(np.asarray([r, theta]))
        results.append(cart_result)

    desired_direction = (desired_direction * 2 + a_end)
    momentum_direction = (momentum_direction * 2 + a_end)
    desired_and_momentum = (desired_and_momentum * 2 + a_end)

    for i in range(25):
        ax.plot([a_end[0], results[i][0] + a_end[0]], [a_end[1], results[i][1] + a_end[1]], color="crimson", alpha=.2,
                linewidth=1.0)

    ax.plot([a_origin[0], a_end[0]], [a_origin[1], a_end[1]], color="gold", linewidth=2.0, label="Segment of Origin")
    ax.plot([a_end[0], desired_direction[0]], [a_end[1], desired_direction[1]], color="seagreen", linewidth=2.0,
            label="Desired Direction")
    ax.plot([a_end[0], momentum_direction[0]], [a_end[1], momentum_direction[1]], color="darkorange", linewidth=2.0,
            label="Momentum Direction")
    ax.plot([a_end[1], desired_and_momentum[0]], [a_end[1], desired_and_momentum[1]], color="dodgerblue", linewidth=3.0,
            label="Weighted Guide Direction")

    ax.set_aspect(1)
    ax.set_xlim([-4, 4])
    ax.set_ylim([-4, 4])

fig, direction_determination = plt.subplots(1, figsize=(5, 5), dpi=300)

origin = np.asarray([-3.5, -3.5])
end = np.asarray([-1.0, -1.0])
target = np.asarray([-5.0, 5.0])
print("Plotting for growth direction fig")
plot_axon_growth_direction_algorithm(origin, end, target, direction_determination)
direction_determination.set_title("Growth Direction Determination")

sns.despine(offset=5)
plt.tight_layout()
plt.savefig("figs/growth-direction-determination.pdf")
plt.close(fig)

#############

print("Plotting axon growth demos")
with open("singleaxonmodel/20.pickle", "rb") as f:
    model = pickle.load(f)

fig, growth_t1 = plt.subplots(1, figsize=(5, 5), dpi=300)

add_axon_to_axis(model.axons[0], growth_t1, axon_color="seagreen")
growth_t1.set_aspect(1)
growth_t1.set_xlim([0, retino.TECTUM_SIZE_X])
growth_t1.set_ylim([0, retino.TECTUM_SIZE_Y])
growth_t1.set_title("Axon A1 at 20 Iterations")

sns.despine(offset=5)
plt.tight_layout()
plt.savefig("figs/axon-at-20-iterations.pdf")
plt.close(fig)

#############

with open("singleaxonmodel/70.pickle", "rb") as f:
    model = pickle.load(f)

fig, growth_t2 = plt.subplots(1, figsize=(5, 5), dpi=300)

add_axon_to_axis(model.axons[0], growth_t2, axon_color="seagreen")
growth_t2.set_aspect(1)
growth_t2.set_xlim([0, retino.TECTUM_SIZE_X])
growth_t2.set_ylim([0, retino.TECTUM_SIZE_Y])
growth_t2.set_title("A1 at 70 Iterations")

sns.despine(offset=5)
plt.tight_layout()
plt.savefig("figs/axon-at-70-iterations.pdf")
plt.close(fig)

#############

with open("singleaxonmodel/140.pickle", "rb") as f:
    model = pickle.load(f)

fig, growth_t3 = plt.subplots(1, figsize=(5, 5), dpi=300)

postsynapses = list(set([synapse.postsynapticcell() for synapse in model.axons[0].synapses]))
add_postsynapticcell_to_axis(postsynapses, growth_t3, color="cornflowerblue", alpha=0.1, size_scale=80)
add_axon_to_axis(model.axons[0], growth_t3, axon_color="seagreen")
growth_t3.set_aspect(1)
growth_t3.set_xlim([0, retino.TECTUM_SIZE_X])
growth_t3.set_ylim([0, retino.TECTUM_SIZE_Y])
growth_t3.set_title("A1 at 140 Iterations")

sns.despine(offset=5)
plt.tight_layout()
plt.savefig("figs/axon-at-140-iterations.pdf")
plt.close(fig)

#############

with open("multipleaxonmodel/25axons.pickle", "rb") as f:
    model = pickle.load(f)

fig, [synapse_color_x, synapse_color_y] = plt.subplots(1, 2, figsize=(10, 5), dpi=300)

for axon in model.axons:
    add_axon_to_axis(axon, synapse_color_x, axon_color="seagreen", axon_alpha=0.2, target_alpha=0)
    add_axon_to_axis(axon, synapse_color_y, axon_color="seagreen", axon_alpha=0.2, target_alpha=0)
    add_synapses_to_axarr_by_axon(axon, [synapse_color_x, synapse_color_y],
                                  retino.TECTUM_SIZE_X, retino.TECTUM_SIZE_Y)

synapse_color_x.set_aspect(1)
synapse_color_x.set_xlim([0, retino.TECTUM_SIZE_X])
synapse_color_x.set_ylim([0, retino.TECTUM_SIZE_Y])
synapse_color_x.set_title("Synapses Coloured by X Gradient")

synapse_color_y.set_aspect(1)
synapse_color_y.set_xlim([0, retino.TECTUM_SIZE_X])
synapse_color_y.set_ylim([0, retino.TECTUM_SIZE_Y])
synapse_color_y.set_title("Synapses Coloured by Y Gradient")

sns.despine(offset=5)
plt.tight_layout()

plt.savefig("figs/25axis-synapse-colouring.pdf")

#############

with open("multipleaxonmodel/625axons.pickle", "rb") as f:
    model = pickle.load(f)

fig, [other1, other2] = plt.subplots(1, 2, figsize=(10, 5), dpi=500)

for axon in model.axons:
    add_synapses_to_axarr_by_axon(axon, [other1, other2],
                                  retino.TECTUM_SIZE_X, retino.TECTUM_SIZE_Y, alpha=0.2)

other1.set_aspect(1)
other1.set_xlim([0, retino.TECTUM_SIZE_X])
other1.set_ylim([0, retino.TECTUM_SIZE_Y])
other1.set_title("Synapses Coloured by X Gradient")

other2.set_aspect(1)
other2.set_xlim([0, retino.TECTUM_SIZE_X])
other2.set_ylim([0, retino.TECTUM_SIZE_Y])
other2.set_title("Synapses Coloured by Y Gradient")

sns.despine(offset=5)
plt.tight_layout()
plt.savefig("figs/625-axon-axis-synapse-colouring.png", dpi=1000)

############

fig, [postsynatic_ax_x, postsynatic_ax_y] = plt.subplots(1, 2)

for postsynapticcell in model.postsynapticcells:
    add_postsynapticcell_to_axarr_by_mapping(postsynapticcell, [postsynatic_ax_x, postsynatic_ax_y], 100.0, 100.0)
for ax in [postsynatic_ax_x, postsynatic_ax_y]:
    ax.set_aspect(1)
    ax.set_xlim([0, retino.TECTUM_SIZE_X])
    ax.set_ylim([0, retino.TECTUM_SIZE_Y])

postsynatic_ax_x.set_title("Post Synapse Mapping by X")
postsynatic_ax_y.set_title("Post Synapse Mapping by Y")

sns.despine(offset=5)
plt.tight_layout()
plt.savefig("figs/625-axon-postsynaptic-mapping-colour.pdf")


text:
@interface PKVariableSymbol : PKBaseSymbol

@end


text:
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} ..
make install


text:
package com.buffalokiwi.aerodrome.jet.products;

/**
 * Product Code Type used with the ProductCodes
 *
 * @author john Quinn
 */
public enum ProductCodeType
{
  GTIN14( "GTIN-14", 0 ),
  EAN( "EAN", 1 ),
  ISBN( "ISBN-10", 4 ),
  ISBN13( "ISBN-13", 3 ),
  UPC( "UPC", 2 ),

  /**
   * This is not a valid product code.  Do not send this value under
   * standard_product_codes.
   */
  ASIN( "ASIN", 5 );

  /**
   * Type
   */
  private final String type;

  /**
   * Sort order
   */
  private final int sort;

  private final static ProductCodeType[] values = values();

  /**
   * Attempt to retrieve a ProductCodeType by text value
   * @param text value
   * @return code
   * @throws IllegalArgumentException if text is not found
   */
  public static ProductCodeType fromText( final String text )
    throws IllegalArgumentException
  {
    for ( final ProductCodeType c : values )
    {
      if ( c.getType().equalsIgnoreCase( text ))
        return c;
    }

    throw new IllegalArgumentException( "Invalid value " + text );
  }

  /**
   * Create a new ProductCodeType instance
   * @param type Jet constant value
   * @param sort Sort order
   */
  ProductCodeType( final String type, final int sort )
  {
    this.type = type;
    this.sort = sort;
  }

  /**
   * Retrieve the sort index
   * @return index
   */
  public int getSort()
  {
    return sort;
  }

  /**
   * Retrieve the product type string
   * @return type
   */
  public String getType()
  {
    return type;
  }

  @Override
  public String toString()
  {
    return type;
  }
}


text:
<?php

namespace Magento\Customer\Controller\Adminhtml\Index;

use Magento\Customer\Controller\RegistryConstants;

class Wishlist extends \Magento\Customer\Controller\Adminhtml\Index
{
    /**
     * Wishlist Action
     *
     * @return void
     */
    public function execute()
    {
        $this->_initCustomer();
        $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
        $itemId = (int)$this->getRequest()->getParam('delete');
        if ($customerId && $itemId) {
            try {
                $this->_objectManager->create('Magento\Wishlist\Model\Item')->load($itemId)->delete();
            } catch (\Exception $exception) {
                $this->_objectManager->get('Magento\Framework\Logger')->logException($exception);
            }
        }

        $this->_view->getLayout()->getUpdate()->addHandle(strtolower($this->_request->getFullActionName()));
        $this->_view->loadLayoutUpdates();
        $this->prepareDefaultCustomerTitle();
        $this->_view->generateLayoutXml();
        $this->_view->generateLayoutBlocks();
        $this->_view->renderLayout();
    }
}


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Boll. R. Staz. Patalog. Veget. Roma, N. S. 15: 136 (1935)

#### Original name
Hyalodendron pyrinum Goid.

### Remarks
null


text:
package errors

import (
	"encoding/json"
	"fmt"
	"net/http"
	"strings"

	"github.com/CAP-ALL/kube2consul/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/unversioned"
	"github.com/CAP-ALL/kube2consul/Godeps/_workspace/src/k8s.io/kubernetes/pkg/runtime"
	"github.com/CAP-ALL/kube2consul/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/errors"
	"github.com/CAP-ALL/kube2consul/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/fielderrors"
)

// HTTP Status codes not in the golang http package.
const (
	StatusUnprocessableEntity = 422
	StatusTooManyRequests     = 429
	// HTTP recommendations are for servers to define 5xx error codes
	// for scenarios not covered by behavior. In this case, ServerTimeout
	// is an indication that a transient server error has occurred and the
	// client *should* retry, with an optional Retry-After header to specify
	// the back off window.
	StatusServerTimeout = 504
)

// StatusError is an error intended for consumption by a REST API server; it can also be
// reconstructed by clients from a REST response. Public to allow easy type switches.
type StatusError struct {
	ErrStatus unversioned.Status
}

var _ error = &StatusError{}

// Error implements the Error interface.
func (e *StatusError) Error() string {
	return e.ErrStatus.Message
}

// Status allows access to e's status without having to know the detailed workings
// of StatusError. Used by pkg/apiserver.
func (e *StatusError) Status() unversioned.Status {
	return e.ErrStatus
}

// DebugError reports extended info about the error to debug output.
func (e *StatusError) DebugError() (string, []interface{}) {
	if out, err := json.MarshalIndent(e.ErrStatus, "", "  "); err == nil {
		return "server response object: %s", []interface{}{string(out)}
	}
	return "server response object: %#v", []interface{}{e.ErrStatus}
}

// UnexpectedObjectError can be returned by FromObject if it's passed a non-status object.
type UnexpectedObjectError struct {
	Object runtime.Object
}

// Error returns an error message describing 'u'.
func (u *UnexpectedObjectError) Error() string {
	return fmt.Sprintf("unexpected object: %v", u.Object)
}

// FromObject generates an StatusError from an unversioned.Status, if that is the type of obj; otherwise,
// returns an UnexpecteObjectError.
func FromObject(obj runtime.Object) error {
	switch t := obj.(type) {
	case *unversioned.Status:
		return &StatusError{*t}
	}
	return &UnexpectedObjectError{obj}
}

// NewNotFound returns a new error which indicates that the resource of the kind and the name was not found.
func NewNotFound(kind, name string) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusNotFound,
		Reason: unversioned.StatusReasonNotFound,
		Details: &unversioned.StatusDetails{
			Kind: kind,
			Name: name,
		},
		Message: fmt.Sprintf("%s %q not found", kind, name),
	}}
}

// NewAlreadyExists returns an error indicating the item requested exists by that identifier.
func NewAlreadyExists(kind, name string) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusConflict,
		Reason: unversioned.StatusReasonAlreadyExists,
		Details: &unversioned.StatusDetails{
			Kind: kind,
			Name: name,
		},
		Message: fmt.Sprintf("%s %q already exists", kind, name),
	}}
}

// NewUnauthorized returns an error indicating the client is not authorized to perform the requested
// action.
func NewUnauthorized(reason string) error {
	message := reason
	if len(message) == 0 {
		message = "not authorized"
	}
	return &StatusError{unversioned.Status{
		Status:  unversioned.StatusFailure,
		Code:    http.StatusUnauthorized,
		Reason:  unversioned.StatusReasonUnauthorized,
		Message: message,
	}}
}

// NewForbidden returns an error indicating the requested action was forbidden
func NewForbidden(kind, name string, err error) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusForbidden,
		Reason: unversioned.StatusReasonForbidden,
		Details: &unversioned.StatusDetails{
			Kind: kind,
			Name: name,
		},
		Message: fmt.Sprintf("%s %q is forbidden: %v", kind, name, err),
	}}
}

// NewConflict returns an error indicating the item can't be updated as provided.
func NewConflict(kind, name string, err error) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusConflict,
		Reason: unversioned.StatusReasonConflict,
		Details: &unversioned.StatusDetails{
			Kind: kind,
			Name: name,
		},
		Message: fmt.Sprintf("%s %q cannot be updated: %v", kind, name, err),
	}}
}

// NewInvalid returns an error indicating the item is invalid and cannot be processed.
func NewInvalid(kind, name string, errs fielderrors.ValidationErrorList) error {
	causes := make([]unversioned.StatusCause, 0, len(errs))
	for i := range errs {
		if err, ok := errs[i].(*fielderrors.ValidationError); ok {
			causes = append(causes, unversioned.StatusCause{
				Type:    unversioned.CauseType(err.Type),
				Message: err.ErrorBody(),
				Field:   err.Field,
			})
		}
	}
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   StatusUnprocessableEntity, // RFC 4918: StatusUnprocessableEntity
		Reason: unversioned.StatusReasonInvalid,
		Details: &unversioned.StatusDetails{
			Kind:   kind,
			Name:   name,
			Causes: causes,
		},
		Message: fmt.Sprintf("%s %q is invalid: %v", kind, name, errors.NewAggregate(errs)),
	}}
}

// NewBadRequest creates an error that indicates that the request is invalid and can not be processed.
func NewBadRequest(reason string) error {
	return &StatusError{unversioned.Status{
		Status:  unversioned.StatusFailure,
		Code:    http.StatusBadRequest,
		Reason:  unversioned.StatusReasonBadRequest,
		Message: reason,
	}}
}

// NewServiceUnavailable creates an error that indicates that the requested service is unavailable.
func NewServiceUnavailable(reason string) error {
	return &StatusError{unversioned.Status{
		Status:  unversioned.StatusFailure,
		Code:    http.StatusServiceUnavailable,
		Reason:  unversioned.StatusReasonServiceUnavailable,
		Message: reason,
	}}
}

// NewMethodNotSupported returns an error indicating the requested action is not supported on this kind.
func NewMethodNotSupported(kind, action string) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusMethodNotAllowed,
		Reason: unversioned.StatusReasonMethodNotAllowed,
		Details: &unversioned.StatusDetails{
			Kind: kind,
		},
		Message: fmt.Sprintf("%s is not supported on resources of kind %q", action, kind),
	}}
}

// NewServerTimeout returns an error indicating the requested action could not be completed due to a
// transient error, and the client should try again.
func NewServerTimeout(kind, operation string, retryAfterSeconds int) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusInternalServerError,
		Reason: unversioned.StatusReasonServerTimeout,
		Details: &unversioned.StatusDetails{
			Kind:              kind,
			Name:              operation,
			RetryAfterSeconds: retryAfterSeconds,
		},
		Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, kind),
	}}
}

// NewInternalError returns an error indicating the item is invalid and cannot be processed.
func NewInternalError(err error) error {
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   http.StatusInternalServerError,
		Reason: unversioned.StatusReasonInternalError,
		Details: &unversioned.StatusDetails{
			Causes: []unversioned.StatusCause{{Message: err.Error()}},
		},
		Message: fmt.Sprintf("Internal error occurred: %v", err),
	}}
}

// NewTimeoutError returns an error indicating that a timeout occurred before the request
// could be completed.  Clients may retry, but the operation may still complete.
func NewTimeoutError(message string, retryAfterSeconds int) error {
	return &StatusError{unversioned.Status{
		Status:  unversioned.StatusFailure,
		Code:    StatusServerTimeout,
		Reason:  unversioned.StatusReasonTimeout,
		Message: fmt.Sprintf("Timeout: %s", message),
		Details: &unversioned.StatusDetails{
			RetryAfterSeconds: retryAfterSeconds,
		},
	}}
}

// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
func NewGenericServerResponse(code int, verb, kind, name, serverMessage string, retryAfterSeconds int, isUnexpectedResponse bool) error {
	reason := unversioned.StatusReasonUnknown
	message := fmt.Sprintf("the server responded with the status code %d but did not return more information", code)
	switch code {
	case http.StatusConflict:
		if verb == "POST" {
			reason = unversioned.StatusReasonAlreadyExists
		} else {
			reason = unversioned.StatusReasonConflict
		}
		message = "the server reported a conflict"
	case http.StatusNotFound:
		reason = unversioned.StatusReasonNotFound
		message = "the server could not find the requested resource"
	case http.StatusBadRequest:
		reason = unversioned.StatusReasonBadRequest
		message = "the server rejected our request for an unknown reason"
	case http.StatusUnauthorized:
		reason = unversioned.StatusReasonUnauthorized
		message = "the server has asked for the client to provide credentials"
	case http.StatusForbidden:
		reason = unversioned.StatusReasonForbidden
		message = "the server does not allow access to the requested resource"
	case http.StatusMethodNotAllowed:
		reason = unversioned.StatusReasonMethodNotAllowed
		message = "the server does not allow this method on the requested resource"
	case StatusUnprocessableEntity:
		reason = unversioned.StatusReasonInvalid
		message = "the server rejected our request due to an error in our request"
	case StatusServerTimeout:
		reason = unversioned.StatusReasonServerTimeout
		message = "the server cannot complete the requested operation at this time, try again later"
	case StatusTooManyRequests:
		reason = unversioned.StatusReasonTimeout
		message = "the server has received too many requests and has asked us to try again later"
	default:
		if code >= 500 {
			reason = unversioned.StatusReasonInternalError
			message = "an error on the server has prevented the request from succeeding"
		}
	}
	switch {
	case len(kind) > 0 && len(name) > 0:
		message = fmt.Sprintf("%s (%s %s %s)", message, strings.ToLower(verb), kind, name)
	case len(kind) > 0:
		message = fmt.Sprintf("%s (%s %s)", message, strings.ToLower(verb), kind)
	}
	var causes []unversioned.StatusCause
	if isUnexpectedResponse {
		causes = []unversioned.StatusCause{
			{
				Type:    unversioned.CauseTypeUnexpectedServerResponse,
				Message: serverMessage,
			},
		}
	} else {
		causes = nil
	}
	return &StatusError{unversioned.Status{
		Status: unversioned.StatusFailure,
		Code:   code,
		Reason: reason,
		Details: &unversioned.StatusDetails{
			Kind: kind,
			Name: name,

			Causes:            causes,
			RetryAfterSeconds: retryAfterSeconds,
		},
		Message: message,
	}}
}

// IsNotFound returns true if the specified error was created by NewNotFound.
func IsNotFound(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonNotFound
}

// IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
func IsAlreadyExists(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonAlreadyExists
}

// IsConflict determines if the err is an error which indicates the provided update conflicts.
func IsConflict(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonConflict
}

// IsInvalid determines if the err is an error which indicates the provided resource is not valid.
func IsInvalid(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonInvalid
}

// IsMethodNotSupported determines if the err is an error which indicates the provided action could not
// be performed because it is not supported by the server.
func IsMethodNotSupported(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonMethodNotAllowed
}

// IsBadRequest determines if err is an error which indicates that the request is invalid.
func IsBadRequest(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonBadRequest
}

// IsUnauthorized determines if err is an error which indicates that the request is unauthorized and
// requires authentication by the user.
func IsUnauthorized(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonUnauthorized
}

// IsForbidden determines if err is an error which indicates that the request is forbidden and cannot
// be completed as requested.
func IsForbidden(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonForbidden
}

// IsServerTimeout determines if err is an error which indicates that the request needs to be retried
// by the client.
func IsServerTimeout(err error) bool {
	return reasonForError(err) == unversioned.StatusReasonServerTimeout
}

// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// and may be the result of another HTTP actor.
func IsUnexpectedServerError(err error) bool {
	switch t := err.(type) {
	case *StatusError:
		if d := t.Status().Details; d != nil {
			for _, cause := range d.Causes {
				if cause.Type == unversioned.CauseTypeUnexpectedServerResponse {
					return true
				}
			}
		}
	}
	return false
}

// IsUnexpectedObjectError determines if err is due to an unexpected object from the master.
func IsUnexpectedObjectError(err error) bool {
	_, ok := err.(*UnexpectedObjectError)
	return err != nil && ok
}

// SuggestsClientDelay returns true if this error suggests a client delay as well as the
// suggested seconds to wait, or false if the error does not imply a wait.
func SuggestsClientDelay(err error) (int, bool) {
	switch t := err.(type) {
	case *StatusError:
		if t.Status().Details != nil {
			switch t.Status().Reason {
			case unversioned.StatusReasonServerTimeout, unversioned.StatusReasonTimeout:
				return t.Status().Details.RetryAfterSeconds, true
			}
		}
	}
	return 0, false
}

func reasonForError(err error) unversioned.StatusReason {
	switch t := err.(type) {
	case *StatusError:
		return t.ErrStatus.Reason
	}
	return unversioned.StatusReasonUnknown
}


text:
/**
 * Month string transformer.
 * @type {string}
 */
export const STRING_MONTH = 'Month';

/**
 * Lowercase month string transformer.
 * @type {string}
 */
export const STRING_MONTH_LOWERCASE = 'lcMonth';

/**
 * Uppercase month string transformer.
 * @type {string}
 */
export const STRING_MONTH_UPPERCASE = 'ucMonth';

/**
 * Day string transformer.
 * @type {string}
 */
export const STRING_DAY = 'Day';

/**
 * Lowercase day string transformer.
 * @type {string}
 */
export const STRING_DAY_LOWERCASE = 'lcDay';

/**
 * Uppercase day string transformer.
 * @type {string}
 */
export const STRING_DAY_UPPERCASE = 'ucDay';


text:
package org.thehecklers.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.thehecklers.entity.Quote;
import org.thehecklers.entity.QuoteSource;
import org.thehecklers.repository.QuoteRepo;

import java.util.Iterator;
import java.util.List;

/**
 * Created by markheckler on 11/24/15.
 */
@RestController
public class QuoteController {
    @Autowired
    private QuoteRepo quoteRepo;

    @RequestMapping("/sources/{sourceId}/quotes")
    public String getAllQuotesForSource(@PathVariable(value = "sourceId") Integer sourceId) {
        String quotesForSource = "";
        Iterator<Quote> iq = quoteRepo.findByQuoteSource(new QuoteSource(sourceId)).iterator();
        while (iq.hasNext()) {
            quotesForSource += iq.next().getQuoteText() + "
";
        }

        return "All quotes for source ID: " + sourceId + "

" + quotesForSource;
    }

    @RequestMapping(value = "/sources/{sourceId}/quote", method = RequestMethod.POST)
    public Quote addQuote(@PathVariable(value = "sourceId") Integer sourceId,
                          @RequestParam(name = "quoteText") String quoteText,
                          @RequestParam(name = "context", required = false) String context) {

        return quoteRepo.save(new Quote(quoteText, context, new QuoteSource(sourceId)));
    }

    @RequestMapping(value = "/random")
    public Quote randomQuote() {
        List<Quote> randomQuotes = quoteRepo.randomQuotes();
        return randomQuotes.get(0);
    }
}


text:
"""Graypools' CacheClient Cache module.

This module provides an sqlite3 back-end, allowing for easy transport and
storage of historical HTTP-fetched results. Sqlite3 has anecdotally proven to
be significantly faster in terms of read/write forcaching when compared with
other filesystem schemes.

Copyright (c) 2015 graypools LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import sqlite3
import datetime
import threading
import os
from io import BytesIO
from collections import namedtuple

# Caching constants
CACHE_FILE = 'cache.db'
CACHE_TABLE = 'locations'
FIELDS = ','.join(['url TEXT PRIMARY KEY', 'content BLOB',
                   "last_modified TIMESTAMP DEFAULT (datetime('now', 'localtime'))"])

LAST_MOD = "SELECT last_modified FROM {} WHERE url=?".format(CACHE_TABLE)
INSERT = 'INSERT INTO {} (content, url) VALUES (?, ?)'.format(CACHE_TABLE)
UPDATE = 'UPDATE {} SET content=?, last_modified=? WHERE url=?'.format(
    CACHE_TABLE)
SELECT = 'SELECT content FROM {} WHERE url=?'.format(CACHE_TABLE)
CREATE = 'CREATE TABLE IF NOT EXISTS {} ({})'.format(CACHE_TABLE, FIELDS)
CLEAR = 'DELETE FROM LOCATIONS'

def _get_buffer(buf):
    val = buf
    if not isinstance(buf, (basestring)):
            line = buf.tell()
            val = buf.read()
            buf.seek(line)
    return val

Response = namedtuple('Response', ('buffer', 'url', 'fresh'))

def block_and_execute(meth):
    """Wrapper method acquires lock and tries operation until DB is open.

    Args:
        meth (method): to operate on the database.
    """

    def _method(self, *args, **kwargs):
        while True:
            try:
                self._lock.acquire()
                result = meth(self, *args, **kwargs)
            except sqlite3.OperationalError:
                pass
            except Exception:
                raise
            else:
                break
            finally:
                self._lock.release()
        return result
    return _method

class Cache(object):

    """Lightweight sqlite3 interface for CRUD transactions into a URL cache."""

    def __init__(self):
        self.conn = sqlite3.connect(CACHE_FILE,
                                    detect_types=sqlite3.PARSE_DECLTYPES)
        self.conn.text_factory = BytesIO
        self.cursor = self.conn.cursor()
        self._lock = threading.Lock()
        self.create()

    @block_and_execute
    def create(self):
        """Create a cache table."""
        self.conn.execute(CREATE, ())

    def close(self):
        """Close the database connection and release the cursor."""
        self.conn.close()

    @block_and_execute
    def last_modified(self, url):
        """Retrive the last modification datetime for a given url.

        Args:
            url (string): the url to retrieve.

        Returns:
            last_mod (datetime.datetime): last updated. Sqlite3 automatically
                converts to datetime.datetime because detect_types is set.
        """
        self.cursor.execute(LAST_MOD, (url,))
        last_mod = self.cursor.fetchone()
        if last_mod and last_mod[0]:
            return last_mod[0]

    @block_and_execute
    def add(self, url, buf, overwrite=False, commit=True):
        """Add a location to the cache.

        Args:
            url (string): the url to save the object to.
            buf (misc., sqlite3-adapted): the buffer to be saved to the cache.
                Note that this argument must have been adapted for sqlite3
                insertion. BytesIO, strings, unicode and core Python types are
                all acceptable.
            overwrite (bool): if True, the cache will overwrite pre-existing
                entries for the same url.
            commit (bool): if True, the Cache will commit the insert after.
                This should be false where a large group of inserts is
                anticipated, to improve performance. In that case, a manual
                commit should be issued after.
        """
        val = _get_buffer(buf)
        try:
            self.cursor.execute(INSERT, (val, url))
            if commit:
                self.conn.commit()
        except sqlite3.IntegrityError:
            if overwrite:
                val = _get_buffer(buf)
                now = datetime.datetime.now()
                self.cursor.execute(UPDATE, (val, now, url))
                if commit:
                    self.conn.commit()

    @block_and_execute
    def load(self, url):
        """Load a cached location from the cache.

        Args:
            url (string): the url of the location to be loaded.

        Returns:
            response (Response): a Response object containing the url (string)
                and buffer (BytesIO).
        """
        self.cursor.execute(SELECT, (url,))
        content = self.cursor.fetchone()
        if content:
            content = content[0]
            if isinstance(content, buffer):
                content = BytesIO(content)
            return Response(content, url, False)

    @block_and_execute
    def clear(self):
        """Empty the cache."""
        self.cursor.execute(CLEAR)
        self.conn.commit()


text:
"""
Author: torcellite
Date of Creation: 12/14/2014
"""

import os
import jinja2
import logging
import webapp2

from translate import Translate

from lib.microsofttranslator import Translator as MicrosoftTranslator

JINJA_ENVIRONMENT = jinja2.Environment(
    loader=jinja2.FileSystemLoader(os.path.abspath(
        os.path.join(os.path.dirname(__file__), os.pardir))),
    extensions=['jinja2.ext.autoescape'],
    autoescape=True)

client_id = 'client_id'
client_secret = 'client_secret'

debug = False

"""Get Client ID and Client Secret
"""

class CredentialsPage(webapp2.RequestHandler):

    def __init__(self, request, response):
        self.initialize(request, response)

    def get(self):
        template = JINJA_ENVIRONMENT.get_template('static/index.html')
        template_values = {}
        self.response.write(template.render(template_values))

"""Handle the main page requests - /
   __init__:
    Initialize a goslate object to retrieve the language list.
   post:
    Populate the select list with the retrieved languages.
"""

class MainPage(webapp2.RequestHandler):

    def __init__(self, request, response):
        self.initialize(request, response)

    def post(self):
        global client_id
        client_id = self.request.get('client_id')
        global client_secret
        client_secret = self.request.get('client_secret')
        microsofttranslator = MicrosoftTranslator(client_id,
                                                  client_secret,
                                                  debug=debug)
        if microsofttranslator.get_access_token() == 400:
            self.response.write(
                """Invalid Client ID or Client Secret,
                   go back and try again.""")
            return
        languages = microsofttranslator.get_languages()
        languages.sort()
        template_values = {
            'languages': languages
        }
        template = JINJA_ENVIRONMENT.get_template('static/main.html')
        self.response.write(template.render(template_values))

"""Handle the translate page requests - /translate
"""

class Translator(webapp2.RequestHandler):

    def __init__(self, request, response):
        self.initialize(request, response)
        self.request = request
        self.to_lang = None
        self.from_lang = None
        self.translated = None
        self.extra_tags = None
        self.store_listing = False

    def post(self):
        strings_xml = self.request.get('strings_xml')
        self.to_lang = self.request.get('languages')
        self.extra_tags = self.request.get('extra_tags').split(',')
        if 'store_listing' in self.request.POST:
            self.store_listing = True
        translator = Translate(client_id=client_id,
                               client_secret=client_secret,
                               xml_string=strings_xml,
                               to_lang=self.to_lang,
                               extra_tags=self.extra_tags,
                               store_listing=self.store_listing,
                               debug=debug)
        two_tuple = translator.translate()
        self.translated = two_tuple[0]
        self.from_lang = two_tuple[1]
        if self.translated == 'session expired':
            self.response.write(
                """Your session has expired,
                   go back and try again.""")
            return
        elif self.translated == 'Expat Error':
            self.response.write(
                'Looks like something is wrong with your XML file.\n' +
                self.from_lang)
        template_values = {
            'strings_xml': strings_xml,
            'new_strings_xml': self.translated.decode('utf-8'),
            'original_language': 'values-' + self.from_lang + '/strings.xml',
            'translated_language': 'values-' + self.to_lang + '/strings.xml'
        }
        template = JINJA_ENVIRONMENT.get_template('static/translate.html')
        self.response.write(template.render(template_values))

application = webapp2.WSGIApplication([
    ('/', CredentialsPage),
    ('/main', MainPage),
    ('/translate', Translator),
], debug=debug)


text:
export PKG_NAME=$1

for p in "${@:2}"
do
export CPATH=$p/include:$CPATH LIBRARY_PATH=$p/lib:$LIBRARY_PATH LD_LIBRARY_PATH=$p/lib:$LD_LIBRARY_PATH
done

( python2 -m pip >/dev/null || curl -Ls https://bootstrap.pypa.io/get-pip.py | python2 - --user )
python2 -m pip install --user virtualenv
python2 -m virtualenv /tmp/test_py2
sed -i -E -e "/python_requires/d" setup.py
bash -c "source /tmp/test_py2/bin/activate; pip install 'numpy<1.17' pytest '.[all]' && pytest -rs --pyargs ${PKG_NAME} -k not test_run_integration"


text:
{% extends "lifeflow/editor/base.html" %}

{% block body %}

  Blogroll
   Sites-to-Ping
   Site Config

{% block body2 %}{% endblock %}

{% endblock %}


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
Grevillea 6(no. 39): 85 (1878)

#### Original name
Pestalotia clavata Cooke & Ellis

### Remarks
null


text:
layout: post
title: Custom Color Scheme
category: note
tags: curtana
scheme-text: "#0029ff"
scheme-link: "#ff00b4"
scheme-hover: "#ff00b4"
scheme-code: "#ad00ff"
scheme-bg: "#00ebff"
scheme-hero-text: "#00ebff"
scheme-hero-link: "#00ebff"
scheme-hero-bg: "#0029ff"
---

This is an example how to change your post color scheme for specific posts. You can simply add the following variables to your post [front-matter field](https://jekyllrb.com/docs/frontmatter/):

```
scheme-text: "#0029ff"
scheme-link: "#ff00b4"
scheme-hover: "#ff00b4"
scheme-code: "#ad00ff"
scheme-bg: "#00ebff"
scheme-hero-text: "#00ebff"
scheme-hero-link: "#00ebff"
scheme-hero-bg: "#0029ff"
```

You can also ignore other variables if you only want to change the background:

```
scheme-bg: "#00ebff"
```


text:
package com.venmo.android.pin.pindemo.demo;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.venmo.android.pin.PinListener;
import com.venmo.android.pin.PinFragment;
import com.venmo.android.pin.util.PinHelper;

public class PinDemoActivity extends Activity implements PinListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pin_demo);
        Fragment toShow = PinHelper.hasDefaultPinSaved(this) ?
                PinFragment.newInstanceForVerification() :
                PinFragment.newInstanceForCreation();

        getFragmentManager().beginTransaction()
                .replace(R.id.root, toShow, toShow.getClass().getSimpleName())
                .commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.pin_demo, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            PinHelper.resetDefaultSavedPin(this);
            recreate();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onValidated() {
        Toast.makeText(this, "Validated PIN!", Toast.LENGTH_SHORT).show();
        recreate();
    }

    @Override
    public void onPinCreated() {
        Toast.makeText(this, "Created PIN!", Toast.LENGTH_SHORT).show();
        recreate();
    }

}


text:
    Overview

    History

    Settings

{% ifequal section "overview" %}
{% include "normal/normal_overview.html" %}
{% endifequal %}
{% ifequal section "history" %}
{% include "normal/normal_history.html" %}
{% endifequal %}
{% ifequal section "settings" %}
{% include "settings.html" %}
{% endifequal %}


text:
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new klgForm());
        }
    }
}


text:
namespace content {

NotificationResources::NotificationResources() {}

NotificationResources::NotificationResources(
    const NotificationResources& other) = default;

NotificationResources::~NotificationResources() {}

}  // namespace content


text:
module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jshint: {
      all: [ 'Gruntfile.js', 'owl-carousel/owl.carousel.js' ]
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: 'owl-carousel/owl.carousel.js',
        dest: 'owl-carousel/owl.carousel.min.js'
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Load the plugin that provides the "jshint" task.
  grunt.loadNpmTasks('grunt-contrib-jshint');

  // Default task(s).
  grunt.registerTask('default', ['jshint', 'uglify']);

};


text:
#!/bin/sh
# Copyright 2019, The Tor Project, Inc.
# See LICENSE for licensing information

# Integration test for checkSpace.pl, which we want to rewrite.

umask 077
set -e

# Skip this test if we're running on Windows; we expect line-ending
# issues in that case.
case "$(uname -s)" in
    CYGWIN*) WINDOWS=1;;
    MINGW*) WINDOWS=1;;
    MSYS*) WINDOWS=1;;
    *) WINDOWS=0;;
esac
if test "$WINDOWS" = 1; then
    # This magic value tells automake that the test has been skipped.
    exit 77
fi

# make a safe space for temporary files
DATA_DIR=$(mktemp -d -t tor_checkspace_tests.XXXXXX)
trap 'rm -rf "$DATA_DIR"' 0

RECEIVED_FNAME="${DATA_DIR}/got.txt"

cd "$(dirname "$0")/checkspace_tests"

# we expect this to give an error code.
../checkSpace.pl -C ./*.[ch] ./*/*.[ch] > "${RECEIVED_FNAME}" && exit 1

diff -u expected.txt "${RECEIVED_FNAME}" || exit 1

echo "OK"


text:
package ru.job4j.tree;

/**
 * Task tree.
 *
 * @author Dmitriy Bobrov (bobrov.dmitriy@gmail.com)
 * @since 14.08.2017
 * @param <E>
 */

public interface SimpleTree<E extends Comparable<E>> extends Iterable<E> {
    /**
     * Add child in parent.
     * Parent can have list of child
     *
     * @param parent input parent value.
     * @param child input child value.
     * @return boolean.
     */
    boolean add(E parent, E child);
}


text:
using Moyd.Api.BungieApi;
using Moyd.Api.Services;
using Ninject.Modules;

namespace Moyd.App
{
    public class AppModule : NinjectModule
    {
        public override void Load()
        {
            Bind<SearchService>().ToSelf().InSingletonScope();
            Bind<IBungieHttpClient>().To<BungieHttpClient>().InSingletonScope();
        }
    }
}


text:
class Spree::TempPoItem < ActiveRecord::Base

end


text:
package com.l000phone.themovietime.discover.bean;

/**
 *
 */
public class TopListDetailsBean1 {
    private String actor;
    private String director;
    private String id;
    private String movieType;
    private String name;
    private String nameEn;
    private String posterUrl;
    private String rankNum;
    private String rating;
    private String releaseDate;
    private String releaseLocation;
    private String remark;

    public String getActor() {
        return actor;
    }

    public void setActor(String actor) {
        this.actor = actor;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMovieType() {
        return movieType;
    }

    public void setMovieType(String movieType) {
        this.movieType = movieType;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNameEn() {
        return nameEn;
    }

    public void setNameEn(String nameEn) {
        this.nameEn = nameEn;
    }

    public String getPosterUrl() {
        return posterUrl;
    }

    public void setPosterUrl(String posterUrl) {
        this.posterUrl = posterUrl;
    }

    public String getRankNum() {
        return rankNum;
    }

    public void setRankNum(String rankNum) {
        this.rankNum = rankNum;
    }

    public String getRating() {
        return rating;
    }

    public void setRating(String rating) {
        this.rating = rating;
    }

    public String getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(String releaseDate) {
        this.releaseDate = releaseDate;
    }

    public String getReleaseLocation() {
        return releaseLocation;
    }

    public void setReleaseLocation(String releaseLocation) {
        this.releaseLocation = releaseLocation;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}


text:
import uuid
import logging
from threading import Thread
from props import prop
from NotificationCenter import NotificationCenter
from Template import Template
from PluginManager import PluginManager
from ApplicationConfiguration import ApplicationConfiguration
from PersistentImageManager import PersistentImageManager
from BaseImage import BaseImage
from TargetImage import TargetImage
from ProviderImage import ProviderImage
from ImageFactoryException import ImageFactoryException
from CallbackWorker import CallbackWorker
from time import sleep

class Builder(object):
    """ TODO: Docstring for Builder  """

##### PROPERTIES
    os_plugin = prop("_os_plugin")
    cloud_plugin = prop("_cloud_plugin")
    base_image = prop("_base_image")
    target_image = prop("_target_image")
    provider_image = prop("_provider_image")
    image_metadata = prop("_image_metadata")

##### INITIALIZER
    def __init__(self):
        self.log = logging.getLogger('%s.%s' % (__name__, self.__class__.__name__))
        self.app_config = ApplicationConfiguration().configuration
        self.notification_center = NotificationCenter()
        self.pim = PersistentImageManager.default_manager()
        self._os_plugin = None
        self._cloud_plugin = None
        self._base_image = None
        self._base_image_cbws = [ ]
        self._target_image = None
        self._target_image_cbws = [ ]
        self._provider_image = None
        self._provider_image_cbws = [ ]
        self._deletion_cbws = []
        self.base_thread = None
        self.target_thread = None
        self.push_thread = None
        self.snapshot_thread = None
        try:
            from imgfac.secondary.SecondaryDispatcher import SecondaryDispatcher
            from imgfac.secondary.SecondaryPlugin import SecondaryPlugin
            self.secondary_dispatcher = SecondaryDispatcher()
        except:
            self.log.debug("No SecondaryDispatcher present - Use of secondary factories is not enabled")
            self.secondary_dispatcher = None

#####  SETUP CALLBACKS
    def _init_callback_workers(self, image, callbacks, callbackworkers):
        for callback_url in callbacks:
            self.log.debug("Seeting up callback worker for (%s)" % (callback_url))
            worker = CallbackWorker(callback_url)
            worker.start()
            callbackworkers.append(worker)
            self.notification_center.add_observer(worker, 'status_notifier', 'image.status', sender = image)

    def _shutdown_callback_workers(self, image, callbackworkers):
        for worker in callbackworkers:
            self.notification_center.remove_observer(worker, 'status_notifier', 'image.status', sender = image)
            worker.shut_down()

#####  PENDING BUILD HELPERS
    def _wait_for_final_status(self, image):
        image_id = image.identifier
        self.log.debug("Waiting for image of type (%s) and id (%s) to enter a final status" % (str(type(image)), image_id ) )
        # Wait forever - Short of a factory crash, we have timeouts elsewhere that should ensure
        #                that the pending images eventually hit success or failure
        while(True):
            # Our local image object isn't necessarily the one that is being actively updated
            # In fact, we know it isn't.  It has been created out of a PIM retrieval.
            # To update its metadata, we just re-fetch it.
            image = self.pim.image_with_id(image_id)
            if image.status not in [ 'NEW','PENDING' ]:
                self.log.debug("Image of type (%s) entered final status of (%s)" % (str(type(image)), image.status) )
                return image
            sleep(5)

#####  BUILD IMAGE
    def build_image_from_template(self, template, parameters=None):
        """
        TODO: Docstring for build_image_from_template

        @param template TODO

        @return TODO
        """
        # Create what is essentially an empty BaseImage here
        self.base_image = BaseImage()
        self.base_image.template = template
        if parameters:
            self.base_image.parameters = parameters
        self.pim.add_image(self.base_image)
        if parameters and ('callbacks' in parameters):
            # This ensures we have workers in place before any potential state changes
            self._init_callback_workers(self.base_image, parameters['callbacks'], self._base_image_cbws)

        thread_name = str(uuid.uuid4())[0:8]
        thread_kwargs = {'template':template, 'parameters':parameters}
        self.base_thread = Thread(target=self._build_image_from_template, name=thread_name, args=(), kwargs=thread_kwargs)
        self.base_thread.start()

    def _build_image_from_template(self, template, parameters=None):
        try:
            template = template if(isinstance(template, Template)) else Template(template)
            plugin_mgr = PluginManager(self.app_config['plugins'])
            self.os_plugin = plugin_mgr.plugin_for_target((template.os_name, template.os_version, template.os_arch))
            self.base_image.status="BUILDING"
            self.os_plugin.create_base_image(self, template, parameters)
            # This implies a convention where the plugin can never dictate completion and must indicate failure
            # via an exception
            self.base_image.status_detail = { 'activity': 'Base Image build complete', 'error':None }
            self.base_image.status="COMPLETE"
            self.pim.save_image(self.base_image)
        except Exception, e:
            self.base_image.status_detail = {'activity': 'Base Image build failed with exception.', 'error': str(e)}
            self.base_image.status="FAILED"
            self.pim.save_image(self.base_image)
            self.log.error("Exception encountered in _build_image_from_template thread")
            self.log.exception(e)
        finally:
            # We only shut the workers down after a known-final state change
            self._shutdown_callback_workers(self.base_image, self._base_image_cbws)

##### CUSTOMIZE IMAGE FOR TARGET
    def customize_image_for_target(self, target, image_id=None, template=None, parameters=None):
        """
        TODO: Docstring for customize_image_for_target

        @param factory_image TODO
        @param target TODO
        @param target_params TODO

        @return TODO
        """

        self.target_image = TargetImage()
        self.target_image.target = target
        self.target_image.base_image_id = image_id
        self.target_image.template = template
        if parameters:
            self.target_image.parameters = parameters
        self.pim.add_image(self.target_image)
        if parameters and ('callbacks' in parameters):
            # This ensures we have workers in place before any potential state changes
            self._init_callback_workers(self.target_image, parameters['callbacks'], self._target_image_cbws)

        if(image_id and (not template)):
            self.base_image = self.pim.image_with_id(image_id)
            template = self.base_image.template
            self.target_image.template = template
        elif template:
            self.build_image_from_template(template, parameters)
            # Populate the base_image property of our target image correctly
            # (The ID value is always available immediately after the call above)
            image_id = self.base_image.identifier
            self.target_image.base_image_id = self.base_image.identifier
        elif template and image_id:
            raise ImageFactoryException("Must specify either a template or a BaseImage ID, not both")
        else:
            raise ImageFactoryException("Asked to create a TargetImage without a BaseImage or a template")

        # Both base_image and target_image exist at this point and have IDs and status
        # We can now launch our thread and return to the caller

        thread_name = str(uuid.uuid4())[0:8]
        thread_kwargs = {'target':target, 'image_id':image_id, 'template':template, 'parameters':parameters}
        self.target_thread = Thread(target=self._customize_image_for_target, name=thread_name, args=(), kwargs=thread_kwargs)
        self.target_thread.start()

    def _customize_image_for_target(self, target, image_id=None, template=None, parameters=None):
        try:
            # If there is an ongoing base image build that we started, wait for it to finish
            if self.base_thread:
                self.target_image.status="PENDING"
                threadname=self.base_thread.getName()
                self.log.debug("Waiting for our BaseImage builder thread (%s) to finish" % (threadname))
                self.base_thread.join()
                self.log.debug("BaseImage builder thread (%s) finished - continuing with TargetImage tasks" % (threadname))

            # If we were called against an ongoing base_image build, wait for a terminal status on it
            if self.base_image.status in [ "NEW", "PENDING" ]:
                self.target_image.status="PENDING"
                self.base_image = self._wait_for_final_status(self.base_image)

            if self.base_image.status == "FAILED":
                raise ImageFactoryException("The BaseImage (%s) for our TargetImage has failed its build.  Cannot continue." % (self.base_image.identifier))

            if self.base_image.status != "COMPLETE":
                raise ImageFactoryException("Got to TargetImage build step with a BaseImage status of (%s).  This should never happen.  Aborting." % (self.base_image.status))

            # Only at this point can we be sure that our base_image has icicle associated with it
            self.target_image.icicle = self.base_image.icicle

            template = template if(isinstance(template, Template)) else Template(template)

            plugin_mgr = PluginManager(self.app_config['plugins'])

            # It's possible this has already been set by the base_image creation above
            if not self.os_plugin:
                self.os_plugin = plugin_mgr.plugin_for_target((template.os_name, template.os_version, template.os_arch))

            self.cloud_plugin = plugin_mgr.plugin_for_target(target)
            if not self.cloud_plugin:
                self.log.warn("Unable to find cloud plugin for target (%s)" % (target))

            self.target_image.status = "BUILDING"
            if(hasattr(self.cloud_plugin, 'builder_should_create_target_image')):
                _should_create = self.cloud_plugin.builder_should_create_target_image(self, target, image_id, template, parameters)
            else:
                _should_create = True
            if(_should_create and hasattr(self.cloud_plugin, 'builder_will_create_target_image')):
                self.cloud_plugin.builder_will_create_target_image(self, target, image_id, template, parameters)
            if(_should_create):
                if(hasattr(self.os_plugin, 'create_target_image')):
                    self.os_plugin.create_target_image(self, target, image_id, parameters)
                if(hasattr(self.cloud_plugin, 'builder_did_create_target_image')):
                    self.cloud_plugin.builder_did_create_target_image(self, target, image_id, template, parameters)
            self.target_image.status_detail = { 'activity': 'Target Image build complete', 'error':None }
            self.target_image.status = "COMPLETE"
            self.pim.save_image(self.target_image)
        except Exception, e:
            self.target_image.status_detail={'activity': 'Target Image build failed with exception', 'error': str(e)}
            self.target_image.status = "FAILED"
            self.pim.save_image(self.target_image)
            self.log.error("Exception encountered in _customize_image_for_target thread")
            self.log.exception(e)
        finally:
            # We only shut the workers down after a known-final state change
            self._shutdown_callback_workers(self.target_image, self._target_image_cbws)

##### CREATE PROVIDER IMAGE
    def create_image_on_provider(self, provider, credentials, target, image_id=None, template=None, parameters=None, my_image_id = None):
        if(parameters and parameters.get('snapshot', False)):
            self.snapshot_image(provider, credentials, target, image_id, template, parameters, my_image_id)
        else:
            self.push_image_to_provider(provider, credentials, target, image_id, template, parameters, my_image_id)

##### PUSH IMAGE TO PROVIDER
    def push_image_to_provider(self, provider, credentials, target, image_id, template, parameters, my_image_id):
        """
        TODO: Docstring for push_image_to_provider

        @param image TODO
        @param provider TODO
        @param credentials TODO
        @param provider_params TODO

        @return TODO
        """

        # If operating as a secondary we will have the provider_image ID dictated to us - otherwise it is None and it is created
        self.provider_image = ProviderImage(image_id = my_image_id)
        self.provider_image.provider = provider
        self.provider_image.credentials = credentials
        self.provider_image.target_image_id = image_id
        self.provider_image.template = template
        self.pim.add_image(self.provider_image)
        if parameters and ('callbacks' in parameters):
            # This ensures we have workers in place before any potential state changes
            self._init_callback_workers(self.provider_image, parameters['callbacks'], self._provider_image_cbws)

        if(image_id and (not template)):
            self.target_image = self.pim.image_with_id(image_id)
            if not self.target_image:
                raise ImageFactoryException("Unable to retrieve target image with id (%s) from storage" % (image_id))
            # If we are being called as a secondary do not try to look up the base image
            if not my_image_id:
                self.base_image = self.pim.image_with_id(self.target_image.base_image_id)
                if not self.base_image:
                    raise ImageFactoryException("Unable to retrieve base image with id (%s) from storage" % (image_id))
            template = self.target_image.template
            self.provider_image.template = template
        elif template and image_id:
            raise ImageFactoryException("Must specify either a template or a TargetImage ID, not both")
        elif template:
            self.customize_image_for_target(target=target , image_id=None, template=template, parameters=parameters)
            # Populate the target_image value of our provider image properly
            # (The ID value is always available immediately after the call above)
            # self.base_image is created in cascading fashion from the above call
            image_id = self.target_image.identifier
            self.provider_image.target_image_id = self.target_image.identifier
        else:
            raise ImageFactoryException("Asked to create a ProviderImage without a TargetImage or a template")

        thread_name = str(uuid.uuid4())[0:8]
        thread_kwargs = {'provider':provider, 'credentials':credentials, 'target':target, 'image_id':image_id, 'template':template, 'parameters':parameters}
        self.push_thread = Thread(target=self._push_image_to_provider, name=thread_name, args=(), kwargs=thread_kwargs)
        self.push_thread.start()

    def _push_image_to_provider(self, provider, credentials, target, image_id, template, parameters):
        try:
            # If there is an ongoing target_image build that we started, wait for it to finish
            if self.target_thread:
                self.provider_image.status = "PENDING"
                threadname=self.target_thread.getName()
                self.log.debug("Waiting for our TargetImage builder thread (%s) to finish" % (threadname))
                self.target_thread.join()
                self.log.debug("TargetImage builder thread (%s) finished - continuing with ProviderImage tasks" % (threadname))

            # If we were called against an ongoing target_image build, wait for a terminal status on it
            if self.target_image.status in [ "NEW", "PENDING" ]:
                self.provider_image.status = "PENDING"
                self.target_image = self._wait_for_final_status(self.target_image)

            if self.target_image.status == "FAILED":
                raise ImageFactoryException("The TargetImage (%s) for our ProviderImage has failed its build.  Cannot continue." % (self.target_image.identifier))

            if self.target_image.status != "COMPLETE":
                raise ImageFactoryException("Got to ProviderImage build step with a TargetImage status of (%s).  This should never happen.  Aborting." % (self.target_image.status))

            # Only at this point can we be sure that our target_image has icicle associated with it
            self.provider_image.icicle = self.target_image.icicle

            template = template if(isinstance(template, Template)) else Template(template)

            if not self.app_config['secondary'] and self.secondary_dispatcher:
                secondary = self.secondary_dispatcher.get_secondary(target, provider)
            else:
                # Do not allow nesting of secondaries and do not try to use the dispatcher if it is not present
                secondary = None

            if secondary:
                # NOTE: This may overwrite the cloud_plugin that was used to create the target_image
                #       This is expected and is correct
                self.cloud_plugin = SecondaryPlugin(SecondaryDispatcher().get_helper(secondary))
            else:
                plugin_mgr = PluginManager(self.app_config['plugins'])
                if not self.cloud_plugin:
                    self.cloud_plugin = plugin_mgr.plugin_for_target(target)
            self.provider_image.status="BUILDING"
            self.cloud_plugin.push_image_to_provider(self, provider, credentials, target, image_id, parameters)
            self.provider_image.status_detail = { 'activity': 'Provider Image build complete', 'error':None }
            self.provider_image.status="COMPLETE"
            self.pim.save_image(self.provider_image)
        except Exception, e:
            self.provider_image.status_detail={'activity': 'Provider Image build failed with exception', 'error': str(e)}
            self.provider_image.status="FAILED"
            self.pim.save_image(self.provider_image)
            self.log.error("Exception encountered in _push_image_to_provider thread")
            self.log.exception(e)
        finally:
            # We only shut the workers down after a known-final state change
            self._shutdown_callback_workers(self.provider_image, self._provider_image_cbws)

##### SNAPSHOT IMAGE
    def snapshot_image(self, provider, credentials, target, image_id, template, parameters, my_image_id):
        """
        TODO: Docstring for snapshot_image

        @param template TODO
        @param target TODO
        @param provider TODO
        @param credentials TODO
        @param snapshot_params TODO

        @return TODO
        """

        # If operating as a secondary we will have the provider_image ID dictated to us - otherwise it is None and it is created
        self.provider_image = ProviderImage(image_id = my_image_id)
        self.provider_image.provider = provider
        self.provider_image.credentials = credentials
        self.provider_image.target_image_id = image_id
        self.provider_image.template = template
        self.pim.add_image(self.provider_image)
        if parameters and ('callbacks' in parameters):
            # This ensures we have workers in place before any potential state changes
            self._init_callback_workers(self.provider_image, parameters['callbacks'], self._provider_image_cbws)

        if not template:
            raise ImageFactoryException("Must specify a template when requesting a snapshot-style build")

        thread_name = str(uuid.uuid4())[0:8]
        thread_kwargs = {'provider':provider, 'credentials':credentials, 'target':target, 'image_id':image_id, 'template':template, 'parameters':parameters}
        self.snapshot_thread = Thread(target=self._snapshot_image, name=thread_name, args=(), kwargs=thread_kwargs)
        self.snapshot_thread.start()

    def _snapshot_image(self, provider, credentials, target, image_id, template, parameters):
        try:
            if not self.app_config['secondary'] and self.secondary_dispatcher:
                secondary = self.secondary_dispatcher.get_secondary(target, provider)
            else:
                # Do not allow nesting of secondaries and do not try to use the dispatcher if it is not present
                secondary = None

            if secondary:
                self.cloud_plugin = SecondaryPlugin(SecondaryDispatcher().get_helper(secondary))
            else:
                plugin_mgr = PluginManager(self.app_config['plugins'])
                self.cloud_plugin = plugin_mgr.plugin_for_target(target)
            self.provider_image.status="BUILDING"
            self.cloud_plugin.snapshot_image_on_provider(self, provider, credentials, target, template, parameters)
            self.provider_image.status_detail = { 'activity': 'Provider Image build complete', 'error':None }
            self.provider_image.status="COMPLETE"
            self.pim.save_image(self.provider_image)
        except Exception, e:
            self.provider_image.status_detail = {'activity': 'Provider Image build failed with exception',
                                                 'error': str(e)}
            self.provider_image.status="FAILED"
            self.pim.save_image(self.provider_image)
            self.log.error("Exception encountered in _snapshot_image thread")
            self.log.exception(e)
        finally:
            # We only shut the workers down after a known-final state change
            self._shutdown_callback_workers(self.provider_image, self._provider_image_cbws)

##### DELETE IMAGE
    def delete_image(self, provider, credentials, target, image_object, parameters):
        """
        Delete an image of any type - We only need plugin-specific methods to delete ProviderImages
        Both TargetImages and BaseImages can be deleted directly at the PersistentImageManager layer only.

        @param provider - XML or JSON provider definition - None if not a ProviderImage
        @param credentials - Credentials for the given provider - None if not a ProviderImage
        @param target - Target type if applicable - None if not
        @param image_object - Already-retrieved and populated PersistentImage object
        @param parameters TODO

        @return TODO
        """
        if parameters and ('callbacks' in parameters):
            # This ensures we have workers in place before any potential state changes
            self._init_callback_workers(image_object, parameters['callbacks'], self._deletion_cbws)

        thread_name = str(uuid.uuid4())[0:8]
        thread_kwargs = {'provider':provider, 'credentials':credentials, 'target':target, 'image_object':image_object, 'parameters':parameters}
        self.delete_thread = Thread(target=self._delete_image, name=thread_name, args=(), kwargs=thread_kwargs)
        self.delete_thread.start()

    def _delete_image(self, provider, credentials, target, image_object, parameters):
        try:
            image_object.status = "DELETING"
            if type(image_object).__name__ == "ProviderImage":
                self.provider_image = image_object
                plugin_mgr = PluginManager(self.app_config['plugins'])
                self.cloud_plugin = plugin_mgr.plugin_for_target(target)
                self.cloud_plugin.delete_from_provider(self, provider, credentials, target, parameters)
            self.pim.delete_image_with_id(image_object.identifier)
            image_object.status_detail = {'activity': 'Image deleted.', 'error': None}
            image_object.status = "DELETED"
        except Exception, e:
            image_object.status_detail = {'activity': 'Failed to delete image.', 'error': str(e)}
            image_object.status="DELETEFAILED"
            self.pim.save_image(image_object)
            self.log.error("Exception encountered in _delete_image_on_provider thread")
            self.log.exception(e)
        finally:
            # We only shut the workers down after a known-final state change
            self._shutdown_callback_workers(image_object, self._deletion_cbws)