text:
"""Tests for :mod:`sphinxcontrib.napoleon.docstring` module."""

from collections import namedtuple

# inspect.cleandoc() implements the trim() function from PEP 257
from inspect import cleandoc
from textwrap import dedent
from sphinxcontrib.napoleon import Config
from sphinxcontrib.napoleon.docstring import GoogleDocstring, NumpyDocstring
from unittest import TestCase

try:
    # Python >=3.3
    from unittest.mock import Mock
except ImportError:
    from mock import Mock

class NamedtupleSubclass(namedtuple('NamedtupleSubclass', ('attr1', 'attr2'))):
    """Sample namedtuple subclass

    Attributes
    ----------
    attr1 : Arbitrary type
        Quick description of attr1
    attr2 : Another arbitrary type
        Quick description of attr2
    attr3 : Type

        Adds a newline after the type

    """
    # To avoid creating a dict, as a namedtuple doesn't have it:
    __slots__ = ()

    def __new__(cls, attr1, attr2=None):
        return super(NamedtupleSubclass, cls).__new__(cls, attr1, attr2)

class BaseDocstringTest(TestCase):
    pass

class NamedtupleSubclassTest(BaseDocstringTest):
    def test_attributes_docstring(self):
        config = Config()
        actual = str(NumpyDocstring(cleandoc(NamedtupleSubclass.__doc__),
                     config=config, app=None, what='class',
                     name='NamedtupleSubclass', obj=NamedtupleSubclass))
        expected = """\
Sample namedtuple subclass

.. attribute:: attr1

   *Arbitrary type* -- Quick description of attr1

.. attribute:: attr2

   *Another arbitrary type* -- Quick description of attr2

.. attribute:: attr3

   *Type* -- Adds a newline after the type
"""

        self.assertEqual(expected, actual)

class GoogleDocstringTest(BaseDocstringTest):
    docstrings = [(
        """Single line summary""",
        """Single line summary"""
    ), (
        """
        Single line summary

        Extended description

        """,
        """
        Single line summary

        Extended description
        """
    ), (
        """
        Single line summary

        Args:
          arg1(str):Extended
            description of arg1
        """,
        """
        Single line summary

        :Parameters: **arg1** (*str*) -- Extended
                     description of arg1
        """
    ), (
        """
        Single line summary

        Args:
          arg1(str):Extended
            description of arg1
          arg2 ( int ) : Extended
            description of arg2

        Keyword Args:
          kwarg1(str):Extended
            description of kwarg1
          kwarg2 ( int ) : Extended
            description of kwarg2""",
        """
        Single line summary

        :Parameters: * **arg1** (*str*) -- Extended
                       description of arg1
                     * **arg2** (*int*) -- Extended
                       description of arg2

        :Keyword Arguments: * **kwarg1** (*str*) -- Extended
                              description of kwarg1
                            * **kwarg2** (*int*) -- Extended
                              description of kwarg2
        """
    ), (
        """
        Single line summary

        Arguments:
          arg1(str):Extended
            description of arg1
          arg2 ( int ) : Extended
            description of arg2

        Keyword Arguments:
          kwarg1(str):Extended
            description of kwarg1
          kwarg2 ( int ) : Extended
            description of kwarg2""",
        """
        Single line summary

        :Parameters: * **arg1** (*str*) -- Extended
                       description of arg1
                     * **arg2** (*int*) -- Extended
                       description of arg2

        :Keyword Arguments: * **kwarg1** (*str*) -- Extended
                              description of kwarg1
                            * **kwarg2** (*int*) -- Extended
                              description of kwarg2
        """
    ), (
        """
        Single line summary

        Return:
          str:Extended
          description of return value
        """,
        """
        Single line summary

        :returns: *str* -- Extended
                  description of return value
        """
    ), (
        """
        Single line summary

        Returns:
          str:Extended
          description of return value
        """,
        """
        Single line summary

        :returns: *str* -- Extended
                  description of return value
        """
    ), (
        """
        Single line summary

        Returns:
          Extended
          description of return value
        """,
        """
        Single line summary

        :returns: Extended
                  description of return value
        """
    ), (
        """
        Single line summary

        Args:
          arg1(str):Extended
            description of arg1
          *args: Variable length argument list.
          **kwargs: Arbitrary keyword arguments.
        """,
        """
        Single line summary

        :Parameters: * **arg1** (*str*) -- Extended
                       description of arg1
                     * **\\*args** -- Variable length argument list.
                     * **\\*\\*kwargs** -- Arbitrary keyword arguments.
        """
    ), (
        """
        Single line summary

        Yield:
          str:Extended
          description of yielded value
        """,
        """
        Single line summary

        :Yields: *str* -- Extended
                 description of yielded value
        """
    ), (
        """
        Single line summary

        Yields:
          Extended
          description of yielded value
        """,
        """
        Single line summary

        :Yields: Extended
                 description of yielded value
        """
    )]

    def test_docstrings(self):
        config = Config(napoleon_use_param=False, napoleon_use_rtype=False)
        for docstring, expected in self.docstrings:
            actual = str(GoogleDocstring(dedent(docstring), config))
            expected = dedent(expected)
            self.assertEqual(expected, actual)

    def test_parameters_with_class_reference(self):
        docstring = """\
Construct a new XBlock.

This class should only be used by runtimes.

Arguments:
    runtime (:class:`Runtime`): Use it to access the environment.
        It is available in XBlock code as ``self.runtime``.

    field_data (:class:`FieldData`): Interface used by the XBlock
        fields to access their data from wherever it is persisted.

    scope_ids (:class:`ScopeIds`): Identifiers needed to resolve scopes.

"""

        actual = str(GoogleDocstring(docstring))
        expected = """\
Construct a new XBlock.

This class should only be used by runtimes.

:param runtime: Use it to access the environment.
                It is available in XBlock code as ``self.runtime``.

:type runtime: :class:`Runtime`
:param field_data: Interface used by the XBlock
                   fields to access their data from wherever it is persisted.

:type field_data: :class:`FieldData`
:param scope_ids: Identifiers needed to resolve scopes.

:type scope_ids: :class:`ScopeIds`
"""
        self.assertEqual(expected, actual)

    def test_attributes_with_class_reference(self):
        docstring = """\
Attributes:
    in_attr(:class:`numpy.ndarray`): super-dooper attribute
"""

        actual = str(GoogleDocstring(docstring))
        expected = """\
.. attribute:: in_attr

   :class:`numpy.ndarray` -- super-dooper attribute
"""
        self.assertEqual(expected, actual)

        docstring = """\
Attributes:
    in_attr(numpy.ndarray): super-dooper attribute
"""

        actual = str(GoogleDocstring(docstring))
        expected = """\
.. attribute:: in_attr

   *numpy.ndarray* -- super-dooper attribute
"""
        self.assertEqual(expected, actual)

    def test_code_block_in_returns_section(self):
        docstring = """
Returns:
    foobar: foo::

        codecode
        codecode
"""
        expected = """
:returns: foo::

              codecode
              codecode
:rtype: foobar
"""
        actual = str(GoogleDocstring(docstring))
        self.assertEqual(expected, actual)

    def test_colon_in_return_type(self):
        docstring = """Example property.

Returns:
    :py:class:`~.module.submodule.SomeClass`: an example instance
    if available, None if not available.
"""
        expected = """Example property.

:returns: an example instance
          if available, None if not available.
:rtype: :py:class:`~.module.submodule.SomeClass`
"""
        actual = str(GoogleDocstring(docstring))
        self.assertEqual(expected, actual)

    def test_xrefs_in_return_type(self):
        docstring = """Example Function

Returns:
    :class:`numpy.ndarray`: A :math:`n \\times 2` array containing
    a bunch of math items
"""
        expected = """Example Function

:returns: A :math:`n \\times 2` array containing
          a bunch of math items
:rtype: :class:`numpy.ndarray`
"""
        actual = str(GoogleDocstring(docstring))
        self.assertEqual(expected, actual)

    def test_raises_types(self):
        docstrings = [("""
Example Function

Raises:
    RuntimeError:
        A setting wasn't specified, or was invalid.
    ValueError:
        Something something value error.

""", """
Example Function

:raises: * :exc:`RuntimeError` -- A setting wasn't specified, or was invalid.
         * :exc:`ValueError` -- Something something value error.
"""),
                      ################################
                      ("""
Example Function

Raises:
    InvalidDimensionsError

""", """
Example Function

:raises: :exc:`InvalidDimensionsError`
"""),
                      ################################
                      ("""
Example Function

Raises:
    Invalid Dimensions Error

""", """
Example Function

:raises: Invalid Dimensions Error
"""),
                      ################################
                      ("""
Example Function

Raises:
    Invalid Dimensions Error: With description

""", """
Example Function

:raises: *Invalid Dimensions Error* -- With description
"""),
                      ################################
                      ("""
Example Function

Raises:
    InvalidDimensionsError: If the dimensions couldn't be parsed.

""", """
Example Function

:raises: :exc:`InvalidDimensionsError` -- If the dimensions couldn't be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises:
    Invalid Dimensions Error: If the dimensions couldn't be parsed.

""", """
Example Function

:raises: *Invalid Dimensions Error* -- If the dimensions couldn't be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises:
    If the dimensions couldn't be parsed.

""", """
Example Function

:raises: If the dimensions couldn't be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises:
    :class:`exc.InvalidDimensionsError`

""", """
Example Function

:raises: :class:`exc.InvalidDimensionsError`
"""),
                      ################################
                      ("""
Example Function

Raises:
    :class:`exc.InvalidDimensionsError`: If the dimensions couldn't be parsed.

""", """
Example Function

:raises: :class:`exc.InvalidDimensionsError` -- If the dimensions couldn't """
                          """be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises:
    :class:`exc.InvalidDimensionsError`: If the dimensions couldn't be parsed,
       then a :class:`exc.InvalidDimensionsError` will be raised.

""", """
Example Function

:raises: :class:`exc.InvalidDimensionsError` -- If the dimensions couldn't """
                          """be parsed,
         then a :class:`exc.InvalidDimensionsError` will be raised.
"""),
                      ################################
                      ("""
Example Function

Raises:
    :class:`exc.InvalidDimensionsError`: If the dimensions couldn't be parsed.
    :class:`exc.InvalidArgumentsError`: If the arguments are invalid.

""", """
Example Function

:raises: * :class:`exc.InvalidDimensionsError` -- If the dimensions """
                          """couldn't be parsed.
         * :class:`exc.InvalidArgumentsError` -- If the arguments are invalid.
"""),
                      ################################
                      ("""
Example Function

Raises:
    :class:`exc.InvalidDimensionsError`
    :class:`exc.InvalidArgumentsError`

""", """
Example Function

:raises: * :class:`exc.InvalidDimensionsError`
         * :class:`exc.InvalidArgumentsError`
""")]
        for docstring, expected in docstrings:
            actual = str(GoogleDocstring(docstring))
            self.assertEqual(expected, actual)

    def test_kwargs_in_arguments(self):
        docstring = """Allows to create attributes binded to this device.

Some other paragraph.

Code sample for usage::

  dev.bind(loopback=Loopback)
  dev.loopback.configure()

Arguments:
  **kwargs: name/class pairs that will create resource-managers
    bound as instance attributes to this instance. See code
    example above.
"""
        expected = """Allows to create attributes binded to this device.

Some other paragraph.

Code sample for usage::

  dev.bind(loopback=Loopback)
  dev.loopback.configure()

:param \\*\\*kwargs: name/class pairs that will create resource-managers
                   bound as instance attributes to this instance. See code
                   example above.
"""
        actual = str(GoogleDocstring(docstring))
        self.assertEqual(expected, actual)

class NumpyDocstringTest(BaseDocstringTest):
    docstrings = [(
        """Single line summary""",
        """Single line summary"""
    ), (
        """
        Single line summary

        Extended description

        """,
        """
        Single line summary

        Extended description
        """
    ), (
        """
        Single line summary

        Parameters
        ----------
        arg1:str
            Extended
            description of arg1
        """,
        """
        Single line summary

        :Parameters: **arg1** (*str*) -- Extended
                     description of arg1
        """
    ), (
        """
        Single line summary

        Parameters
        ----------
        arg1:str
            Extended
            description of arg1
        arg2 : int
            Extended
            description of arg2

        Keyword Arguments
        -----------------
          kwarg1:str
              Extended
              description of kwarg1
          kwarg2 : int
              Extended
              description of kwarg2
        """,
        """
        Single line summary

        :Parameters: * **arg1** (*str*) -- Extended
                       description of arg1
                     * **arg2** (*int*) -- Extended
                       description of arg2

        :Keyword Arguments: * **kwarg1** (*str*) -- Extended
                              description of kwarg1
                            * **kwarg2** (*int*) -- Extended
                              description of kwarg2
        """
    ), (
        """
        Single line summary

        Return
        ------
        str
            Extended
            description of return value
        """,
        """
        Single line summary

        :returns: *str* -- Extended
                  description of return value
        """
    ), (
        """
        Single line summary

        Returns
        -------
        str
            Extended
            description of return value
        """,
        """
        Single line summary

        :returns: *str* -- Extended
                  description of return value
        """
    ), (
        """
        Single line summary

        Parameters
        ----------
        arg1:str
             Extended description of arg1
        *args:
            Variable length argument list.
        **kwargs:
            Arbitrary keyword arguments.
        """,
        """
        Single line summary

        :Parameters: * **arg1** (*str*) -- Extended description of arg1
                     * ***args** -- Variable length argument list.
                     * ****kwargs** -- Arbitrary keyword arguments.
        """
    ), (
        """
        Single line summary

        Yield
        -----
        str
            Extended
            description of yielded value
        """,
        """
        Single line summary

        :Yields: *str* -- Extended
                 description of yielded value
        """
    ), (
        """
        Single line summary

        Yields
        ------
        str
            Extended
            description of yielded value
        """,
        """
        Single line summary

        :Yields: *str* -- Extended
                 description of yielded value
        """
    )]

    def test_docstrings(self):
        config = Config(napoleon_use_param=False, napoleon_use_rtype=False)
        for docstring, expected in self.docstrings:
            actual = str(NumpyDocstring(dedent(docstring), config))
            expected = dedent(expected)
            self.assertEqual(expected, actual)

    def test_parameters_with_class_reference(self):
        docstring = """\
Parameters
----------
param1 : :class:`MyClass <name.space.MyClass>` instance

"""

        config = Config(napoleon_use_param=False)
        actual = str(NumpyDocstring(docstring, config))
        expected = """\
:Parameters: **param1** (:class:`MyClass <name.space.MyClass>` instance)
"""
        self.assertEqual(expected, actual)

        config = Config(napoleon_use_param=True)
        actual = str(NumpyDocstring(docstring, config))
        expected = """\
:param param1:
:type param1: :class:`MyClass <name.space.MyClass>` instance
"""
        self.assertEqual(expected, actual)

    def test_parameters_without_class_reference(self):
        docstring = """\
Parameters
----------
param1 : MyClass instance

"""

        config = Config(napoleon_use_param=False)
        actual = str(NumpyDocstring(docstring, config))
        expected = """\
:Parameters: **param1** (*MyClass instance*)
"""
        self.assertEqual(expected, actual)

        config = Config(napoleon_use_param=True)
        actual = str(NumpyDocstring(dedent(docstring), config))
        expected = """\
:param param1:
:type param1: MyClass instance
"""
        self.assertEqual(expected, actual)

    def test_see_also_refs(self):
        docstring = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)

See Also
--------
some, other, funcs
otherfunc : relationship

"""

        actual = str(NumpyDocstring(docstring))

        expected = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)

.. seealso::

   :obj:`some`, :obj:`other`, :obj:`funcs`
   \n\
   :obj:`otherfunc`
       relationship
"""
        self.assertEqual(expected, actual)

        docstring = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)

See Also
--------
some, other, funcs
otherfunc : relationship

"""

        config = Config()
        app = Mock()
        actual = str(NumpyDocstring(docstring, config, app, "method"))

        expected = """\
numpy.multivariate_normal(mean, cov, shape=None, spam=None)

.. seealso::

   :meth:`some`, :meth:`other`, :meth:`funcs`
   \n\
   :meth:`otherfunc`
       relationship
"""
        self.assertEqual(expected, actual)

    def test_colon_in_return_type(self):
        docstring = """
Summary

Returns
-------
:py:class:`~my_mod.my_class`
    an instance of :py:class:`~my_mod.my_class`
"""

        expected = """
Summary

:returns: an instance of :py:class:`~my_mod.my_class`
:rtype: :py:class:`~my_mod.my_class`
"""

        config = Config()
        app = Mock()
        actual = str(NumpyDocstring(docstring, config, app, "method"))

        self.assertEqual(expected, actual)

    def test_underscore_in_attribute(self):
        docstring = """
Attributes
----------

arg_ : type
    some description
"""

        expected = """
:ivar arg_: some description
:vartype arg_: type
"""

        config = Config(napoleon_use_ivar=True)
        app = Mock()
        actual = str(NumpyDocstring(docstring, config, app, "class"))

        self.assertEqual(expected, actual)

    def test_raises_types(self):
        docstrings = [("""
Example Function

Raises
------
  RuntimeError

      A setting wasn't specified, or was invalid.
  ValueError

      Something something value error.

""", """
Example Function

:raises: * :exc:`RuntimeError` -- A setting wasn't specified, or was invalid.
         * :exc:`ValueError` -- Something something value error.
"""),
                      ################################
                      ("""
Example Function

Raises
------
InvalidDimensionsError

""", """
Example Function

:raises: :exc:`InvalidDimensionsError`
"""),
                      ################################
                      ("""
Example Function

Raises
------
Invalid Dimensions Error

""", """
Example Function

:raises: Invalid Dimensions Error
"""),
                      ################################
                      ("""
Example Function

Raises
------
Invalid Dimensions Error
    With description

""", """
Example Function

:raises: *Invalid Dimensions Error* -- With description
"""),
                      ################################
                      ("""
Example Function

Raises
------
InvalidDimensionsError
    If the dimensions couldn't be parsed.

""", """
Example Function

:raises: :exc:`InvalidDimensionsError` -- If the dimensions couldn't be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises
------
Invalid Dimensions Error
    If the dimensions couldn't be parsed.

""", """
Example Function

:raises: *Invalid Dimensions Error* -- If the dimensions couldn't be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises
------
If the dimensions couldn't be parsed.

""", """
Example Function

:raises: If the dimensions couldn't be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises
------
:class:`exc.InvalidDimensionsError`

""", """
Example Function

:raises: :class:`exc.InvalidDimensionsError`
"""),
                      ################################
                      ("""
Example Function

Raises
------
:class:`exc.InvalidDimensionsError`
    If the dimensions couldn't be parsed.

""", """
Example Function

:raises: :class:`exc.InvalidDimensionsError` -- If the dimensions couldn't """
                          """be parsed.
"""),
                      ################################
                      ("""
Example Function

Raises
------
:class:`exc.InvalidDimensionsError`
    If the dimensions couldn't be parsed,
    then a :class:`exc.InvalidDimensionsError` will be raised.

""", """
Example Function

:raises: :class:`exc.InvalidDimensionsError` -- If the dimensions couldn't """
                          """be parsed,
         then a :class:`exc.InvalidDimensionsError` will be raised.
"""),
                      ################################
                      ("""
Example Function

Raises
------
:class:`exc.InvalidDimensionsError`
    If the dimensions couldn't be parsed.
:class:`exc.InvalidArgumentsError`
    If the arguments are invalid.

""", """
Example Function

:raises: * :class:`exc.InvalidDimensionsError` -- If the dimensions """
                          """couldn't be parsed.
         * :class:`exc.InvalidArgumentsError` -- If the arguments """
                          """are invalid.
"""),
                      ################################
                      ("""
Example Function

Raises
------
:class:`exc.InvalidDimensionsError`
:class:`exc.InvalidArgumentsError`

""", """
Example Function

:raises: * :class:`exc.InvalidDimensionsError`
         * :class:`exc.InvalidArgumentsError`
""")]
        for docstring, expected in docstrings:
            config = Config()
            app = Mock()
            actual = str(NumpyDocstring(docstring, config, app, "method"))
            self.assertEqual(expected, actual)

    def test_xrefs_in_return_type(self):
        docstring = """
Example Function

Returns
-------
:class:`numpy.ndarray`
    A :math:`n \\times 2` array containing
    a bunch of math items
"""
        expected = """
Example Function

:returns: A :math:`n \\times 2` array containing
          a bunch of math items
:rtype: :class:`numpy.ndarray`
"""
        config = Config()
        app = Mock()
        actual = str(NumpyDocstring(docstring, config, app, "method"))
        self.assertEqual(expected, actual)


text:
package s3manager

import (
	"bytes"
	"errors"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/awserr"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/request"
	"github.com/aws/aws-sdk-go/awstesting/unit"
	"github.com/aws/aws-sdk-go/service/s3"
	"github.com/aws/aws-sdk-go/service/s3/s3iface"
)

func TestHasParity(t *testing.T) {
	cases := []struct {
		o1       *s3.DeleteObjectsInput
		o2       BatchDeleteObject
		expected bool
	}{
		{
			&s3.DeleteObjectsInput{},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{},
			},
			true,
		},
		{
			&s3.DeleteObjectsInput{
				Bucket: aws.String("foo"),
			},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{
					Bucket: aws.String("bar"),
				},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{
					Bucket: aws.String("foo"),
				},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{
				Bucket: aws.String("foo"),
			},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{
				MFA: aws.String("foo"),
			},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{
					MFA: aws.String("bar"),
				},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{
					MFA: aws.String("foo"),
				},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{
				MFA: aws.String("foo"),
			},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{
				RequestPayer: aws.String("foo"),
			},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{
					RequestPayer: aws.String("bar"),
				},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{
					RequestPayer: aws.String("foo"),
				},
			},
			false,
		},
		{
			&s3.DeleteObjectsInput{
				RequestPayer: aws.String("foo"),
			},
			BatchDeleteObject{
				Object: &s3.DeleteObjectInput{},
			},
			false,
		},
	}

	for i, c := range cases {
		if result := hasParity(c.o1, c.o2); result != c.expected {
			t.Errorf("Case %d: expected %t, but received %t\n", i, c.expected, result)
		}
	}
}

func TestBatchDelete(t *testing.T) {
	cases := []struct {
		objects  []BatchDeleteObject
		size     int
		expected int
	}{
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("2"),
						Bucket: aws.String("bucket2"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("3"),
						Bucket: aws.String("bucket3"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("4"),
						Bucket: aws.String("bucket4"),
					},
				},
			},
			1,
			4,
		},
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("2"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("3"),
						Bucket: aws.String("bucket3"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("4"),
						Bucket: aws.String("bucket3"),
					},
				},
			},
			1,
			4,
		},
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("2"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("3"),
						Bucket: aws.String("bucket3"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("4"),
						Bucket: aws.String("bucket3"),
					},
				},
			},
			4,
			2,
		},
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("2"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("3"),
						Bucket: aws.String("bucket3"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("4"),
						Bucket: aws.String("bucket3"),
					},
				},
			},
			10,
			2,
		},
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("2"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("3"),
						Bucket: aws.String("bucket1"),
					},
				},
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("4"),
						Bucket: aws.String("bucket3"),
					},
				},
			},
			2,
			3,
		},
	}

	count := 0
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNoContent)
		count++
	}))

	svc := &mockS3Client{S3: buildS3SvcClient(server.URL)}
	for i, c := range cases {
		batcher := BatchDelete{
			Client:    svc,
			BatchSize: c.size,
		}

		if err := batcher.Delete(aws.BackgroundContext(), &DeleteObjectsIterator{Objects: c.objects}); err != nil {
			panic(err)
		}

		if count != c.expected {
			t.Errorf("Case %d: expected %d, but received %d", i, c.expected, count)
		}

		count = 0
	}
}

func TestBatchDeleteError(t *testing.T) {
	cases := []struct {
		objects            []BatchDeleteObject
		output             s3.DeleteObjectsOutput
		size               int
		expectedErrCode    string
		expectedErrMessage string
	}{
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
			},
			s3.DeleteObjectsOutput{
				Errors: []*s3.Error{
					{
						Code:    aws.String("foo code"),
						Message: aws.String("foo error"),
					},
				},
			},
			1,
			"foo code",
			"foo error",
		},
		{
			[]BatchDeleteObject{
				{
					Object: &s3.DeleteObjectInput{
						Key:    aws.String("1"),
						Bucket: aws.String("bucket1"),
					},
				},
			},
			s3.DeleteObjectsOutput{
				Errors: []*s3.Error{
					{},
				},
			},
			1,
			ErrDeleteBatchFailCode,
			errDefaultDeleteBatchMessage,
		},
	}

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNoContent)
	}))

	index := 0
	svc := &mockS3Client{
		S3: buildS3SvcClient(server.URL),
		deleteObjects: func(input *s3.DeleteObjectsInput) (*s3.DeleteObjectsOutput, error) {
			output := &cases[index].output
			index++
			return output, nil
		},
	}
	for _, c := range cases {
		batcher := BatchDelete{
			Client:    svc,
			BatchSize: c.size,
		}

		err := batcher.Delete(aws.BackgroundContext(), &DeleteObjectsIterator{Objects: c.objects})
		if err == nil {
			t.Errorf("expected error, but received none")
		}

		berr := err.(*BatchError)

		if len(berr.Errors) != 1 {
			t.Errorf("expected 1 error, but received %d", len(berr.Errors))
		}

		aerr := berr.Errors[0].OrigErr.(awserr.Error)
		if e, a := c.expectedErrCode, aerr.Code(); e != a {
			t.Errorf("expected %q, but received %q", e, a)
		}

		if e, a := c.expectedErrMessage, aerr.Message(); e != a {
			t.Errorf("expected %q, but received %q", e, a)
		}
	}
}

type mockS3Client struct {
	*s3.S3
	index         int
	objects       []*s3.ListObjectsOutput
	deleteObjects func(*s3.DeleteObjectsInput) (*s3.DeleteObjectsOutput, error)
}

func (client *mockS3Client) ListObjects(input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) {
	object := client.objects[client.index]
	client.index++
	return object, nil
}

func (client *mockS3Client) DeleteObjects(input *s3.DeleteObjectsInput) (*s3.DeleteObjectsOutput, error) {
	if client.deleteObjects == nil {
		return client.S3.DeleteObjectsWithContext(aws.BackgroundContext(), input)
	}

	return client.deleteObjects(input)
}

func (client *mockS3Client) DeleteObjectsWithContext(ctx aws.Context, input *s3.DeleteObjectsInput, opt ...request.Option) (*s3.DeleteObjectsOutput, error) {
	if client.deleteObjects == nil {
		return client.S3.DeleteObjectsWithContext(ctx, input)
	}

	return client.deleteObjects(input)
}

func TestNilOrigError(t *testing.T) {
	err := Error{
		Bucket: aws.String("bucket"),
		Key:    aws.String("key"),
	}
	errStr := err.Error()
	const expected1 = `failed to perform batch operation on "key" to "bucket"`
	if errStr != expected1 {
		t.Errorf("Expected %s, but received %s", expected1, errStr)
	}

	err = Error{
		OrigErr: errors.New("foo"),
		Bucket:  aws.String("bucket"),
		Key:     aws.String("key"),
	}
	errStr = err.Error()
	const expected2 = "failed to perform batch operation on \"key\" to \"bucket\":\nfoo"
	if errStr != expected2 {
		t.Errorf("Expected %s, but received %s", expected2, errStr)
	}

}

func TestBatchDeleteList(t *testing.T) {
	count := 0

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNoContent)
		count++
	}))

	objects := []*s3.ListObjectsOutput{
		{
			Contents: []*s3.Object{
				{
					Key: aws.String("1"),
				},
			},
			NextMarker:  aws.String("marker"),
			IsTruncated: aws.Bool(true),
		},
		{
			Contents: []*s3.Object{
				{
					Key: aws.String("2"),
				},
			},
			NextMarker:  aws.String("marker"),
			IsTruncated: aws.Bool(true),
		},
		{
			Contents: []*s3.Object{
				{
					Key: aws.String("3"),
				},
			},
			IsTruncated: aws.Bool(false),
		},
	}

	svc := &mockS3Client{S3: buildS3SvcClient(server.URL), objects: objects}
	batcher := BatchDelete{
		Client:    svc,
		BatchSize: 1,
	}

	input := &s3.ListObjectsInput{
		Bucket: aws.String("bucket"),
	}
	iter := &DeleteListIterator{
		Bucket: input.Bucket,
		Paginator: request.Pagination{
			NewRequest: func() (*request.Request, error) {
				var inCpy *s3.ListObjectsInput
				if input != nil {
					tmp := *input
					inCpy = &tmp
				}
				req, _ := svc.ListObjectsRequest(inCpy)
				req.Handlers.Clear()
				output, _ := svc.ListObjects(inCpy)
				req.Data = output
				return req, nil
			},
		},
	}

	if err := batcher.Delete(aws.BackgroundContext(), iter); err != nil {
		t.Error(err)
	}

	if count != len(objects) {
		t.Errorf("Expected %d, but received %d", len(objects), count)
	}
}

func buildS3SvcClient(u string) *s3.S3 {
	return s3.New(unit.Session, &aws.Config{
		Endpoint:         aws.String(u),
		S3ForcePathStyle: aws.Bool(true),
		DisableSSL:       aws.Bool(true),
		Credentials:      credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
	})

}

func TestBatchDeleteList_EmptyListObjects(t *testing.T) {
	count := 0

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNoContent)
		count++
	}))

	svc := &mockS3Client{S3: buildS3SvcClient(server.URL)}
	batcher := BatchDelete{
		Client: svc,
	}

	input := &s3.ListObjectsInput{
		Bucket: aws.String("bucket"),
	}

	// Test DeleteListIterator in the case when the ListObjectsRequest responds
	// with an empty listing.

	// We need a new iterator with a fresh Pagination since
	// Pagination.HasNextPage() is always true the first time Pagination.Next()
	// called on it
	iter := &DeleteListIterator{
		Bucket: input.Bucket,
		Paginator: request.Pagination{
			NewRequest: func() (*request.Request, error) {
				req, _ := svc.ListObjectsRequest(input)
				// Simulate empty listing
				req.Data = &s3.ListObjectsOutput{Contents: []*s3.Object{}}
				return req, nil
			},
		},
	}

	if err := batcher.Delete(aws.BackgroundContext(), iter); err != nil {
		t.Error(err)
	}
	if count != 1 {
		t.Errorf("expect count to be 1, got %d", count)
	}
}

func TestBatchDownload(t *testing.T) {
	count := 0
	expected := []struct {
		bucket, key string
	}{
		{
			key:    "1",
			bucket: "bucket1",
		},
		{
			key:    "2",
			bucket: "bucket2",
		},
		{
			key:    "3",
			bucket: "bucket3",
		},
		{
			key:    "4",
			bucket: "bucket4",
		},
	}

	received := []struct {
		bucket, key string
	}{}

	payload := []string{
		"1",
		"2",
		"3",
		"4",
	}

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		urlParts := strings.Split(r.URL.String(), "/")
		received = append(received, struct{ bucket, key string }{urlParts[1], urlParts[2]})
		w.Write([]byte(payload[count]))
		count++
	}))

	svc := NewDownloaderWithClient(buildS3SvcClient(server.URL))

	objects := []BatchDownloadObject{
		{
			Object: &s3.GetObjectInput{
				Key:    aws.String("1"),
				Bucket: aws.String("bucket1"),
			},
			Writer: aws.NewWriteAtBuffer(make([]byte, 128)),
		},
		{
			Object: &s3.GetObjectInput{
				Key:    aws.String("2"),
				Bucket: aws.String("bucket2"),
			},
			Writer: aws.NewWriteAtBuffer(make([]byte, 128)),
		},
		{
			Object: &s3.GetObjectInput{
				Key:    aws.String("3"),
				Bucket: aws.String("bucket3"),
			},
			Writer: aws.NewWriteAtBuffer(make([]byte, 128)),
		},
		{
			Object: &s3.GetObjectInput{
				Key:    aws.String("4"),
				Bucket: aws.String("bucket4"),
			},
			Writer: aws.NewWriteAtBuffer(make([]byte, 128)),
		},
	}

	iter := &DownloadObjectsIterator{Objects: objects}
	if err := svc.DownloadWithIterator(aws.BackgroundContext(), iter); err != nil {
		panic(err)
	}

	if count != len(objects) {
		t.Errorf("Expected %d, but received %d", len(objects), count)
	}

	if len(expected) != len(received) {
		t.Errorf("Expected %d, but received %d", len(expected), len(received))
	}

	for i := 0; i < len(expected); i++ {
		if expected[i].key != received[i].key {
			t.Errorf("Expected %q, but received %q", expected[i].key, received[i].key)
		}

		if expected[i].bucket != received[i].bucket {
			t.Errorf("Expected %q, but received %q", expected[i].bucket, received[i].bucket)
		}
	}

	for i, p := range payload {
		b := iter.Objects[i].Writer.(*aws.WriteAtBuffer).Bytes()
		b = bytes.Trim(b, "\x00")

		if string(b) != p {
			t.Errorf("Expected %q, but received %q", p, b)
		}
	}
}

func TestBatchUpload(t *testing.T) {
	count := 0
	expected := []struct {
		bucket, key string
		reqBody     string
	}{
		{
			key:     "1",
			bucket:  "bucket1",
			reqBody: "1",
		},
		{
			key:     "2",
			bucket:  "bucket2",
			reqBody: "2",
		},
		{
			key:     "3",
			bucket:  "bucket3",
			reqBody: "3",
		},
		{
			key:     "4",
			bucket:  "bucket4",
			reqBody: "4",
		},
	}

	received := []struct {
		bucket, key, reqBody string
	}{}

	payload := []string{
		"a",
		"b",
		"c",
		"d",
	}

	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		urlParts := strings.Split(r.URL.String(), "/")

		b, err := ioutil.ReadAll(r.Body)
		if err != nil {
			t.Error(err)
		}

		received = append(received, struct{ bucket, key, reqBody string }{urlParts[1], urlParts[2], string(b)})
		w.Write([]byte(payload[count]))

		count++
	}))

	svc := NewUploaderWithClient(buildS3SvcClient(server.URL))

	objects := []BatchUploadObject{
		{
			Object: &UploadInput{
				Key:    aws.String("1"),
				Bucket: aws.String("bucket1"),
				Body:   bytes.NewBuffer([]byte("1")),
			},
		},
		{
			Object: &UploadInput{
				Key:    aws.String("2"),
				Bucket: aws.String("bucket2"),
				Body:   bytes.NewBuffer([]byte("2")),
			},
		},
		{
			Object: &UploadInput{
				Key:    aws.String("3"),
				Bucket: aws.String("bucket3"),
				Body:   bytes.NewBuffer([]byte("3")),
			},
		},
		{
			Object: &UploadInput{
				Key:    aws.String("4"),
				Bucket: aws.String("bucket4"),
				Body:   bytes.NewBuffer([]byte("4")),
			},
		},
	}

	iter := &UploadObjectsIterator{Objects: objects}
	if err := svc.UploadWithIterator(aws.BackgroundContext(), iter); err != nil {
		panic(err)
	}

	if count != len(objects) {
		t.Errorf("Expected %d, but received %d", len(objects), count)
	}

	if len(expected) != len(received) {
		t.Errorf("Expected %d, but received %d", len(expected), len(received))
	}

	for i := 0; i < len(expected); i++ {
		if expected[i].key != received[i].key {
			t.Errorf("Expected %q, but received %q", expected[i].key, received[i].key)
		}

		if expected[i].bucket != received[i].bucket {
			t.Errorf("Expected %q, but received %q", expected[i].bucket, received[i].bucket)
		}

		if expected[i].reqBody != received[i].reqBody {
			t.Errorf("Expected %q, but received %q", expected[i].reqBody, received[i].reqBody)
		}
	}
}

type mockClient struct {
	s3iface.S3API
	Put       func() (*s3.PutObjectOutput, error)
	Get       func() (*s3.GetObjectOutput, error)
	List      func() (*s3.ListObjectsOutput, error)
	responses []response
}

type response struct {
	out interface{}
	err error
}

func (client *mockClient) PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error) {
	return client.Put()
}

func (client *mockClient) PutObjectRequest(input *s3.PutObjectInput) (*request.Request, *s3.PutObjectOutput) {
	req, _ := client.S3API.PutObjectRequest(input)
	req.Handlers.Clear()
	req.Data, req.Error = client.Put()
	return req, req.Data.(*s3.PutObjectOutput)
}

func (client *mockClient) ListObjects(input *s3.ListObjectsInput) (*s3.ListObjectsOutput, error) {
	return client.List()
}

func (client *mockClient) ListObjectsRequest(input *s3.ListObjectsInput) (*request.Request, *s3.ListObjectsOutput) {
	req, _ := client.S3API.ListObjectsRequest(input)
	req.Handlers.Clear()
	req.Data, req.Error = client.List()
	return req, req.Data.(*s3.ListObjectsOutput)
}

func TestBatchError(t *testing.T) {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	}))

	index := 0
	responses := []response{
		{
			&s3.PutObjectOutput{},
			errors.New("Foo"),
		},
		{
			&s3.PutObjectOutput{},
			nil,
		},
		{
			&s3.PutObjectOutput{},
			nil,
		},
		{
			&s3.PutObjectOutput{},
			errors.New("Bar"),
		},
	}

	svc := &mockClient{
		S3API: buildS3SvcClient(server.URL),
		Put: func() (*s3.PutObjectOutput, error) {
			resp := responses[index]
			index++
			return resp.out.(*s3.PutObjectOutput), resp.err
		},
		List: func() (*s3.ListObjectsOutput, error) {
			resp := responses[index]
			index++
			return resp.out.(*s3.ListObjectsOutput), resp.err
		},
	}
	uploader := NewUploaderWithClient(svc)

	objects := []BatchUploadObject{
		{
			Object: &UploadInput{
				Key:    aws.String("1"),
				Bucket: aws.String("bucket1"),
				Body:   bytes.NewBuffer([]byte("1")),
			},
		},
		{
			Object: &UploadInput{
				Key:    aws.String("2"),
				Bucket: aws.String("bucket2"),
				Body:   bytes.NewBuffer([]byte("2")),
			},
		},
		{
			Object: &UploadInput{
				Key:    aws.String("3"),
				Bucket: aws.String("bucket3"),
				Body:   bytes.NewBuffer([]byte("3")),
			},
		},
		{
			Object: &UploadInput{
				Key:    aws.String("4"),
				Bucket: aws.String("bucket4"),
				Body:   bytes.NewBuffer([]byte("4")),
			},
		},
	}

	iter := &UploadObjectsIterator{Objects: objects}
	if err := uploader.UploadWithIterator(aws.BackgroundContext(), iter); err != nil {
		if bErr, ok := err.(*BatchError); !ok {
			t.Error("Expected BatchError, but received other")
		} else {
			if len(bErr.Errors) != 2 {
				t.Errorf("Expected 2 errors, but received %d", len(bErr.Errors))
			}

			expected := []struct {
				bucket, key string
			}{
				{
					"bucket1",
					"1",
				},
				{
					"bucket4",
					"4",
				},
			}
			for i, expect := range expected {
				if *bErr.Errors[i].Bucket != expect.bucket {
					t.Errorf("Case %d: Invalid bucket expected %s, but received %s", i, expect.bucket, *bErr.Errors[i].Bucket)
				}

				if *bErr.Errors[i].Key != expect.key {
					t.Errorf("Case %d: Invalid key expected %s, but received %s", i, expect.key, *bErr.Errors[i].Key)
				}
			}
		}
	} else {
		t.Error("Expected error, but received nil")
	}

	if index != len(objects) {
		t.Errorf("Expected %d, but received %d", len(objects), index)
	}

}

type testAfterDeleteIter struct {
	afterDelete   bool
	afterDownload bool
	afterUpload   bool
	next          bool
}

func (iter *testAfterDeleteIter) Next() bool {
	next := !iter.next
	iter.next = !iter.next
	return next
}

func (iter *testAfterDeleteIter) Err() error {
	return nil
}

func (iter *testAfterDeleteIter) DeleteObject() BatchDeleteObject {
	return BatchDeleteObject{
		Object: &s3.DeleteObjectInput{
			Bucket: aws.String("foo"),
			Key:    aws.String("foo"),
		},
		After: func() error {
			iter.afterDelete = true
			return nil
		},
	}
}

type testAfterDownloadIter struct {
	afterDownload bool
	afterUpload   bool
	next          bool
}

func (iter *testAfterDownloadIter) Next() bool {
	next := !iter.next
	iter.next = !iter.next
	return next
}

func (iter *testAfterDownloadIter) Err() error {
	return nil
}

func (iter *testAfterDownloadIter) DownloadObject() BatchDownloadObject {
	return BatchDownloadObject{
		Object: &s3.GetObjectInput{
			Bucket: aws.String("foo"),
			Key:    aws.String("foo"),
		},
		Writer: aws.NewWriteAtBuffer([]byte{}),
		After: func() error {
			iter.afterDownload = true
			return nil
		},
	}
}

type testAfterUploadIter struct {
	afterUpload bool
	next        bool
}

func (iter *testAfterUploadIter) Next() bool {
	next := !iter.next
	iter.next = !iter.next
	return next
}

func (iter *testAfterUploadIter) Err() error {
	return nil
}

func (iter *testAfterUploadIter) UploadObject() BatchUploadObject {
	return BatchUploadObject{
		Object: &UploadInput{
			Bucket: aws.String("foo"),
			Key:    aws.String("foo"),
			Body:   strings.NewReader("bar"),
		},
		After: func() error {
			iter.afterUpload = true
			return nil
		},
	}
}

func TestAfter(t *testing.T) {
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	}))

	index := 0
	responses := []response{
		{
			&s3.PutObjectOutput{},
			nil,
		},
		{
			&s3.GetObjectOutput{},
			nil,
		},
		{
			&s3.DeleteObjectOutput{},
			nil,
		},
	}

	svc := &mockClient{
		S3API: buildS3SvcClient(server.URL),
		Put: func() (*s3.PutObjectOutput, error) {
			resp := responses[index]
			index++
			return resp.out.(*s3.PutObjectOutput), resp.err
		},
		Get: func() (*s3.GetObjectOutput, error) {
			resp := responses[index]
			index++
			return resp.out.(*s3.GetObjectOutput), resp.err
		},
		List: func() (*s3.ListObjectsOutput, error) {
			resp := responses[index]
			index++
			return resp.out.(*s3.ListObjectsOutput), resp.err
		},
	}
	uploader := NewUploaderWithClient(svc)
	downloader := NewDownloaderWithClient(svc)
	deleter := NewBatchDeleteWithClient(svc)

	deleteIter := &testAfterDeleteIter{}
	downloadIter := &testAfterDownloadIter{}
	uploadIter := &testAfterUploadIter{}

	if err := uploader.UploadWithIterator(aws.BackgroundContext(), uploadIter); err != nil {
		t.Error(err)
	}

	if err := downloader.DownloadWithIterator(aws.BackgroundContext(), downloadIter); err != nil {
		t.Error(err)
	}

	if err := deleter.Delete(aws.BackgroundContext(), deleteIter); err != nil {
		t.Error(err)
	}

	if !deleteIter.afterDelete {
		t.Error("Expected 'afterDelete' to be true, but received false")
	}

	if !downloadIter.afterDownload {
		t.Error("Expected 'afterDownload' to be true, but received false")
	}

	if !uploadIter.afterUpload {
		t.Error("Expected 'afterUpload' to be true, but received false")
	}
}

redpajama_set_name: RedPajamaGithub


text:
Node.js API for gifs.com's public-api for importing media.

### Accepted media types:
- gif  -> image/gif.
- mp4  -> video/mp4.
- webm -> video/wemb.

### Routes:
- /import, takes in a source URL, sends it the API endpoint then imports it into gifs.com's API.
- /upload, takes a file/stream/binary-data in the form of a multipart-form, sends it to the API endpoint
then makes the equivalent files.

### Sample usage in code:

* Import any media, mp4, gif, webm

```javascript
const gifs = require('gifs-api');

const urls = ['https://giant.gfycat.com/ClutteredSevereCur.gif', 'https://fat.gfycat.com/JovialPerkyArmyant.webm', 'https://pbs.twimg.com/tweet_video/Ca0ztmfWIAAi-UX.mp4'];
urls.forEach(function(url) {
  gifs.import(url, function(status, response) {
    console.log('url', url, status, response);
  });
});

// Alternatively
urls.forEach(function(url) {
  gifs.import({source: url, attribution: {user: 'nbcsnl', site: 'twitter'}, title: '40th Anniversary SNL'}, function(status, response) {
    console.log('url', url, status, response);
  });
});
```

* To restrict importing, use:
- gifs.importMP4.
- gifs.importWEBM.
- gifs.importGIF.

* Upload any accepted media: mp4, gif, webm.

```javascript
const fs   = require('fs');
const gifs = require('gifs-api');
const glob = require('glob');

glob('**/*.mp4', function(err, mp4Matches) {
  if (err)
    throw err;

  mp4Matches.forEach(function(mp4Match) {
    fs.readFile(mp4Match, function(err, stream) {
      if (err)
	throw err;

      var form = {
	file: stream,
	title: mp4Match,
	attribution_url: 'https://mysite.com',
	attribution_user: 'yourself',
	attribution_name: 'mysite',
      };

      gifs.upload(form, function(status, response) {
	console.log('mp4Match', mp4Match, status, response);
      });
  });
});
```

###  For stricter uploading, use:
- gifs.uploadMP4.
- gifs.uploadWEBM.
- gifs.uploadGIF.


text:
#ifndef VIRG_NEXUS_NX_TYPES_H
#define VIRG_NEXUS_NX_TYPES_H

#include "virg/nexus/nx_config.h"

#ifdef VIRG_NEXUS_PC_WIN32
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#else
#  include <inttypes.h>
#endif

__NX_BEGIN_DECL

typedef unsigned char uchar;

typedef int NXBool;

#define NX_FALSE 0
#define NX_TRUE  1

typedef int NXResult;

#define NX_OK 0
#define NX_FAIL -1

__NX_END_DECL

#endif


text:
begin;
insert into sys.version(number,comment) values(29,'CDR timing fixes');

ALTER TYPE switch.time_data_ty RENAME ATTRIBUTE leg_b_time_start TO leg_b_time;

CREATE OR REPLACE FUNCTION switch.writecdr(
  i_is_master boolean,
  i_node_id integer,
  i_pop_id integer,
  i_routing_attempt integer,
  i_is_last_cdr boolean,
  i_lega_local_ip character varying,
  i_lega_local_port integer,
  i_lega_remote_ip character varying,
  i_lega_remote_port integer,
  i_legb_local_ip character varying,
  i_legb_local_port integer,
  i_legb_remote_ip character varying,
  i_legb_remote_port integer,
  i_time_data json,
  i_early_media_present boolean,
  i_legb_disconnect_code integer,
  i_legb_disconnect_reason character varying,
  i_disconnect_initiator integer,
  i_internal_disconnect_code integer,
  i_internal_disconnect_reason character varying,
  i_lega_disconnect_code integer,
  i_lega_disconnect_reason character varying,
  i_orig_call_id character varying,
  i_term_call_id character varying,
  i_local_tag character varying,
  i_msg_logger_path character varying,
  i_dump_level_id integer,
  i_rtp_stats_data json,
  i_global_tag character varying,
  i_customer_id character varying,
  i_vendor_id character varying,
  i_customer_acc_id character varying,
  i_vendor_acc_id character varying,
  i_customer_auth_id character varying,
  i_destination_id character varying,
  i_destination_prefix character varying,
  i_dialpeer_id character varying,
  i_dialpeer_prefix character varying,
  i_orig_gw_id character varying,
  i_term_gw_id character varying,
  i_routing_group_id character varying,
  i_rateplan_id character varying,
  i_destination_initial_rate character varying,
  i_destination_next_rate character varying,
  i_destination_initial_interval integer,
  i_destination_next_interval integer,
  i_destination_rate_policy_id integer,
  i_dialpeer_initial_interval integer,
  i_dialpeer_next_interval integer,
  i_dialpeer_next_rate character varying,
  i_destination_fee character varying,
  i_dialpeer_initial_rate character varying,
  i_dialpeer_fee character varying,
  i_dst_prefix_in character varying,
  i_dst_prefix_out character varying,
  i_src_prefix_in character varying,
  i_src_prefix_out character varying,
  i_src_name_in character varying,
  i_src_name_out character varying,
  i_diversion_in character varying,
  i_diversion_out character varying,
  i_auth_orig_ip inet,
  i_auth_orig_port integer,
  i_dst_country_id integer,
  i_dst_network_id integer,
  i_dst_prefix_routing character varying,
  i_src_prefix_routing character varying,
  i_routing_plan_id integer,
  i_lrn character varying,
  i_lnp_database_id smallint)
  RETURNS integer AS
  $BODY$
DECLARE
    v_cdr cdr.cdr%rowtype;
    v_billing_event billing.cdr_v2;

    v_rtp_stats_data switch.rtp_stats_data_ty;
    v_time_data switch.time_data_ty;

v_nozerolen boolean;
BEGIN
    v_time_data:=json_populate_record(null::switch.time_data_ty, i_time_data);

v_cdr.pop_id=i_pop_id;
v_cdr.node_id=i_node_id;

v_cdr.src_name_in:=i_src_name_in;
v_cdr.src_name_out:=i_src_name_out;

v_cdr.diversion_in:=i_diversion_in;
v_cdr.diversion_out:=i_diversion_out;

v_cdr.customer_id:=i_customer_id;
v_cdr.vendor_id:=i_vendor_id;
v_cdr.customer_acc_id:=i_customer_acc_id;
v_cdr.vendor_acc_id:=i_vendor_acc_id;
v_cdr.customer_auth_id:=i_customer_auth_id;

v_cdr.destination_id:=i_destination_id;
v_cdr.destination_prefix:=i_destination_prefix;
v_cdr.dialpeer_id:=i_dialpeer_id;
v_cdr.dialpeer_prefix:=i_dialpeer_prefix;

v_cdr.orig_gw_id:=i_orig_gw_id;
v_cdr.term_gw_id:=i_term_gw_id;
v_cdr.routing_group_id:=i_routing_group_id;
v_cdr.rateplan_id:=i_rateplan_id;

v_cdr.routing_attempt=i_routing_attempt;
v_cdr.is_last_cdr=i_is_last_cdr;

v_cdr.destination_initial_rate:=i_destination_initial_rate::numeric;
v_cdr.destination_next_rate:=i_destination_next_rate::numeric;
v_cdr.destination_initial_interval:=i_destination_initial_interval;
v_cdr.destination_next_interval:=i_destination_next_interval;
v_cdr.destination_fee:=i_destination_fee;
v_cdr.destination_rate_policy_id:=i_destination_rate_policy_id;

v_cdr.dialpeer_initial_rate:=i_dialpeer_initial_rate::numeric;
v_cdr.dialpeer_next_rate:=i_dialpeer_next_rate::numeric;
v_cdr.dialpeer_initial_interval:=i_dialpeer_initial_interval;
v_cdr.dialpeer_next_interval:=i_dialpeer_next_interval;
v_cdr.dialpeer_fee:=i_dialpeer_fee;

/* sockets addresses */
v_cdr.sign_orig_ip:=i_legA_remote_ip;
v_cdr.sign_orig_port=i_legA_remote_port;
v_cdr.sign_orig_local_ip:=i_legA_local_ip;
v_cdr.sign_orig_local_port=i_legA_local_port;
v_cdr.sign_term_ip:=i_legB_remote_ip;
v_cdr.sign_term_port:=NULLIF(i_legB_remote_port,0);
v_cdr.sign_term_local_ip:=i_legB_local_ip;
v_cdr.sign_term_local_port:=NULLIF(i_legB_local_port,0);

v_cdr.local_tag=i_local_tag;

/* Call time data */
v_cdr.time_start:=to_timestamp(v_time_data.time_start);
v_cdr.time_limit:=v_time_data.time_limit;

if v_time_data.time_connect is not null then
    v_cdr.time_connect:=to_timestamp(v_time_data.time_connect);
    v_cdr.duration:=switch.round(v_time_data.time_end-v_time_data.time_connect); -- rounding
    v_nozerolen:=true;
    v_cdr.success=true;
else
    v_cdr.time_connect:=NULL;
    v_cdr.duration:=0;
    v_nozerolen:=false;
    v_cdr.success=false;
end if;
v_cdr.routing_delay=(v_time_data.leg_b_time-v_time_data.time_start)::real;
v_cdr.pdd=(coalesce(v_time_data.time_18x,v_time_data.time_connect)-v_time_data.time_start)::real;
v_cdr.rtt=(coalesce(v_time_data.time_1xx,v_time_data.time_18x,v_time_data.time_connect)-v_time_data.leg_b_time)::real;
v_cdr.early_media_present=i_early_media_present;

v_cdr.time_end:=to_timestamp(v_time_data.time_end);

-- DC processing
v_cdr.legb_disconnect_code:=i_legb_disconnect_code;
v_cdr.legb_disconnect_reason:=i_legb_disconnect_reason;
v_cdr.disconnect_initiator_id:=i_disconnect_initiator;
v_cdr.internal_disconnect_code:=i_internal_disconnect_code;
v_cdr.internal_disconnect_reason:=i_internal_disconnect_reason;
v_cdr.lega_disconnect_code:=i_lega_disconnect_code;
v_cdr.lega_disconnect_reason:=i_lega_disconnect_reason;

v_cdr.src_prefix_in:=i_src_prefix_in;
v_cdr.src_prefix_out:=i_src_prefix_out;
v_cdr.dst_prefix_in:=i_dst_prefix_in;
v_cdr.dst_prefix_out:=i_dst_prefix_out;

v_cdr.orig_call_id=i_orig_call_id;
v_cdr.term_call_id=i_term_call_id;

/* removed */
--v_cdr.dump_file:=i_msg_logger_path;

v_cdr.dump_level_id:=i_dump_level_id;

v_cdr.auth_orig_ip:=i_auth_orig_ip;
v_cdr.auth_orig_port:=i_auth_orig_port;

v_rtp_stats_data:=json_populate_record(null::switch.rtp_stats_data_ty, i_rtp_stats_data);

v_cdr.lega_rx_payloads:=v_rtp_stats_data.lega_rx_payloads;
v_cdr.lega_tx_payloads:=v_rtp_stats_data.lega_tx_payloads;
v_cdr.legb_rx_payloads:=v_rtp_stats_data.legb_rx_payloads;
v_cdr.legb_tx_payloads:=v_rtp_stats_data.legb_tx_payloads;

v_cdr.lega_rx_bytes:=v_rtp_stats_data.lega_rx_bytes;
v_cdr.lega_tx_bytes:=v_rtp_stats_data.lega_tx_bytes;
v_cdr.legb_rx_bytes:=v_rtp_stats_data.legb_rx_bytes;
v_cdr.legb_tx_bytes:=v_rtp_stats_data.legb_tx_bytes;

v_cdr.lega_rx_decode_errs:=v_rtp_stats_data.lega_rx_decode_errs;
v_cdr.lega_rx_no_buf_errs:=v_rtp_stats_data.lega_rx_no_buf_errs;
v_cdr.lega_rx_parse_errs:=v_rtp_stats_data.lega_rx_parse_errs;
v_cdr.legb_rx_decode_errs:=v_rtp_stats_data.legb_rx_decode_errs;
v_cdr.legb_rx_no_buf_errs:=v_rtp_stats_data.legb_rx_no_buf_errs;
v_cdr.legb_rx_parse_errs:=v_rtp_stats_data.legb_rx_parse_errs;

v_cdr.global_tag=i_global_tag;

v_cdr.dst_country_id=i_dst_country_id;
v_cdr.dst_network_id=i_dst_network_id;
v_cdr.dst_prefix_routing=i_dst_prefix_routing;
v_cdr.src_prefix_routing=i_src_prefix_routing;
v_cdr.routing_plan_id=i_routing_plan_id;
v_cdr.lrn=i_lrn;
v_cdr.lnp_database_id=i_lnp_database_id;

    v_cdr.id:=nextval('cdr.cdr_id_seq'::regclass);
    v_cdr:=billing.bill_cdr(v_cdr);

    perform stats.update_rt_stats(v_cdr);

    v_billing_event.id=v_cdr.id;
    v_billing_event.customer_id=v_cdr.customer_id;
    v_billing_event.vendor_id=v_cdr.vendor_id;
    v_billing_event.customer_acc_id=v_cdr.customer_acc_id;
    v_billing_event.vendor_acc_id=v_cdr.vendor_acc_id;
    v_billing_event.customer_auth_id=v_cdr.customer_auth_id;
    v_billing_event.destination_id=v_cdr.destination_id;
    v_billing_event.dialpeer_id=v_cdr.dialpeer_id;
    v_billing_event.orig_gw_id=v_cdr.orig_gw_id;
    v_billing_event.term_gw_id=v_cdr.term_gw_id;
    v_billing_event.routing_group_id=v_cdr.routing_group_id;
    v_billing_event.rateplan_id=v_cdr.rateplan_id;
    v_billing_event.destination_next_rate=v_cdr.destination_next_rate;
    v_billing_event.destination_fee=v_cdr.destination_fee;
    v_billing_event.dialpeer_next_rate=v_cdr.dialpeer_next_rate;
    v_billing_event.dialpeer_fee=v_cdr.dialpeer_fee;
    v_billing_event.internal_disconnect_code=v_cdr.internal_disconnect_code;
    v_billing_event.internal_disconnect_reason=v_cdr.internal_disconnect_reason;
    v_billing_event.disconnect_initiator_id=v_cdr.disconnect_initiator_id;
    v_billing_event.customer_price=v_cdr.customer_price;
    v_billing_event.vendor_price=v_cdr.vendor_price;
    v_billing_event.duration=v_cdr.duration;
    v_billing_event.success=v_cdr.success;
    v_billing_event.profit=v_cdr.profit;
    v_billing_event.time_start=v_cdr.time_start;
    v_billing_event.time_connect=v_cdr.time_connect;
    v_billing_event.time_end=v_cdr.time_end;
    v_billing_event.lega_disconnect_code=v_cdr.lega_disconnect_code;
    v_billing_event.lega_disconnect_reason=v_cdr.lega_disconnect_reason;
    v_billing_event.legb_disconnect_code=v_cdr.legb_disconnect_code;
    v_billing_event.legb_disconnect_reason=v_cdr.legb_disconnect_reason;

        -- generate event to routing engine
    perform event.billing_insert_event('cdr_full',v_billing_event);
    INSERT INTO cdr.cdr VALUES( v_cdr.*);
    RETURN 0;
END;
$BODY$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 10;

ALTER TABLE cdr.cdr DROP COLUMN dump_file ;
ALTER TABLE cdr.cdr_archive DROP COLUMN dump_file ;

commit;


text:
layout: "openstack"
page_title: "OpenStack: openstack_compute_secgroup_v2"
sidebar_current: "docs-openstack-resource-compute-secgroup-v2"
description: |-
  Manages a V2 security group resource within OpenStack.
---

# openstack\_compute\_secgroup_v2

Manages a V2 security group resource within OpenStack.

## Example Usage

```
resource "openstack_compute_secgroup_v2" "secgroup_1" {
  name = "my_secgroup"
  description = "my security group"
  rule {
    from_port = 22
    to_port = 22
    ip_protocol = "tcp"
    cidr = "0.0.0.0/0"
  }
  rule {
    from_port = 80
    to_port = 80
    ip_protocol = "tcp"
    cidr = "0.0.0.0/0"
  }
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Required) The region in which to obtain the V2 Compute client.
    A Compute client is needed to create a security group. If omitted, the
    `OS_REGION_NAME` environment variable is used. Changing this creates a new
    security group.

* `name` - (Required) A unique name for the security group. Changing this
    updates the `name` of an existing security group.

* `description` - (Required) A description for the security group. Changing this
    updates the `description` of an existing security group.

* `rule` - (Optional) A rule describing how the security group operates. The
    rule object structure is documented below. Changing this updates the
    security group rules. As shown in the example above, multiple rule blocks
    may be used.

The `rule` block supports:

* `from_port` - (Required) An integer representing the lower bound of the port
range to open. Changing this creates a new security group rule.

* `to_port` - (Required) An integer representing the upper bound of the port
range to open. Changing this creates a new security group rule.

* `ip_protocol` - (Required) The protocol type that will be allowed. Changing
this creates a new security group rule.

* `cidr` - (Optional) Required if `from_group_id` or `self` is empty. The IP range
that will be the source of network traffic to the security group. Use 0.0.0.0/0
to allow all IP addresses. Changing this creates a new security group rule. Cannot
be combined with `from_group_id` or `self`.

* `from_group_id` - (Optional) Required if `cidr` or `self` is empty. The ID of a
group from which to forward traffic to the parent group. Changing this creates a
new security group rule. Cannot be combined with `cidr` or `self`.

* `self` - (Optional) Required if `cidr` and `from_group_id` is empty. If true,
the security group itself will be added as a source to this ingress rule. Cannot
be combined with `cidr` or `from_group_id`.

## Attributes Reference

The following attributes are exported:

* `region` - See Argument Reference above.
* `name` - See Argument Reference above.
* `description` - See Argument Reference above.
* `rule` - See Argument Reference above.

## Notes

### ICMP Rules

When using ICMP as the `ip_protocol`, the `from_port` sets the ICMP _type_ and the `to_port` sets the ICMP _code_. To allow all ICMP types, set each value to `-1`, like so:

```
rule {
  from_port = -1
  to_port = -1
  ip_protocol = "icmp"
  cidr = "0.0.0.0/0"
}
```

A list of ICMP types and codes can be found [here](https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol#Control_messages).

### Referencing Security Groups

When referencing a security group in a configuration (for example, a configuration creates a new security group and then needs to apply it to an instance being created in the same configuration), it is currently recommended to reference the security group by name and not by ID, like this:

```
resource "openstack_compute_instance_v2" "test-server" {
  name = "tf-test"
  image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743"
  flavor_id = "3"
  key_pair = "my_key_pair_name"
  security_groups = ["${openstack_compute_secgroup_v2.secgroup_1.name}"]
}
```


text:
require "spec_helper"

describe Billymad::Setting do
  include_examples "can be initialized"

  include_examples "has .all method"
  include_examples "has .update methods"

  it "has correct .resource_name" do
    expect(described_class.send(:resource_name)).to eq('setting')
  end

  it "has correct .plural_resource_name" do
    expect(described_class.send(:plural_resource_name)).to eq('settings')
  end
end


text:
<title>UMEPS Merging</title>
<link rel="stylesheet" type="text/css" href="pythia.css"/>
<link rel="shortcut icon" href="pythia32.gif"/>

Unitarised Matrix Element + Parton Shower Merging

Pythia offers the possibility to use the unitarised matrix element + parton
shower merging scheme, as presented in [Lon12]. Unitarised ME+PS
merging (UMEPS) allows for a consistent inclusion of tree-level multi-parton
matrix elements into Pythia, and prevents potential changes in the inclusive
production cross section. This makes it theoretically more appealing than
CKKW-L merging. As in CKKW-L, UMEPS merging requires the user to supply Les
Houches Event File input.

UMEPS is different from other tree-level merging schemes in that it contains
events with negative weights. These are generated by constructing
parts of no-emission probabilities by reweighted higher-multiplicity
samples [Lon12]. The main philosophy of UMEPS is "subtract what you
add", meaning that in order to ensure the stability of the inclusive cross
section, one has to counter the inclusion of additional tree-level matrix
elements by "subtraction terms".

 The scheme closely reflects how unitarity
is achieved in a non-merged shower, and indeed explicitly enforces the
cancellations that are implicitly happening in a non-merged shower. This makes
very low merging scale values possible.

The usage of UMEPS is illustrated in the sample main program
main86.cc, together with the input file
main86.cmnd.

Unitarised merging is heavily indebted to CKKW-L merging, and shares many
settings with CKKW-L. In particular,

          The hard process
(Merging:Process)needs to be defined
exactly as in CKKW-L (see Defining the hard process in the
CKKW-L documentation).

          The merging scale value
(Merging:TMS) has to be set.

          The maximal number of additional partons
Merging:nJetMax has to be set.

UMEPS further shares the switches listed under the sections "Matrix
element merging and HepMC output for RIVET" and "Further
variables" in  the CKKW-L
documentation with CKKW-L merging. Also, all
MergingHooks routines that allow for user interference in
CKKW-L merging are also usable for UMEPS -- with the exception of a
user-defined merging scale.
Currently, UMEPS is only implemented for a merging scale defined
by the minimal Pythia evolution pT value between sets of radiator, emitted
and recoiler partons. This is no fundamental limitation of the method, and
will possibly be lifted in the future. Since this merging scale definition is
not completely obvious, UMEPS also shares the
Merging:enforceCutOnLHE switch with CKKW-L. In this way, it
is possible to use LHE files that are regularised only with weak cuts as
input, while the merging machinery imposes the stronger merging scale cut
automatically. This means that no merging scale implementation is required
from the user side, but also means that it is the user's responsibility to
ensure that the cuts used for generating input LHE files are always looser
than the cut given by the merging scale value Merging:TMS.

UMEPS merging with main86.cc

The UMEPS procedure is illustrated in the sample main program
main86.cc (with the input card main86.cmnd). This
program produces HepMC events [Dob01], that can be histogrammed (e.g.
using RIVET [Buc10]), or used as input for a detector simulation. If
the user is not familiar with HepMC analysis tools, it is possible to instead
use Pythia's histogramming routines. For this, remove the lines referring to
HepMC, and histogram events as illustrated (for CKKW-L) for the histogram
histPTFirstSum in main84.cc, i.e. using
weight*normhepmc as weight.

In principle, no changes to main86.cc are necessary. Instead, all
settings can be transferred to main86.cc through an input file.
The input LHE files are also part of the (command line) input of
main86.cc. Note  that the sample program assumes that LHE file
names are of the form name_tree_#nAdditionalJets.lhe. If you want to
e.g. use the LHE files that are shipped with the Pythia distribution, you can
execute main86.exe with the command

./main86.exe ./main86.cmnd ./w_production ./myhepmc.hepmc

Since main86.cc is currently the "front-end" for UMEPS merging,
we will briefly discuss this sample program in the following.

Inputs

In its current form, main86.cc uses separate tree-level LHE files
for different numbers of additional partons as input. If e.g. UMEPS merging
for W-boson + up to two additional partons is to be performed, three LHE files
(for W+zero, W+one, W+two partons) are required. The configurations in the
input files should be regularised with inclusive (i.e. weak) cuts. The actual
"merging scale cut" will be handled internally. If e.g.
Merging:TMS = 15 is the desired merging scale value,
it is acceptable
to regularise the matrix element calculation for Higgs+jets events at the LHC
with the loose cuts pTjet = 5 GeV,
 ΔRjetA jetB = 0.01 and
 QjetA jetB = 5 GeV.

All input settings are handed to main86.cc in the form of an
input file. This input file has to contain

          The number of desired events
(Main:numberOfEvents)

          The hard process
(Merging:Process)

          The merging scale value
(Merging:TMS)

          The maximal number of additional partons
(Merging:nJetMax).

Other settings are of course allowed. However, please refrain from adding
switches that are used to invoke other merging schemes (e.g.
Merging:doKTMerging) into the input file, since this can
cause problems.

Program flow

The sample program starts by estimating the cross section for samples with
different jet multiplicities. For this, the switch
Merging:doXSectionEstimate is invoked together with the merging
scale definition of Merging:doUMEPSTree, which corresponds to the
minimal Pythia evolution pT value. We will come back to the latter switch
below. All showering, multiparton interactions and hadronisation is, for speed
reasons, switched off when estimating the cross section, since the hard cross
section estimate would not be influenced by the event evolution anyway.

After the hard cross sections are known (including the application of the
merging scale cut), the first part of the UMEPS events is generated by
using the following switch.

flag   Merging:doUMEPSTree
 (default = off)

Reweight events according to the UMEPS prescription for tree-level
configurations.

The weight generated by the UMEPS procedure can be accessed by using the
function  double Info::mergingWeight().
When printing (or histogramming) merged events, this weight, multiplied
with the estimated cross section for the current sample, should be
used as event weight (or to fill histogram bins).

After this first part is complete, the outcome is an addition of reweighted
tree-level samples. To restore the inclusive cross section (i.e. that the
cross section after merging corresponds to the cross section of the hard
process, without any additional jets), it is necessary to subtract samples.
Parton shower unitarity leads to the conclusion that "resolved" and
"unresolved" corrections always cancel between states that contain an
additional resolved jet, and states in which we "integrate over" the phase
space of the additional jet.
main86.cc makes this cancellation explicit by producing
(correctly weighted) counter events by switching on

flag   Merging:doUMEPSSubt
 (default = off)

Reweight events according to the UMEPS prescription of reweighted,
integrated configurations. Please note that, in order for this to work
smoothly, the switch Merging:doUMEPSTree has to be turned off.

 The integration is achieved internally, and the number of desired
integrations (which is always one for UMEPS counter events) is set by

mode   Merging:nRecluster
 (default = 0; minimum = 0)

Number of hard partons to integrate out in the UMEPS procedure.

 Again, the weight generated by the UMEPS procedure can be accessed by
using the function  double Info::mergingWeight(). This
weight, multiplied with the cross section of the current sample, and
multiplied by -1, should then be used as event weight (or to fill
histogram bins).

Before returning, main86.cc prints the merged cross section
after UMEPS merging.


text:
/** augmentor_clicks_runner.cc                                 -*- C++ -*-
    Alexander Poznyak, 09 Oct 2016

    Runner for augmentor.

*/

#include "augmentor_clicks.h"
#include "soa/service/service_utils.h"

#include <boost/program_options/cmdline.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/positional_options.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>

#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

/******************************************************************************/
/* MAIN                                                                       */
/******************************************************************************/

int main(int argc, char** argv)
{
    using namespace boost::program_options;

    Datacratic::ServiceProxyArguments args;

    options_description options = args.makeProgramOptions();
    options.add_options() ("help,h", "Print this message");

    variables_map vm;
    store(command_line_parser(argc, argv).options(options).run(), vm);
    notify(vm);

    if (vm.count("help")) {
        cerr << options << endl;
        return 1;
    }

    auto serviceProxies = args.makeServiceProxies();
    RTBKIT::ClicksCapAugmentor augmentor(serviceProxies, "frequency-clicks-cap");
    augmentor.init();
    augmentor.start();

    while (true) this_thread::sleep_for(chrono::seconds(10));

    // Won't ever reach this point but this is how you shutdown an augmentor.
    augmentor.shutdown();

    return 0;
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.aerenserve</groupId>
  <artifactId>starport</artifactId>
  <name>StarPort</name>
  <version>1.0</version>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>net.aerenserve.starport.Main</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>org.math</include>
                </includes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <id>maven-central</id>
      <url>http://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>
  <dependencies>
    <dependency>
      <groupId>joda-time</groupId>
      <artifactId>joda-time</artifactId>
      <version>2.7</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>


text:
package ru.asemenov.models;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

public class User implements Serializable {
    private int id;
    private String name;
    private String login;
    private String address;
    private String roleId;
    private Set<MusicType> musicType;

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public Set<MusicType> getMusicType() {
        return musicType;
    }

    public void setMusicType(Set<MusicType> musicType) {
        this.musicType = musicType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (id != user.id) return false;
        if (name != null ? !name.equals(user.name) : user.name != null) return false;
        if (login != null ? !login.equals(user.login) : user.login != null) return false;
        if (address != null ? !address.equals(user.address) : user.address != null) return false;
        if (roleId != null ? !roleId.equals(user.roleId) : user.roleId != null) return false;
        return musicType != null ? musicType.equals(user.musicType) : user.musicType == null;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (login != null ? login.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (roleId != null ? roleId.hashCode() : 0);
        result = 31 * result + (musicType != null ? musicType.hashCode() : 0);
        return result;
    }
}


text:
package de.qaware.chronix.storage.solr.timeseries.metric;

import java.io.Serializable;
import java.sql.Timestamp;
import java.time.Instant;

/**
 * A metric observation datatype.
 *

 * Wrapper datatype to convert MetricTimeSeries to MetricObservationBeans
 * esp. useful to create Spark DataFrames.
 */
public class MetricObservation implements Serializable {

    private static final long serialVersionUID = 42L;

    private String metric;
    private String host;
    private String measurementSeries;
    private String process;
    private String ag;
    private String group;
    private long timestamp;
    private double value;

    /**
     * Empty constructor for reflection purposes / to be compliant with Java Bean specification.
     * Please use the value constructor per default.
     */
    public MetricObservation() {
    }

    /**
     * @param metric            the metric (dimension)
     * @param host              the host (dimension)
     * @param measurementSeries the measurement series (dimension)
     * @param process           the process (dimension)
     * @param group             the metric group (dimension)
     * @param ag                the aggregation level (dimension)
     * @param timestamp         the timestamp (primary dimension)
     * @param value             the value
     */
    public MetricObservation(String metric,
                             String host,
                             String measurementSeries,
                             String process,
                             String group,
                             String ag,
                             long timestamp,
                             double value) {
        this.metric = metric;
        this.host = host;
        this.measurementSeries = measurementSeries;
        this.process = process;
        this.group = group;
        this.ag = ag;
        this.timestamp = timestamp;
        this.value = value;
    }

    /**
     * @return the metric
     */
    public String getMetric() {
        return metric;
    }

    /**
     *
     * @param metric the metric
     */
    public void setMetric(String metric) {
        this.metric = metric;
    }

    /**
     *
     * @return the host
     */
    public String getHost() {
        return host;
    }

    /**
     *
     * @param host the host
     */
    public void setHost(String host) {
        this.host = host;
    }

    /**
     * Returns the measurement series name.
     *

     * Used "measurement" as property name to be symmetric with MetricTimeSeries attribute name
     *
     * @return measurement series name
     */
    public String getMeasurement() {
        return measurementSeries;
    }

    /**
     * Sets the measurement series name.
     *

     * Used "measurement" as property name to be symmetric with MetricTimeSeries attribute name
     */
    public void setMeasurement(String measurementSeries) {
        this.measurementSeries = measurementSeries;
    }

    /**
     *
     * @return the process
     */
    public String getProcess() {
        return process;
    }

    /**
     *
     * @param process the process
     */
    public void setProcess(String process) {
        this.process = process;
    }

    /**
     *
     * @return the aggregation level
     */
    public String getAg() {
        return ag;
    }

    /**
     *
     * @param ag the aggregation level
     */
    public void setAg(String ag) {
        this.ag = ag;
    }

    /**
     *
     * @return the timestamp
     */
    public long getTimestamp() {
        return timestamp;
    }

    /**
     *
     * @param timestamp the timestamp
     */
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    /**
     * Returns a Timestamp object which can be better
     * used in Spark SQL and/or Zeppelin.
     *
     * @return a Timestamp object
     */
    public Timestamp getTime() {
        return Timestamp.from(Instant.ofEpochMilli(timestamp));
    }

    /**
     * Sets the timestamp (milliseconds since 1.1.1970)
     *
     * @param ts the Timestamp object
     */
    public void setTime(Timestamp ts) {
        this.timestamp = ts.getTime();
    }

    /**
     *
     * @return the metric group
     */
    public String getGroup() {
        return group;
    }

    /**
     *
     * @param group the metric group
     */
    public void setGroup(String group) {
        this.group = group;
    }

    /**
     *
     * @return the value at the timestamp
     */
    public double getValue() {
        return value;
    }

    /**
     *
     * @param value the value at the timestamp
     */
    public void setValue(double value) {
        this.value = value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MetricObservation that = (MetricObservation) o;

        if (timestamp != that.timestamp) return false;
        if (Double.compare(that.value, value) != 0) return false;
        if (!metric.equals(that.metric)) return false;
        if (host != null ? !host.equals(that.host) : that.host != null) return false;
        if (measurementSeries != null ? !measurementSeries.equals(that.measurementSeries) : that.measurementSeries != null)
            return false;
        if (process != null ? !process.equals(that.process) : that.process != null) return false;
        if (ag != null ? !ag.equals(that.ag) : that.ag != null) return false;
        return group != null ? group.equals(that.group) : that.group == null;

    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = metric.hashCode();
        result = 31 * result + (host != null ? host.hashCode() : 0);
        result = 31 * result + (measurementSeries != null ? measurementSeries.hashCode() : 0);
        result = 31 * result + (process != null ? process.hashCode() : 0);
        result = 31 * result + (ag != null ? ag.hashCode() : 0);
        result = 31 * result + (group != null ? group.hashCode() : 0);
        result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
        temp = Double.doubleToLongBits(value);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }

    @Override
    public String toString() {
        return "MetricObservation{" +
                "metric='" + metric + '\'' +
                ", host='" + host + '\'' +
                ", measurement series='" + measurementSeries + '\'' +
                ", process='" + process + '\'' +
                ", ag='" + ag + '\'' +
                ", group='" + group + '\'' +
                ", timestamp=" + getTime().toString() +
                ", value=" + value +
                '}';
    }
}


text:
Products

{{productdetail.name}}

            <form action="" class="form-horizontal">

                        <input type="text" name="search_prod" class="form-control" placeholder="Search products...">

                            <input type="submit" value="Search" class="btn btn-xs" style="padding:7px 15px">

            </form>

{{productdetail.prodname}}

Category : {{productdetail.catname}}

Price : {{productdetail.curreny}} {{productdetail.price}}

            Description

Related Produts

{{productdetail.name}}

                            {{productdetail.curreny}} {{productdetail.price}}

{{productdetail.name}}

                            {{productdetail.curreny}} {{productdetail.price}}

{{productdetail.name}}

                            {{productdetail.curreny}} {{productdetail.price}}


text:
Smart Core CMS Sandbox
======================
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Smart-Core/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

The modern system for creating and managing web projects with open source, based on the Symfony2 Framework.

Получение последней версии песочницы:
```
    git pull;git submodule update --init
```

Обновление подмодулей из удалённых репозиториев:
```
    git submodule update --remote
```

Решение проблемы с detached head, переключение всех подмодулей в master:
```
    git submodule foreach 'git checkout master'
```

Пока не созданы тэги, для проектов использовать следующий набор пакетов в `composer.json`:
```
    "smart-core/module-breadcrumbs": "dev-master",
    "smart-core/module-gallery": "dev-master",
    "smart-core/module-menu": "dev-master",
    "smart-core/module-simplenews": "dev-master",
    "smart-core/module-slider": "dev-master",
    "smart-core/module-texter": "dev-master",
    "smart-core/module-unicat": "dev-master",
    "smart-core/module-user": "dev-master",
    "smart-core/module-webform": "dev-master",
    "smart-core/module-widget": "dev-master",

    "smart-core/cms-bundle": "dev-master",
    "smart-core/cms-generator-bundle": "dev-master",
    "smart-core/core-bundle": "dev-master",
    "smart-core/db-dumper-bundle": "dev-master",
    "smart-core/felib-bundle": "dev-master",
    "smart-core/html-bundle": "dev-master",
    "smart-core/media-bundle": "dev-master",
    "smart-core/rich-editor-bundle": "dev-master",
    "smart-core/seo-bundle": "dev-master",
    "smart-core/session-bundle": "dev-master",
    "smart-core/settings-bundle": "dev-master",
    "smart-core/simple-profiler-bundle": "dev-master",
    "smart-core/sitemap-bundle": "dev-master"
```

Удаление подмодуля (например `src/SmartCore/Bundle/SimpleProfilerBundle`):
```
    git submodule deinit -f src/SmartCore/Bundle/SimpleProfilerBundle
    git rm -f src/SmartCore/Bundle/SimpleProfilerBundle
    rm -rf .git/modules/src/SmartCore/Bundle/SimpleProfilerBundle
```


text:
ACTIVITY_WINDOW_WEEKS = 4;
TIME_RETRY_STATS_MS = 250;

loadActivity = function() {
	$.ajax({
		dataType: 'json',
		url: 'https://api.github.com/repos'+getProjectPath()+'/stats/commit_activity',
		statusCode: {
			200: function(data) {
				var activity = computeActivity(data);
				var activityLabel = getActivityLabel(activity);
				displayActivity(activityLabel, activity);
			},
			202: function() {
				// github processing the data
				setTimeout(loadActivity, TIME_RETRY_STATS_MS)
			},
			403: function() {
				console.warn('GitHub API limit reached!');
			},
			404: function() {
				console.log('Private repository, wont get activity.');
			}

		}
	});
}

displayActivity = function(label, number) {
	var hint = number + ' commits in the past ' + ACTIVITY_WINDOW_WEEKS + ' weeks';

	if(!$('.activity').size()) {
		var html = '
';
		html += '<svg aria-hidden="true" class="octicon octicon-pulse" height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M11.5 8L8.8 5.4 6.6 8.5 5.5 1.6 2.38 8H0V10h3.6L4.5 8.2l0.9 5.4L9 8.5l1.6 1.5H14V8H11.5z"></path></svg>';
		html += ' ' + label + ' activity
';

		$('.numbers-summary').append(html);

	} else {
		$('.activity .num').text(label);
		$('.activity a').attr('title', hint)
	}
}

computeActivity = function(data) {
	return _(data)
		.mapValues(function(week) {return week.total})
		.values()
		.slice(52 - ACTIVITY_WINDOW_WEEKS)
		.reduce(function(a, b) {return a + b}, 0);
}

getActivityLabel = function(total) {
	if(total === 0)		return 'no';
	if(total < 10) 		return 'low';
	if(total < 100) 	return 'medium';
	if(total < 1000) 	return 'high';
	return 'incredible';
}

getProjectPath = function() {
	return window.location.pathname;
}

displayActivity('-', 0);
loadActivity();

// Google Universal Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-36471625-5', 'auto');
ga('set', 'checkProtocolTask', function(){});
ga('require', 'displayfeatures');
ga('send', 'pageview', 'started');


text:
package com.google.cloud.ids.v1.samples;

// [START ids_v1_generated_IDS_GetEndpoint_Endpointname_sync]
import com.google.cloud.ids.v1.Endpoint;
import com.google.cloud.ids.v1.EndpointName;
import com.google.cloud.ids.v1.IDSClient;

public class SyncGetEndpointEndpointname {

  public static void main(String[] args) throws Exception {
    syncGetEndpointEndpointname();
  }

  public static void syncGetEndpointEndpointname() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (IDSClient iDSClient = IDSClient.create()) {
      EndpointName name = EndpointName.of("[PROJECT]", "[LOCATION]", "[ENDPOINT]");
      Endpoint response = iDSClient.getEndpoint(name);
    }
  }
}
// [END ids_v1_generated_IDS_GetEndpoint_Endpointname_sync]


text:
/*******************************
 * cocoa_press/move_e_screen.h *
 *******************************/

/****************************************************************************
 *   Written By Mark Pelletier  2017 - Aleph Objects, Inc.                  *
 *   Written By Marcio Teixeira 2018 - Aleph Objects, Inc.                  *
 *   Written By Marcio Teixeira 2019 - Cocoa Press                          *
 *                                                                          *
 *   This program is free software: you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation, either version 3 of the License, or      *
 *   (at your option) any later version.                                    *
 *                                                                          *
 *   This program is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *   GNU General Public License for more details.                           *
 *                                                                          *
 *   To view a copy of the GNU General Public License, go to the following  *
 *   location: <https://www.gnu.org/licenses/>.                              *
 ****************************************************************************/

#pragma once

#define COCOA_MOVE_E_SCREEN
#define COCOA_MOVE_E_SCREEN_CLASS MoveEScreen

class MoveEScreen : public BaseMoveAxisScreen, public CachedScreen<MOVE_E_SCREEN_CACHE> {
  public:
    static void onRedraw(draw_mode_t);
    static void onIdle();
};


text:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.sicoob</groupId>
    <artifactId>rest-cliente-ejb</artifactId>
    <version>1.0</version>
    <packaging>ejb</packaging>

    <name>rest-cliente-ejb</name>
    <!--
    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    -->
    <dependencies>
    <dependency>
  <groupId>com.owlike</groupId>
  <artifactId>genson</artifactId>
  <version>1.4</version>
  <scope>provided</scope>
</dependency>
        <dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-server</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-common</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-moxy</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-entity-filtering</artifactId>
    <version>2.25.1</version>
    <scope>provided</scope>
</dependency>
    <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>