text:
from django.utils import simplejson
from google.appengine.ext import db

class ObjectListProperty(db.ListProperty):
    """A property that stores a list of serializable class instances.
    Serialization / deserialization are done transparently when putting
    and getting.  This is a paramaterized property; the parameter must be a
    class with serializable members.

    ObjectListProperty optionally uses 'serialize' and 'deserialize' methods
    from the item class if they exist, otherwise a JSON representation of the
    item's internal dict is used.  These methods should be implemented if the
    class has attributes that are not builtin types.

    Note: can store serialized objects of strings up to 500 characters in
    length. For longer strings, change line with #! comment: 'str' ->
     'db.Text' and handle with encoding / decoding

    Example:

    class Record():
        def __init__(self, who, timestamp=None):
            self.who = who.key() if hasattr(who, 'key') else who # Some user model
            self.timestamp = timestamp if timestamp else time.time()

    class Usage_Tracker(db.Model):
        records = ObjectListProperty(Record, indexed=False)

    """
    def __init__(self, cls, *args, **kwargs):
        """Construct ObjectListProperty

        Args:
            cls: Class of objects in list
            *args: Optional additional arguments, passed to base class
            **kwds: Optional additional keyword arguments, passed to base class
        """
        self._cls = cls

        super(ObjectListProperty, self).__init__(str, *args, **kwargs) #!

    def __repr__(self):
        return '<%s.%s at %s\n%s> containing <%s.%s>' % (self.__class__.__module__,
                                        self.__class__.__name__,
                                        hex(id(self)),
                                        str('\n '.join('%s : %s' % (k, repr(v))
                                            for (k, v) in self.__dict.iteritems())),
                                        self._cls.__class__.__module__,
                                        self._cls.__class__.__name__)

    def validate_list_contents(self, value):
        """Validates that all items in the list are of the correct type.

        Returns:
            The validated list.

        Raises:
            BadValueError if the list has items are not instances of the
            cls given to the constructor.
        """
        for item in value:
            if not isinstance(item, self._cls):
                raise db.BadValueError('%s Items in %s must all be of type %r' % (debug_info(), self.name, self._cls) )
        return value

    def get_value_for_datastore(self, model_instance):
        """Serialize list to send to datastore.

        Returns:
            validated list appropriate to save in the datastore.
        """
        if hasattr(self._cls, 'serialize') and callable(getattr(self._cls, 'serialize')):
            def item_to_string(i):
                return i.serialize()
        else:
            def item_to_string(i):
                return simplejson.dumps(i.__dict__)

        obj_list = self.__get__(model_instance, model_instance.__class__)
        if obj_list is not None and type(obj_list) is list:
            db_list = []

            for obj in obj_list:

                if isinstance(obj, self._cls):
                    obj_str = item_to_string(obj)

                    if not len(obj_str) > 500:
                        db_list.append(obj_str)
                    else:
                        raise OverflowError('%s %s does not support object serialization \
                                             over 500 characters in length.  Substitute str representation \
                                             for db.Text in %s.%s' % (debug_info(),
                                                                      self.name,
                                                                      self.__class__.__module__,
                                                                      self.__class__.__name__))
            return db_list
        else:
            return []

    def make_value_from_datastore(self, db_list):
        """Deserialize datastore representation to list

        Returns:
            The value converted for use as a model instance attribute.
        """
        if hasattr(self._cls, 'deserialize') and callable(getattr(self._cls, 'deserialize')):
            def string_to_item(s):
                return self._cls.deserialize(s)
        else:
            def string_to_item(s):
                return self._cls(**(simplejson.loads(s)))

        if db_list is not None and type(db_list) is list:
            return [ string_to_item(value) for value in db_list ]
        else:
            return []


text:
using System.Collections.Generic;
using System.Web.Http.Description;
using Swashbuckle.Swagger;

namespace webapitmpl.Utility
{
    /// <summary>
    /// Swagger operation filter which adds parameters to all filtered APIs
    /// </summary>
    internal class AddedParametersSwaggerOperationFilter : IOperationFilter
    {
        private Parameter[] parameters;

        /// <summary>
        /// Initializes a new instance of the <see cref="AddedParametersSwaggerOperationFilter"/> class.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public AddedParametersSwaggerOperationFilter(params Parameter[] parameters)
        {
            this.parameters = parameters;
        }

        /// <summary>
        /// Applies the specified operation.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="schemaRegistry">The schema registry.</param>
        /// <param name="apiDescription">The API description.</param>
        public void Apply(
            Operation operation,
            SchemaRegistry schemaRegistry,
            ApiDescription apiDescription)
        {
            if (operation.parameters == null)
            {
                operation.parameters = new List<Parameter>(parameters);
            }
            else
            {
                foreach (Parameter p in parameters)
                {
                    operation.parameters.Add(p);
                }
            }
        }
    }
}

redpajama_set_name: RedPajamaGithub


text:
package com.google.common.testing;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * A {@code TearDownStack} contains a stack of {@link TearDown} instances.
 *
 * @author Kevin Bourrillion
 * @since 10.0
 */
@Beta
@GwtCompatible
public class TearDownStack implements TearDownAccepter {
  private static final Logger logger = Logger.getLogger(TearDownStack.class.getName());

  final LinkedList<TearDown> stack = new LinkedList<TearDown>();

  private final boolean suppressThrows;

  public TearDownStack() {
    this.suppressThrows = false;
  }

  public TearDownStack(boolean suppressThrows) {
    this.suppressThrows = suppressThrows;
  }

  @Override
  public final void addTearDown(TearDown tearDown) {
    stack.addFirst(checkNotNull(tearDown));
  }

  /**
   * Causes teardown to execute.
   */
  public final void runTearDown() {
    List<Throwable> exceptions = new ArrayList<Throwable>();
    for (TearDown tearDown : stack) {
      try {
        tearDown.tearDown();
      } catch (Throwable t) {
        if (suppressThrows) {
          logger.log(Level.INFO, "exception thrown during tearDown", t);
        } else {
          exceptions.add(t);
        }
      }
    }
    stack.clear();
    if ((!suppressThrows) && (exceptions.size() > 0)) {
      throw ClusterException.create(exceptions);
    }
  }
}