text:
/*
 * Legal Notice
 *
 * This document and associated source code (the "Work") is a preliminary
 * version of a benchmark specification being developed by the TPC. The
 * Work is being made available to the public for review and comment only.
 * The TPC reserves all right, title, and interest to the Work as provided
 * under U.S. and international laws, including without limitation all patent
 * and trademark rights therein.
 *
 * No Warranty
 *
 * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION
 *     CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE
 *     AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER
 *     WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
 *     INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES,
 *     DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
 *     PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF
 *     WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE.
 *     ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT,
 *     QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT
 *     WITH REGARD TO THE WORK.
 * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO
 *     ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE
 *     COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS
 *     OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT,
 *     INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY,
 *     OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT
 *     RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD
 *     ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * Contributors
 * - Sergey Vasilevskiy, Doug Johnson
 */

/******************************************************************************
*   Description:        Implementation of the MEESecurity class.
*                       See MEESecurity.h for a description.
******************************************************************************/

#include "../inc/MEESecurity.h"

using namespace TPCE;

//  Period of security price change (in seconds)
//  e.g. when the price will repeat.
//
const int iSecPricePeriod = 900;  // 15 minutes

// Mean delay between Submission and Completion times
//
const double fMeanCompletionTimeDelay = 1.0;

// Delay added to the clipped MEE Completion delay
// to simulate SUT-to-MEE and MEE-to-SUT processing delays.
//
const double fCompletionSUTDelay = 1.0; // seconds

/*
*  Constructor.
*  Initializes the class using RNG and constants.
*
*  PARAMETERS:
*           none.
*
*  RETURNS:
*           not applicable.
*/
CMEESecurity::CMEESecurity()
: m_rnd(RNGSeedBaseMEESecurity)
, m_fRangeLow(fMinSecPrice)
, m_fRangeHigh(fMaxSecPrice)
, m_fRange(fMaxSecPrice - fMinSecPrice)
, m_iPeriod(iSecPricePeriod)
, m_TradingTimeSoFar( 0 )
, m_pBaseTime( NULL )
, m_pCurrentTime( NULL )
{
}

/*
*  Initialize before the first use.
*  Separated from constructor in order to have default (no-parameters)
*  constructor.
*
*  PARAMETERS:
*           IN  Index                           - unique security index to generate a unique starting price
*           IN  TradeTimeSoFar                  - point where we last left off on the price curve
*           IN  pBaseTime                       - wall clock time corresponding to the initial time for all securities
*           IN  pCurrentTime                    - current time for the security (determines current price)
*           IN  fMeanInTheMoneySubmissionDelay  - Mean delay between Pending and Submission times for an immediatelly triggered (in-the-money) limit order.
*
*  RETURNS:
*           none
*/
void CMEESecurity::Init(
                        INT32       TradingTimeSoFar,   // for picking up where we last left off on the price curve
                        CDateTime   *pBaseTime,
                        CDateTime   *pCurrentTime,

                        // Mean delay between Pending and Submission times
                        // for an immediatelly triggered (in-the-money) limit
                        // order.
                        //
                        // The actual delay is randomly calculated in the range
                        // [0.5 * Mean .. 1.5 * Mean]
                        //
                        double fMeanInTheMoneySubmissionDelay
                        )
{
    m_TradingTimeSoFar = TradingTimeSoFar;
    m_pBaseTime = pBaseTime;
    m_pCurrentTime = pCurrentTime;

    m_fMeanInTheMoneySubmissionDelay = fMeanInTheMoneySubmissionDelay;

    //  Reset the RNG seed so that loading in multiple EGenLoader instances results in the
    //  same database as running just one EGenLoader.
    //
    m_rnd.SetSeed(RNGSeedBaseMEESecurity);
}

/*
*   Calculate the "unique" starting offset
*   in the price curve based on the security ID (0-based)
*   0 corresponds to m_fRangeLow price,
*   m_fPeriod/2 corresponds to m_fRangeHigh price,
*   m_fPeriod corresponds again to m_fRangeLow price
*
*   PARAMETERS:
*           IN  SecurityIndex  - unique security index to generate a unique starting price
*
*   RETURNS:
*           time from which to calculate initial price
*/
inline double CMEESecurity::InitialTime( TIdent SecurityIndex )
{
    return( (((m_TradingTimeSoFar * MsPerSecond) + (SecurityIndex * 556237 + 253791)) % (iSecPricePeriod * MsPerSecond)) / MsPerSecondDivisor );
}

/*
*  Negative exponential distribution.
*
*  PARAMETERS:
*           IN  fMean  - mean value of the distribution
*
*  RETURNS:
*           random value according to the negative
*           exponential distribution with the given mean.
*/
inline double CMEESecurity::NegExp(double fMean)
{
    double fResult = (-1.0 * log(m_rnd.RndDouble())) * fMean;

    return fResult;
}

/*
*  Calculate current price for the security identified by its index (0-based).
*
*  PARAMETERS:
*           IN  SecurityIndex  - unique identifier for the security.
*
*  RETURNS:
*           price at this point in time given with integer number of cents.
*/
CMoney CMEESecurity::GetCurrentPrice( TIdent SecurityIndex )
{
    return( CalculatePrice( SecurityIndex, *m_pCurrentTime - *m_pBaseTime ));
}

/*
*  Return minimum price on the price curve for any security.
*
*  PARAMETERS:
*           none.
*
*  RETURNS:
*           minimum price given with integer number of cents.
*/
CMoney CMEESecurity::GetMinPrice( void )
{
    return( m_fRangeLow );
}

/*
*  Return maximum price on the price curve for any security.
*
*  PARAMETERS:
*           none.
*
*  RETURNS:
*           maximum price given with integer number of cents.
*/
CMoney CMEESecurity::GetMaxPrice( void )
{
    return( m_fRangeHigh );
}

/*
*   Calculate price at a certain point in time.
*
*   PARAMETERS:
*           IN  SecurityIndex   - unique security index to generate a unique starting price
*           IN  fTime           - seconds from initial time
*
*   RETURNS:
*           price according to the triangular function
*           that will be achived at the given time
*/
CMoney  CMEESecurity::CalculatePrice(   TIdent SecurityIndex,
                                        double fTime
                                        )
{
    double  fPeriodTime = (fTime + InitialTime( SecurityIndex )) / (double)m_iPeriod;
    double  fTimeWithinPeriod = (fPeriodTime - (int)fPeriodTime) * (double)m_iPeriod;

    double  fPricePosition; // 0..1 corresponding to m_fRangeLow..m_fRangeHigh
    CMoney  PriceCents;

    if (fTimeWithinPeriod < m_iPeriod / 2)
    {
        fPricePosition = fTimeWithinPeriod / (m_iPeriod / 2);
    }
    else
    {
        fPricePosition = (m_iPeriod - fTimeWithinPeriod) / (m_iPeriod / 2);
    }

    PriceCents = m_fRangeLow + m_fRange * fPricePosition;

    return PriceCents;
}

/*
*   Calculate time required to move between certain prices
*   with certain initial direction of price change.
*
*   PARAMETERS:
*           IN  fStartPrice     - price at the start of the time interval
*           IN  fEndPrice       - price at the end of the time interval
*           IN  iStartDirection - direction (up or down) on the price curve at the start of the time interval
*
*   RETURNS:
*           seconds required to move from the start price to the end price
*/
double  CMEESecurity::CalculateTime(
                                        CMoney fStartPrice,
                                        CMoney fEndPrice,
                                        int iStartDirection)
{
    int     iHalfPeriod = m_iPeriod / 2;

    // Distance on the price curve from StartPrice to EndPrice (in dollars)
    //
    CMoney fDistance;

    // Amount of time (in seconds) needed to move $1 on the price curve.
    // In half a period the price moves over the entire price range.
    //
    double fSpeed = iHalfPeriod / m_fRange.DollarAmount();

    if (fEndPrice > fStartPrice)
    {
        if (iStartDirection > 0)
        {
            fDistance = fEndPrice - fStartPrice;
        }
        else
        {
            fDistance = (fStartPrice - m_fRangeLow) + (fEndPrice - m_fRangeLow);
        }
    }
    else
    {
        if (iStartDirection > 0)
        {
            fDistance = (m_fRangeHigh - fStartPrice) + (m_fRangeHigh - fEndPrice);
        }
        else
        {
            fDistance = fStartPrice - fEndPrice;
        }
    }

    return fDistance.DollarAmount() * fSpeed;
}

/*
*   Calculate triggering time for limit orders.
*
*   PARAMETERS:
*           IN  SecurityIndex   - unique security index to generate a unique starting price
*           IN  fPendingTime    - pending time of the order, in seconds from time 0
*           IN  fLimitPrice     - limit price of the order
*           IN  TradeType       - order trade type
*
*   RETURNS:
*           the expected submission time
*/
double CMEESecurity::GetSubmissionTime( TIdent          SecurityIndex,
                                        double          fPendingTime,   // in seconds from time 0
                                        CMoney          fLimitPrice,
                                        eTradeTypeID    TradeType
                                        )
{
    CMoney fPriceAtPendingTime = CalculatePrice( SecurityIndex, fPendingTime );

    int iDirectionAtPendingTime;

    double fSubmissionTimeFromPending;  // Submission - Pending time difference

    //  Check if the order is already in the money
    //  e.g. if the current price is less than the buy price
    //  or the current price is more than the sell price.
    //
    if (    ((TradeType == eLimitBuy || TradeType == eStopLoss) &&
            fPriceAtPendingTime <= fLimitPrice)
        ||
            ((TradeType == eLimitSell ) &&
            fPriceAtPendingTime >= fLimitPrice))
    {
        //  Order is in-the-money. Trigger immediatelly.
        //
        fSubmissionTimeFromPending = m_rnd.RndDoubleRange(0.5 * m_fMeanInTheMoneySubmissionDelay,
                                                          1.5 * m_fMeanInTheMoneySubmissionDelay);
    }
    else
    {
        if ((int)(fPendingTime + InitialTime( SecurityIndex )) % m_iPeriod < m_iPeriod / 2)
        {
            //  In the first half of the period => price is going up
            //
            iDirectionAtPendingTime = 1;
        }
        else
        {
            //  In the second half of the period => price is going down
            //
            iDirectionAtPendingTime = -1;
        }

        fSubmissionTimeFromPending = CalculateTime( fPriceAtPendingTime,
            fLimitPrice,
            iDirectionAtPendingTime);
    }

    return fPendingTime + fSubmissionTimeFromPending;
}

/*
*   Return the expected completion time and the completion price.
*   Completion time is between 0 and 5 seconds
*   with 1 sec mean.
*
*   Used to calculate completion time for
*   both limit (first must get submission time)
*   and market orders.
*
*   Equivalent of MEE function sequence
*   'receive trade' then 'complete the trade request'.
*
*   PARAMETERS:
*           IN  SecurityIndex       - unique security index to generate a unique starting price
*           IN  fSubmissionTime     - time when the order was submitted, in seconds from time 0
*           OUT pCompletionPrice    - completion price of the order
*
*   RETURNS:
*           the approximated completion time for the trade
*
*/
double CMEESecurity::GetCompletionTime( TIdent      SecurityIndex,
                                        double      fSubmissionTime,    // in seconds from time 0
                                        CMoney*     pCompletionPrice    // out
                                        )
{
    double  fCompletionDelay = NegExp(fMeanCompletionTimeDelay);

    // Clip at 5 seconds to prevent rare, but really long delays
    //
    if (fCompletionDelay > 5.0)
    {
        fCompletionDelay = 5.0;
    }

    if (pCompletionPrice != NULL)
    {
        *pCompletionPrice = CalculatePrice( SecurityIndex, fSubmissionTime + fCompletionDelay );
    }

    return fSubmissionTime + fCompletionDelay + fCompletionSUTDelay;
}

redpajama_set_name: RedPajamaGithub


text:
'use strict';

moduloUsuario.controller('UsuarioViewController', ['$scope', '$routeParams', 'serverService', '$location', '$rootScope',
    function ($scope, $routeParams, serverService, $location, $rootScope) {
        $scope.title = "Vista de usuario";
        $scope.icon = "/images/U.png";
        $scope.ob = 'usuario';
        $scope.id = $routeParams.id;
        serverService.getDataFromPromise(serverService.promise_getOne($scope.ob, $scope.id)).then(function (data) {
            $scope.bean = data.message;
        });
        $scope.volver = function () {
            $location.path('/usuario/plist/1/50');
        };
        $scope.close = function () {
            $location.path('/home');
        };
        $scope.plist = function () {
            $location.path('/usuario/plist');
        };
        $scope.back = function () {
            window.history.back();
        };

    }]);


text:
package me.st28.flexseries.flexcore.backend.commands;

import me.st28.flexseries.flexcore.FlexCore;
import me.st28.flexseries.flexcore.command.*;
import me.st28.flexseries.flexcore.list.ListBuilder;
import me.st28.flexseries.flexcore.message.MessageReference;
import me.st28.flexseries.flexcore.message.ReplacementMap;
import me.st28.flexseries.flexcore.permission.PermissionNodes;
import me.st28.flexseries.flexcore.plugin.module.FlexModule;
import me.st28.flexseries.flexcore.plugin.FlexPlugin;
import me.st28.flexseries.flexcore.util.PluginUtils;
import me.st28.flexseries.flexcore.util.QuickMap;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;

import java.util.*;

public final class CmdModules extends FlexCommand<FlexCore> implements FlexTabCompleter {

    public CmdModules(FlexCore plugin) {
        super(plugin, "flexmodules", Arrays.asList(new CommandArgument("plugin", true), new CommandArgument("page", false)), new FlexCommandSettings().permission(PermissionNodes.RELOAD));
    }

    @Override
    public void runCommand(CommandSender sender, String command, String label, String[] args, Map<String, String> parameters) {
        int page = CommandUtils.getPage(args, 1);

        String name = PluginUtils.getProperPluginName(args[0]);

        if (name == null) {
            MessageReference.create(FlexCore.class, "general.errors.plugin_not_found", new ReplacementMap("{NAME}", args[0]).getMap()).sendTo(sender);
            return;
        }

        Plugin plugin = Bukkit.getPluginManager().getPlugin(name);
        if (!(plugin instanceof FlexPlugin)) {
            MessageReference.create(FlexCore.class, "lib_plugin.errors.plugin_not_flexplugin", new ReplacementMap("{NAME}", name).getMap()).sendTo(sender);
            return;
        }

        List<FlexModule> modules = new ArrayList<>(((FlexPlugin) plugin).getModules());
        Collections.sort(modules, new Comparator<FlexModule>() {
            @Override
            public int compare(FlexModule o1, FlexModule o2) {
                return o1.getIdentifier().toLowerCase().compareTo(o2.getIdentifier().toLowerCase());
            }
        });

        ListBuilder builder = new ListBuilder("page_subtitle", "Modules", name, label);

        for (FlexModule module : modules) {
            String status;
            switch (module.getStatus()) {
                case ENABLED:
                    status = ChatColor.GREEN + "enabled";
                    break;

                case DISABLED_CONFIG:
                    status = ChatColor.DARK_RED + "disabled";
                    break;

                case DISABLED_DEPENDENCY:
                    status = ChatColor.RED + "missing dependency";
                    break;

                default:
                    status = ChatColor.RED + "error";
                    break;
            }

            builder.addMessage("lib_plugin_module", new QuickMap<>("{STATUS}", status).put("{NAME}", module.getIdentifier()).put("{DESCRIPTION}", module.getDescription()).getMap());
        }

        //TODO: Don't include page number if one was specified
        builder.enableNextPageNotice(command.replace("/", ""));
        builder.sendTo(sender, page);
    }

    @Override
    public List<String> getTabOptions(CommandSender sender, String[] args) {
        if (args.length != 1) {
            return null;
        }

        List<String> returnList = new ArrayList<>();

        for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            if (plugin instanceof FlexPlugin) {
                returnList.add(plugin.getName());
            }
        }

        return returnList;
    }

}


text: export { default } from 'ember-goods/services/goods-metrics';


text:
package org.apache.axis2.jaxws.message.util;

import org.apache.axis2.jaxws.message.util.impl.XMLStreamReaderFromDOM;

import javax.xml.soap.SOAPElement;
import javax.xml.stream.XMLStreamReader;

/** SOAPElementReader Creates an XMLStreamReader backed by a SOAPElement tree. */
public class SOAPElementReader extends Reader {

    SOAPElement element;

    /**
     * @param reader
     * @param resettable
     */
    public SOAPElementReader(SOAPElement element) {
        super(_newReader(element), true);

        this.element = element;
    }

    /* (non-Javadoc)
      * @see org.apache.axis2.jaxws.message.util.Reader#newReader()
      */
    @Override
    protected XMLStreamReader newReader() {
        return _newReader(element);
    }

    /**
     * Utility method to get the stream reader
     *
     * @param element
     * @return
     */
    private static XMLStreamReader _newReader(SOAPElement element) {
        // Construct a reader from an element
        return new XMLStreamReaderFromDOM(element);
    }
}


text:
package org.apache.pulsar.broker.service;

import io.netty.buffer.ByteBuf;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.apache.bookkeeper.mledger.Position;
import org.apache.pulsar.broker.service.persistent.DispatchRateLimiter;
import org.apache.pulsar.broker.service.persistent.SubscribeRateLimiter;
import org.apache.pulsar.broker.service.plugin.EntryFilterWithClassLoader;
import org.apache.pulsar.broker.stats.ClusterReplicationMetrics;
import org.apache.pulsar.broker.stats.NamespaceStats;
import org.apache.pulsar.client.api.MessageId;
import org.apache.pulsar.client.api.transaction.TxnID;
import org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition;
import org.apache.pulsar.common.api.proto.CommandSubscribe.SubType;
import org.apache.pulsar.common.api.proto.KeySharedMeta;
import org.apache.pulsar.common.policies.data.BacklogQuota;
import org.apache.pulsar.common.policies.data.BacklogQuota.BacklogQuotaType;
import org.apache.pulsar.common.policies.data.EntryFilters;
import org.apache.pulsar.common.policies.data.HierarchyTopicPolicies;
import org.apache.pulsar.common.policies.data.PersistentTopicInternalStats;
import org.apache.pulsar.common.policies.data.Policies;
import org.apache.pulsar.common.policies.data.stats.TopicStatsImpl;
import org.apache.pulsar.common.protocol.schema.SchemaData;
import org.apache.pulsar.common.protocol.schema.SchemaVersion;
import org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap;
import org.apache.pulsar.policies.data.loadbalancer.NamespaceBundleStats;
import org.apache.pulsar.utils.StatsOutputStream;

public interface Topic {

    interface PublishContext {

        default String getProducerName() {
            return null;
        }

        default long getSequenceId() {
            return -1L;
        }

        default void setOriginalProducerName(String originalProducerName) {
        }

        default void setOriginalSequenceId(long originalSequenceId) {
        }

        /**
         * Return the producer name for the original producer.
         *
         * For messages published locally, this will return the same local producer name, though in case of replicated
         * messages, the original producer name will differ
         */
        default String getOriginalProducerName() {
            return null;
        }

        default long getOriginalSequenceId() {
            return -1L;
        }

        void completed(Exception e, long ledgerId, long entryId);

        default void setMetadataFromEntryData(ByteBuf entryData) {
        }

        default long getHighestSequenceId() {
            return  -1L;
        }

        default void setOriginalHighestSequenceId(long originalHighestSequenceId) {

        }

        default long getOriginalHighestSequenceId() {
            return  -1L;
        }

        default long getNumberOfMessages() {
            return  1L;
        }

        default long getMsgSize() {
            return  -1L;
        }

        default boolean isMarkerMessage() {
            return false;
        }

        default void setProperty(String propertyName, Object value) {
        }

        default Object getProperty(String propertyName) {
            return null;
        }

        default boolean isChunked() {
            return false;
        }

        default long getEntryTimestamp() {
            return -1L;
        }

        default void setEntryTimestamp(long entryTimestamp) {

        }
    }

    CompletableFuture<Void> initialize();

    void publishMessage(ByteBuf headersAndPayload, PublishContext callback);

    /**
     * Tries to add a producer to the topic. Several validations will be performed.
     *
     * @param producer
     * @param producerQueuedFuture
     *            a future that will be triggered if the producer is being queued up prior of getting established
     * @return the "topic epoch" if there is one or empty
     */
    CompletableFuture<Optional<Long>> addProducer(Producer producer, CompletableFuture<Void> producerQueuedFuture);

    void removeProducer(Producer producer);

    /**
     * Wait TransactionBuffer Recovers completely.
     * Take snapshot after TB Recovers completely.
     * @param isTxnEnabled
     * @return a future which has completely if isTxn = false. Or a future return by takeSnapshot.
     */
    CompletableFuture<Void> checkIfTransactionBufferRecoverCompletely(boolean isTxnEnabled);

    /**
     * record add-latency.
     */
    void recordAddLatency(long latency, TimeUnit unit);

    /**
     * increase the publishing limited times.
     */
    long increasePublishLimitedTimes();

    @Deprecated
    CompletableFuture<Consumer> subscribe(TransportCnx cnx, String subscriptionName, long consumerId, SubType subType,
                                          int priorityLevel, String consumerName, boolean isDurable,
                                          MessageId startMessageId,
                                          Map<String, String> metadata, boolean readCompacted,
                                          InitialPosition initialPosition,
                                          long startMessageRollbackDurationSec, boolean replicateSubscriptionState,
                                          KeySharedMeta keySharedMeta);

    /**
     * Subscribe a topic.
     * @param option
     * @return
     */
    CompletableFuture<Consumer> subscribe(SubscriptionOption option);

    CompletableFuture<Subscription> createSubscription(String subscriptionName, InitialPosition initialPosition,
            boolean replicateSubscriptionState, Map<String, String> properties);

    CompletableFuture<Void> unsubscribe(String subName);

    ConcurrentOpenHashMap<String, ? extends Subscription> getSubscriptions();

    CompletableFuture<Void> delete();

    Map<String, Producer> getProducers();

    String getName();

    CompletableFuture<Void> checkReplication();

    CompletableFuture<Void> close(boolean closeWithoutWaitingClientDisconnect);

    void checkGC();

    CompletableFuture<Void> checkClusterMigration();

    void checkInactiveSubscriptions();

    /**
     * Activate cursors those caught up backlog-threshold entries and deactivate slow cursors which are creating
     * backlog.
     */
    void checkBackloggedCursors();

    void checkCursorsToCacheEntries();

    void checkDeduplicationSnapshot();

    void checkMessageExpiry();

    void checkMessageDeduplicationInfo();

    void checkTopicPublishThrottlingRate();

    void incrementPublishCount(int numOfMessages, long msgSizeInBytes);

    void resetTopicPublishCountAndEnableReadIfRequired();

    void resetBrokerPublishCountAndEnableReadIfRequired(boolean doneReset);

    boolean isPublishRateExceeded();

    boolean isTopicPublishRateExceeded(int msgSize, int numMessages);

    boolean isResourceGroupRateLimitingEnabled();

    boolean isResourceGroupPublishRateExceeded(int msgSize, int numMessages);

    boolean isBrokerPublishRateExceeded();

    void disableCnxAutoRead();

    void enableCnxAutoRead();

    CompletableFuture<Void> onPoliciesUpdate(Policies data);

    CompletableFuture<Void> checkBacklogQuotaExceeded(String producerName, BacklogQuotaType backlogQuotaType);

    boolean isEncryptionRequired();

    boolean getSchemaValidationEnforced();

    boolean isReplicated();

    boolean isShadowReplicated();

    EntryFilters getEntryFiltersPolicy();

    Map<String, EntryFilterWithClassLoader> getEntryFilters();

    BacklogQuota getBacklogQuota(BacklogQuotaType backlogQuotaType);

    void updateRates(NamespaceStats nsStats, NamespaceBundleStats currentBundleStats,
            StatsOutputStream topicStatsStream, ClusterReplicationMetrics clusterReplicationMetrics,
            String namespaceName, boolean hydratePublishers);

    Subscription getSubscription(String subscription);

    ConcurrentOpenHashMap<String, ? extends Replicator> getReplicators();

    ConcurrentOpenHashMap<String, ? extends Replicator> getShadowReplicators();

    TopicStatsImpl getStats(boolean getPreciseBacklog, boolean subscriptionBacklogSize,
                            boolean getEarliestTimeInBacklog);

    CompletableFuture<? extends TopicStatsImpl> asyncGetStats(boolean getPreciseBacklog,
                                                              boolean subscriptionBacklogSize,
                                                              boolean getEarliestTimeInBacklog);

    CompletableFuture<PersistentTopicInternalStats> getInternalStats(boolean includeLedgerMetadata);

    Position getLastPosition();

    CompletableFuture<MessageId> getLastMessageId();

    /**
     * Whether a topic has had a schema defined for it.
     */
    CompletableFuture<Boolean> hasSchema();

    /**
     * Add a schema to the topic. This will fail if the new schema is incompatible with the current
     * schema.
     */
    CompletableFuture<SchemaVersion> addSchema(SchemaData schema);

    /**
     * Delete the schema if this topic has a schema defined for it.
     */
    CompletableFuture<SchemaVersion> deleteSchema();

    /**
     * Check if schema is compatible with current topic schema.
     */
    CompletableFuture<Void> checkSchemaCompatibleForConsumer(SchemaData schema);

    /**
     * If the topic is idle (no producers, no entries, no subscribers and no existing schema),
     * add the passed schema to the topic. Otherwise, check that the passed schema is compatible
     * with what the topic already has.
     */
    CompletableFuture<Void> addSchemaIfIdleOrCheckCompatible(SchemaData schema);

    CompletableFuture<Void> deleteForcefully();

    default Optional<DispatchRateLimiter> getDispatchRateLimiter() {
        return Optional.empty();
    }

    default Optional<SubscribeRateLimiter> getSubscribeRateLimiter() {
        return Optional.empty();
    }

    default Optional<DispatchRateLimiter> getBrokerDispatchRateLimiter() {
        return Optional.empty();
    }

    default boolean isSystemTopic() {
        return false;
    }

    boolean isPersistent();

    /* ------ Transaction related ------ */

    /**
     * Publish Transaction message to this Topic's TransactionBuffer.
     *
     * @param txnID             Transaction Id
     * @param headersAndPayload Message data
     * @param publishContext    Publish context
     */
    void publishTxnMessage(TxnID txnID, ByteBuf headersAndPayload, PublishContext publishContext);

    /**
     * End the transaction in this topic.
     *
     * @param txnID Transaction id
     * @param txnAction Transaction action.
     * @param lowWaterMark low water mark of this tc
     * @return
     */
    CompletableFuture<Void> endTxn(TxnID txnID, int txnAction, long lowWaterMark);

    /**
     * Truncate a topic.
     * The truncate operation will move all cursors to the end of the topic and delete all inactive ledgers.
     * @return
     */
    CompletableFuture<Void> truncate();

    /**
     * Get BrokerService.
     * @return
     */
    BrokerService getBrokerService();

    /**
     * Get HierarchyTopicPolicies.
     * @return
     */
    HierarchyTopicPolicies getHierarchyTopicPolicies();

}


text:
Figura
======

Figura is an *expressive high-level configuration language* based on Python syntax.

This is a python package for parsing and working with `Figura <http://figura.readthedocs.io/>`_ config files.

This library also includes an executable ``figura_print`` command, for processing
your figura config files and generating your configuration, printing it as a JSON structure.
The generated JSON-structured configuration can then be read by programs written in
any other language (using its JSON parser).

For more details, `Read the Figura Docs <http://figura.readthedocs.io/>`_.


text:
<?php

namespace EventsForce\Resources;

use EventsForce\Client;
use EventsForce\Exceptions\InvalidArgumentException;

/**
 * Class BaseResource
 * Abstract used by all resources
 *
 * @package EventsForce\Resources
 */
abstract class BaseResource
{
    /**
     * Stores an instance of the client for resources to Access
     * @var Client
     */
    protected $client;

    /**
     * Stores the endpoint prefix prior to all requests
     * @var string
     */
    protected $endpoint_prefix = '';

    /**
     * BaseResource constructor.
     * @param Client $client
     */
    public function __construct(Client $client)
    {
        $this->client = $client;
    }

    /**
     * Method to generate the endpoint
     * Accepts either string or array
     * e.g string 2/attendees.json
     * or array [2, 'attendees.json']
     * both return events/2/attendees.json when the endpoint_prefix is events
     *
     * @param string | array $suffix
     * @return string
     */
    public function genEndpoint($suffix = '')
    {
        if (!is_array($suffix) && !is_string($suffix)) {
            throw new InvalidArgumentException('You need to pass a valid suffix to generate an endpoint for a resource');
        }

        if (is_array($suffix)) {
            $suffix = implode('/', $suffix);
        }

        if (!empty($this->endpoint_prefix)) {
            $endpoint = $this->endpoint_prefix . '/' . $suffix;
        } else {
            $endpoint = $suffix;
        }

        return $endpoint;
    }

    /**
     * method to merge array of arguments with defaults
     *
     * @param $args - passed in arguments
     * @param $defaults - default argument array to merge with
     *
     * @return array
     */
    public function argsMerge($args = null, $defaults = null)
    {
        if (!is_array($defaults)) {
            $defaults = [];
        }

        if (!is_array($args)) {
            throw new InvalidArgumentException('You must pass an array as your arguments to merge');
        }

        return array_merge($defaults, $args);
    }
}


text:
namespace orion
{
namespace net
{
namespace http2
{
//--------------------------------------------------------------------------------------------------
// Header

struct Header
{
   std::string name;
   std::string value;
   bool indexable{true};

   // Calculates the size of a single entry + 32
   std::size_t size() const { return name.size() + value.size() + 32; }
};

inline bool operator==(const Header& h1, const Header& h2) noexcept
{
   return h1.name == h2.name and h1.value == h2.value and h1.indexable == h2.indexable;
}

inline bool operator!=(const Header& h1, const Header& h2) noexcept
{
   return not (h1 == h2);
}

//--------------------------------------------------------------------------------------------------
// Headers

using Headers = std::vector<Header>;

inline bool operator==(const Headers& h1, const Headers& h2) noexcept
{
   return std::equal(std::begin(h1), std::end(h1), std::begin(h2), std::end(h2));
}

inline bool operator!=(const Headers& h1, const Headers& h2) noexcept
{
   return not (h1 == h2);
}

//--------------------------------------------------------------------------------------------------
// Callback functions

using CloseHandler   = std::function<void()>;
using ConnectHandler = std::function<void(const asio::ip::tcp::endpoint&)>;
using ErrorHandler   = std::function<void(const std::error_code&)>;
using GoAwayHandler  = std::function<void(const std::error_code&, asio::const_buffer)>;
using PingHandler    = std::function<void(asio::const_buffer)>;

} // namespace http2
} // namespace net
} // namespace orion

#endif // ORION_NET_HTTP2_UTILS_H


text:
<?php

namespace RdKafka;

class Consumer extends \RdKafka
{
    /**
     * @param Conf $conf
     */
    public function __construct(Conf $conf = null)
    {
    }

    /**
     * @param string    $topic_name
     * @param TopicConf $topic_conf
     *
     * @return ConsumerTopic
     */
    public function newTopic($topic_name, TopicConf $topic_conf = null)
    {
    }

    /**
     * @return Queue
     */
    public function newQueue()
    {
    }
}


text:
package org.usfirst.frc2811.RecycleRush.commands;

import org.usfirst.frc2811.RecycleRush.Robot;

import edu.wpi.first.wpilibj.command.Command;

/**
 * Stops the bident where it's currently at.
 * Optionally, can be set to clear the I accumulation for safety on mode switching
 * @params optional, ClearIaccumulation: Clear I accumulation of PID
 */
public class BidentStop extends Command {
	boolean clearIaccumulation=false;
    public BidentStop() {
        // Use requires() here to declare subsystem dependencies
        //Do nothing, just update
    }
    public BidentStop(boolean ClearIaccumulation) {
        // Use requires() here to declare subsystem dependencies
        //Do nothing, just update
    	clearIaccumulation=ClearIaccumulation;
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    	Robot.bident.stop(clearIaccumulation);
    	System.out.println("Bident::Stop::Stopping at "+Robot.bident.getHeight()+ (clearIaccumulation?" and cleared Iaccumulation":"") );
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return true;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}


text:
package metroinsight.citadel.metadata.impl;

import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.query.Binding;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.QueryResults;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.RepositoryConnection;

import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.servicediscovery.ServiceDiscovery;
import metroinsight.citadel.common.ErrorMessages;
import metroinsight.citadel.metadata.MetadataService;
import virtuoso.rdf4j.driver.VirtuosoRepository;

public class VirtuosoRdf4jService implements MetadataService{
  private final Vertx vertx;
  private final ServiceDiscovery discovery;
  ValueFactory factory;
  RepositoryConnection conn;

  // Prefixes
  final String CITADEL = "http://metroinsight.io/citadel#";
  final String RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  final String RDFS = "http://www.w3.org/2000/01/rdf-schema#";
  final String EX = "http://example.com#";
  final String BIF = "http://www.openlinksw.com/schema/sparql/extensions#";
  String queryPrefix;

  Map<String, IRI> propertyMap;
  Map<String, String> valPropMap;
  // TODO: Maybe add a map between uesr-prop to rdf property. e.g., "pointType" ->
  // rdf:type.

  // Common Variables
  IRI a;
  IRI hasUnit;
  IRI hasName;
  IRI context;

  // Units
  List<String> units;
  List<String> types;
  String graphname;

  public VirtuosoRdf4jService(Vertx vertx, String virtHostname, Integer virtPort, String graphname, String username,
      String password, ServiceDiscovery discovery) {
    String url = String.format("jdbc:virtuoso://%s:%d/log_enable=0", virtHostname, virtPort);
    VirtuosoRepository repository = new VirtuosoRepository(url, username, password);
    factory = repository.getValueFactory();
    conn = repository.getConnection();
    context = repository.getValueFactory().createIRI(graphname);
    this.graphname = graphname;
    this.vertx = vertx;
    this.discovery = discovery;
    initSchema();
  }

  private void initSchema() {
    // Init prefixes for SPARQL
    queryPrefix = String.format("PREFIX citadel: <%s>\n", CITADEL) +
                  String.format("PREFIX rdf: <%s>\n", RDF) +
                  String.format("PREFIX rdfs: <%s>\n", RDFS) +
                  String.format("PREFIX ex: <%s>\n", EX) +
                  "PREFIX bif: <bif:>\n" +
                  "PREFIX xsd: <xsd:>\n";

    // Init common variables
    units = new ArrayList<String>();
    types = new ArrayList<String>();

    a = factory.createIRI(RDF, "type");
    hasUnit = factory.createIRI(CITADEL, "unit");
    hasName = factory.createIRI(CITADEL, "name");

    // Init Namespace Map
    // This may be automated once we get a schema file (in Turtle).
    propertyMap = new HashMap<String, IRI>();
    propertyMap.put("pointType", factory.createIRI(RDF, "type"));
    propertyMap.put("subClassOf", factory.createIRI(RDFS, "subClassOf"));
    propertyMap.put("unit", factory.createIRI(CITADEL, "unit"));
    propertyMap.put("owner", factory.createIRI(CITADEL, "owner"));
    propertyMap.put("name", factory.createIRI(CITADEL, "name"));
    valPropMap = new HashMap<String, String>();
    valPropMap.put("name", "string");
    valPropMap.put("unit", "citadel");
    valPropMap.put("pointType", "citadel");

    // Init units
    // types
    List<String> citadelTypes = new ArrayList<String>(units);
    citadelTypes.addAll(types);
    for (int i = 0; i < citadelTypes.size(); i++) {
      String v = citadelTypes.get(i);
      propertyMap.put(v, factory.createIRI(CITADEL, v));
    }
  }

  private Value withPrefixValue(String prop, String id) {
    if (valPropMap.containsKey(prop)) {
      String valType = valPropMap.get(prop);
      if (valType.equals("string")) {
        return factory.createLiteral(id);
      } else if (valType.equals("citadel")) {
        return factory.createIRI(CITADEL, id);
      } else {
        System.out.println("TODO: Unknown value type");
        return factory.createIRI(EX, id);
      }
    } else {
      return factory.createLiteral(id);
    }
  }

  private IRI withPrefixProp(String id) {
    return propertyMap.getOrDefault(id, factory.createIRI(EX, id));
  }

  // public static final String VIRTUOSO_INSTANCE = "mc64";
  public static final String VIRTUOSO_INSTANCE = "localhost";
  public static final int VIRTUOSO_PORT = 1111;
  public static final String VIRTUOSO_USERNAME = "dba";
  public static final String VIRTUOSO_PASSWORD = "dba";

  public static void log(String mess) {
    System.out.println("   " + mess);
  }

  TupleQueryResult doTupleQuery(String query) throws Exception {
    try {
      TupleQuery resultsTable = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
      resultsTable.setIncludeInferred(false);
      TupleQueryResult bindings = resultsTable.evaluate();
      bindings = QueryResults.distinctResults(bindings);
      return bindings;
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }

  static void exec_query(Statement st, String query) throws Exception {
    String s = trimStr(query);
    if (s.length() > 0) {
      if (s.charAt(s.length() - 1) == ';') {
        s = s.substring(0, s.length() - 1);
      }
      st.execute(s);
    }

  }

  static String trimStr(String s) {
    int last = s.length() - 1;
    for (int i = last; i >= 0 && Character.isWhitespace(s.charAt(i)); i--) {
    }
    return s.substring(0, last).trim();
  }

  private JsonArray findByStringValue(String tag, String value) throws Exception {
    try {
      if (value.startsWith("\"") && value.endsWith("\"")) {
        value = value.substring(1, value.length() - 1);
      }
      String qStr = queryPrefix +
                    "SELECT ?s FROM <" + context + "> WHERE {\n" +
                    String.format("?s citadel:%s ?o . ?o bif:contains \"'%s'\". }\n", tag, value);
      TupleQueryResult res = doTupleQuery(qStr);
      JsonArray results = new JsonArray();
      while (res.hasNext()) {
        BindingSet tup = res.next();
        Binding aaa = tup.getBinding("s");
        results.add(aaa.toString());
      }
      return results;
    } catch (Exception e) {
      throw e;
    }
  }

  @Override
  public void createPoint(JsonObject jsonMetadata, Handler<AsyncResult<String>> resultHandler) {
    try {
      long totalStartTime = System.nanoTime();
      if (jsonMetadata.getString("name").contains(" ")) {
        throw new Exception("Empty space is not allowed in name.");
      }
      else if (jsonMetadata.getString("unit").contains(" ")) {
        throw new Exception("Empty space is not allowed in unit.");
      }
      // Check if the name already exists
      String nameStr = jsonMetadata.getString("name");
      /*
      ParameterizedSparqlString pss = getDefaultPss();
      pss.setCommandText("select ?s where {?s citadel:name ?name .}");
      pss.setParam("name", name);
      ResultSet res = sparqlQuery(pss.toString());
      */
      long startTime = System.nanoTime();
      Value name = withPrefixValue("name", nameStr); // TODO: Change name to Literal later
      //ResultSet res = findByStringValue("name", nameStr);
      JsonArray res = findByStringValue("name", name.stringValue());
      //Node name = withPrefixValue("name", nameStr); // TODO: Change name to Literal later
      if (res.size() > 0) {
        resultHandler.handle(Future.failedFuture(ErrorMessages.EXISTING_POINT_NAME));
      } else {
        // Create the point
        startTime = System.nanoTime();
        String uuid = jsonMetadata.getString("uuid");//UUID.randomUUID().toString();
        IRI point = factory.createIRI(EX, uuid);
        Value pointType = withPrefixValue("pointType", jsonMetadata.getString("pointType"));
        conn.add(point, a, pointType);
        Value unit = withPrefixValue("unit", jsonMetadata.getString("unit"));
        conn.add(point,  hasUnit, unit, context);
        conn.add(point,  hasName, name, context);
        Iterator<String> tagIter = jsonMetadata.fieldNames().iterator();
        while (tagIter.hasNext()) {
          String tag = tagIter.next();
          String value = jsonMetadata.getString(tag);
          // Check if tag corresponds to predefines properties which should be handeled above.
          if (!tag.equals("unit") && !tag.equals("name") && !tag.equals("uuid") && !tag.equals("pointType")) {
            conn.add(point, withPrefixProp(tag), withPrefixValue(tag, value), context);
          }
        }
        resultHandler.handle(Future.succeededFuture(uuid));
      }
    } catch (Exception e) {
      resultHandler.handle(Future.failedFuture(e));
    }
  }

  @Override
  public void getPoint(String uuid, Handler<AsyncResult<JsonObject>> resultHandler) {
    try {
      String qStr = queryPrefix +
                    String.format("SELECT ?p ?o WHERE {<%s> ?p ?o}", factory.createIRI(EX, uuid));
      TupleQueryResult results = doTupleQuery(qStr);
      if (!results.hasNext()) {
        resultHandler.handle(Future.failedFuture("Not existing UUID"));
      } else {
        JsonObject metadata = new JsonObject();
        while (results.hasNext()) {
          BindingSet result = results.next();
          String p = result.getValue("p").toString().split("#")[1];
          String o = result.getValue("o").toString().split("#")[1]; // TODO: If it is a string?
          if (p.equals("type")) {
            p = "pointType";
          }
          metadata.put(p, o);
        }
        metadata.put("uuid", uuid);
        resultHandler.handle(Future.succeededFuture(metadata));
      }
    } catch (Exception e) {
      resultHandler.handle(Future.failedFuture(e));
    }
  }

  @Override
  public void queryPoint(JsonObject query, Handler<AsyncResult<JsonArray>> resultHandler) {
    try {
      // Construct a SPARQL query.
      String qStr = queryPrefix + "SELECT ?s FROM <" + context + "> WHERE {\n";
      Iterator<String> fieldIter = query.fieldNames().iterator();
      while (fieldIter.hasNext()) {
        String tagStr = fieldIter.next();
        IRI tagNode = withPrefixProp(tagStr);
        Value valNode = withPrefixValue(tagStr, query.getString(tagStr));
        Boolean isIri = true;
        try {
          IRI aaa = (IRI) valNode;
        } catch (Exception e) {
          isIri = false;
        }
        if (isIri) {
          qStr += String.format("?s <%s> <%s> . \n", tagNode, valNode);
        } else {
          qStr += String.format("?s <%s> %s . \n", tagNode, valNode);
        }
      }
      qStr += "?s ?p ?o .\n}";
      TupleQueryResult results = doTupleQuery(qStr);
      JsonArray uuids = new JsonArray();
      while (results.hasNext()) {
        uuids.add(results.next().getValue("s").toString().split("#")[1]);
      }
      resultHandler.handle(Future.succeededFuture(uuids));
    }catch (Exception e) {
      resultHandler.handle(Future.failedFuture(e));
    }
  }

  @Override
  public void upsertMetadata(String uuid, JsonObject newMetadata, Handler<AsyncResult<Void>> rh) {
    try {
      IRI point = factory.createIRI(EX, uuid);
      Iterator<String> keys = newMetadata.fieldNames().iterator();
      while (keys.hasNext()) {
        String key = keys.next();
        IRI prop = withPrefixProp(key);
        Object value = newMetadata.getString(key);
        if (value instanceof List) { // TODO: Check this is working. If not working, use try catch.
          Iterator<String> valueIter = ((List<String>) value).iterator();
          while (valueIter.hasNext()) {
            conn.add(point, prop, withPrefixProp(valueIter.next()), context);
          }
        } else if (value instanceof String) {
          conn.add(point, prop, withPrefixValue(key, (String) value));
        }
      }
      rh.handle(Future.succeededFuture());
    } catch (Exception e) {
      rh.handle(Future.failedFuture(e));
    }
  }

  public static void main(String[] args) {
  }
}


text:
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Preview;
using Microsoft.CodeAnalysis.Editor.Shared.Tagging;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.CodeAnalysis.Editor.Implementation.Preview
{
    [Export(typeof(ITaggerProvider))]
    [TagType(typeof(PreviewWarningTag))]
    [ContentType(ContentTypeNames.RoslynContentType)]
    [TextViewRole(TextViewRoles.PreviewRole)]
    internal class PreviewWarningTaggerProvider
        : AbstractPreviewTaggerProvider<PreviewWarningTag>
    {
        [ImportingConstructor]
        public PreviewWarningTaggerProvider() :
            base(PredefinedPreviewTaggerKeys.WarningSpansKey, PreviewWarningTag.Instance)
        {
        }
    }
}


text:
package org.apache.catalina.authenticator;

import static org.jboss.web.CatalinaMessages.MESSAGES;

import java.io.IOException;
import java.security.Principal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.Authenticator;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Manager;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Realm;
import org.apache.catalina.Session;
import org.apache.catalina.Valve;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.deploy.LoginConfig;
import org.apache.catalina.deploy.SecurityConstraint;
import org.apache.catalina.session.ManagerBase;
import org.apache.catalina.util.DateTool;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.valves.ValveBase;
import org.jboss.web.CatalinaLogger;

/**
 * Basic implementation of the Valve interface that enforces the
 * <security-constraint> elements in the web application
 * deployment descriptor.  This functionality is implemented as a Valve
 * so that it can be ommitted in environments that do not require these
 * features.  Individual implementations of each supported authentication
 * method can subclass this base class as required.
 *

 * USAGE CONSTRAINT:  When this class is utilized, the Context to
 * which it is attached (or a parent Container in a hierarchy) must have an
 * associated Realm that can be used for authenticating users and enumerating
 * the roles to which they have been assigned.
 *

 * USAGE CONSTRAINT:  This Valve is only useful when processing HTTP
 * requests.  Requests of any other type will simply be passed through.
 *
 * @author Craig R. McClanahan
 * @version $Revision: 1848 $ $Date: 2011-10-11 17:29:56 +0200 (Tue, 11 Oct 2011) $
 */

public abstract class AuthenticatorBase
    extends ValveBase
    implements Authenticator, Lifecycle {

    // ----------------------------------------------------- Instance Variables

    /**
     * Authentication header
     */
    protected static final String AUTH_HEADER_NAME = "WWW-Authenticate";

    /**
     * Default authentication realm name.
     */
    protected static final String REALM_NAME = "Authentication required";

    /**
     * The number of random bytes to include when generating a
     * session identifier.
     */
    protected static final int SESSION_ID_BYTES = 18;

    /**
     * Should we cache authenticated Principals if the request is part of
     * an HTTP session?
     */
    protected boolean cache = true;

    /**
     * Should the session ID, if any, be changed upon a successful
     * authentication to prevent a session fixation attack?
     */
    protected boolean changeSessionIdOnAuthentication =
        Boolean.valueOf(System.getProperty("org.apache.catalina.authenticator.AuthenticatorBase.CHANGE_SESSIONID_ON_AUTH", "false")).booleanValue();

    /**
     * Should the session ID, if any, be changed upon a successful
     * authentication to prevent a session fixation attack?
     */
    protected boolean unregisterSsoOnLogout =
        Boolean.valueOf(System.getProperty("org.apache.catalina.authenticator.AuthenticatorBase.UNREGISTER_SSO_ON_LOGOUT", "false")).booleanValue();

    /**
     * Should a session always be used once a user is authenticated? This may
     * offer some performance benefits since the session can then be used to
     * cache the authenticated Principal, hence removing the need to
     * authenticate the user via the Realm on every request. This may be of help
     * for combinations such as BASIC authentication used with the JNDIRealm or
     * DataSourceRealms. However there will also be the performance cost of
     * creating and GC'ing the session. By default, a session will not be
     * created.
     */
    protected boolean alwaysUseSession =
        Boolean.valueOf(System.getProperty("org.apache.catalina.authenticator.AuthenticatorBase.ALWAYS_USE_SESSION", "false")).booleanValue();

    /**
     * The Context to which this Valve is attached.
     */
    protected Context context = null;

    /**
     * Descriptive information about this implementation.
     */
    protected static final String info =
        "org.apache.catalina.authenticator.AuthenticatorBase/1.0";

    /**
     * Flag to determine if we disable proxy caching, or leave the issue
     * up to the webapp developer.
     */
    protected boolean disableProxyCaching = true;

    /**
     * Flag to determine if we disable proxy caching with headers incompatible
     * with IE
     */
    protected boolean securePagesWithPragma = true;

    /**
     * The lifecycle event support for this component.
     */
    protected LifecycleSupport lifecycle = new LifecycleSupport(this);

    /**
     * The SingleSignOn implementation in our request processing chain,
     * if there is one.
     */
    protected SingleSignOn sso = null;

    /**
     * Has this component been started?
     */
    protected boolean started = false;

    /**
     * "Expires" header always set to Date(1), so generate once only
     */
    private static final String DATE_ONE =
        (new SimpleDateFormat(DateTool.HTTP_RESPONSE_DATE_HEADER,
                              Locale.US)).format(new Date(1));

    // ------------------------------------------------------------- Properties

    /**
     * Return the cache authenticated Principals flag.
     */
    public boolean getCache() {

        return (this.cache);

    }

    /**
     * Set the cache authenticated Principals flag.
     *
     * @param cache The new cache flag
     */
    public void setCache(boolean cache) {

        this.cache = cache;

    }

    public boolean isChangeSessionIdOnAuthentication() {
        return changeSessionIdOnAuthentication;
    }

    public void setChangeSessionIdOnAuthentication(
            boolean changeSessionIdOnAuthentication) {
        this.changeSessionIdOnAuthentication = changeSessionIdOnAuthentication;
    }

    public boolean isUnregisterSsoOnLogout() {
        return unregisterSsoOnLogout;
    }

    public void setUnregisterSsoOnLogout(boolean unregisterSsoOnLogout) {
        this.unregisterSsoOnLogout = unregisterSsoOnLogout;
    }

    /**
     * Return the Container to which this Valve is attached.
     */
    public Container getContainer() {

        return (this.context);

    }

    /**
     * Set the Container to which this Valve is attached.
     *
     * @param container The container to which we are attached
     */
    public void setContainer(Container container) {

        if (!(container instanceof Context))
            throw MESSAGES.authenticatorNeedsContext();

        super.setContainer(container);
        this.context = (Context) container;

    }

    /**
     * Return descriptive information about this Valve implementation.
     */
    public String getInfo() {

        return (info);

    }

    /**
     * Return the flag that states if we add headers to disable caching by
     * proxies.
     */
    public boolean getDisableProxyCaching() {
        return disableProxyCaching;
    }

    /**
     * Set the value of the flag that states if we add headers to disable
     * caching by proxies.
     * @param nocache true if we add headers to disable proxy
     *              caching, false if we leave the headers alone.
     */
    public void setDisableProxyCaching(boolean nocache) {
        disableProxyCaching = nocache;
    }

    /**
     * Return the flag that states, if proxy caching is disabled, what headers
     * we add to disable the caching.
     */
    public boolean getSecurePagesWithPragma() {
        return securePagesWithPragma;
    }

    /**
     * Set the value of the flag that states what headers we add to disable
     * proxy caching.
     * @param securePagesWithPragma true if we add headers which
     * are incompatible with downloading office documents in IE under SSL but
     * which fix a caching problem in Mozilla.
     */
    public void setSecurePagesWithPragma(boolean securePagesWithPragma) {
        this.securePagesWithPragma = securePagesWithPragma;
    }

    // --------------------------------------------------------- Public Methods

    /**
     * API login.
     *
     * @param request Request we are processing
     * @param response Response we are creating
     * @param config    Login configuration describing how authentication
     *              should be performed
     *
     * @exception IOException if an input/output error occurs
     */
    public boolean authenticate(Request request, HttpServletResponse response)
        throws IOException, ServletException {
        return authenticate(request, response, this.context.getLoginConfig());
    }

    public void login(Request request, String username, String password)
        throws ServletException {

        // Is there an SSO session against which we can try to reauthenticate?
        String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
        if (ssoId != null) {
            if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled())
                CatalinaLogger.AUTH_LOGGER.debug("SSO Id " + ssoId + " set; attempting " +
                          "reauthentication");
            /* Try to reauthenticate using data cached by SSO.  If this fails,
               either the original SSO logon was of DIGEST or SSL (which
               we can't reauthenticate ourselves because there is no
               cached username and password), or the realm denied
               the user's reauthentication for some reason.
               In either case we have to prompt the user for a logon */
            if (reauthenticateFromSSO(ssoId, request))
                return;
        }

        Realm realm = context.getRealm();
        Principal principal = realm.authenticate(username, password);
        if (principal != null) {
            register(request, request.getResponseFacade(), principal, Constants.LOGIN_METHOD,
                     username, password);
        }
    }

    public void logout(Request request)
        throws ServletException {
        unregister(request, request.getResponseFacade());
    }

    /**
     * Enforce the security restrictions in the web application deployment
     * descriptor of our associated Context.
     *
     * @param request Request to be processed
     * @param response Response to be processed
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if thrown by a processing element
     */
    public void invoke(Request request, Response response)
        throws IOException, ServletException {

        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled())
            CatalinaLogger.AUTH_LOGGER.debug("Security checking request " +
                request.getMethod() + " " + request.getRequestURI());
        LoginConfig config = this.context.getLoginConfig();

        // Have we got a cached authenticated Principal to record?
        if (cache) {
            Principal principal = request.getUserPrincipal();
            if (principal == null) {
                Session session = request.getSessionInternal(false);
                if (session != null) {
                    principal = session.getPrincipal();
                    if (principal != null) {
                        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled())
                            CatalinaLogger.AUTH_LOGGER.debug("We have cached auth type " +
                                session.getAuthType() +
                                " for principal " +
                                session.getPrincipal());
                        request.setAuthType(session.getAuthType());
                        request.setUserPrincipal(principal);
                    }
                }
            }
        }

        // Special handling for form-based logins to deal with the case
        // where the login form (and therefore the "j_security_check" URI
        // to which it submits) might be outside the secured area
        String contextPath = this.context.getPath();
        String requestURI = request.getDecodedRequestURI();
        if (requestURI.startsWith(contextPath) &&
            requestURI.endsWith(Constants.FORM_ACTION)) {
            if (!authenticate(request, response, config)) {
                if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled())
                    CatalinaLogger.AUTH_LOGGER.debug(" Failed authenticate() test ??" + requestURI );
                return;
            }
        }

        Realm realm = this.context.getRealm();
        // Is this request URI subject to a security constraint?
        SecurityConstraint [] constraints
            = realm.findSecurityConstraints(request, this.context);

        if ((constraints == null) /* &&
            (!Constants.FORM_METHOD.equals(config.getAuthMethod())) */ ) {
            if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled())
                CatalinaLogger.AUTH_LOGGER.debug(" Not subject to any constraint");
            getNext().invoke(request, response);
            return;
        }

        // Make sure that constrained resources are not cached by web proxies
        // or browsers as caching can provide a security hole
        if (disableProxyCaching &&
            // Note: Disabled for Mozilla FORM support over SSL
            // (improper caching issue)
            //!request.isSecure() &&
            !"POST".equalsIgnoreCase(request.getMethod())) {
            if (securePagesWithPragma) {
                // Note: These cause problems with downloading office docs
                // from IE under SSL and may not be needed for newer Mozilla
                // clients.
                response.setHeader("Pragma", "No-cache");
                response.setHeader("Cache-Control", "no-cache");
            } else {
                response.setHeader("Cache-Control", "private");
            }
            response.setHeader("Expires", DATE_ONE);
        }

        int i;
        // Enforce any user data constraint for this security constraint
        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
            CatalinaLogger.AUTH_LOGGER.debug(" Calling hasUserDataPermission()");
        }
        if (!realm.hasUserDataPermission(request, response,
                                         constraints)) {
            if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
                CatalinaLogger.AUTH_LOGGER.debug(" Failed hasUserDataPermission() test");
            }
            /*
             * ASSERT: Authenticator already set the appropriate
             * HTTP status code, so we do not have to do anything special
             */
            return;
        }

        // Since authenticate modifies the response on failure,
        // we have to check for allow-from-all first.
        boolean authRequired = true;
        for(i=0; i < constraints.length && authRequired; i++) {
            if(!constraints[i].getAuthConstraint()) {
                authRequired = false;
            } else if(!constraints[i].getAllRoles()) {
                String [] roles = constraints[i].findAuthRoles();
                if(roles == null || roles.length == 0) {
                    authRequired = false;
                }
            }
        }

        if(authRequired) {
            if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
                CatalinaLogger.AUTH_LOGGER.debug(" Calling authenticate()");
            }
            if (!authenticate(request, response, config)) {
                if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
                    CatalinaLogger.AUTH_LOGGER.debug(" Failed authenticate() test");
                }
                /*
                 * ASSERT: Authenticator already set the appropriate
                 * HTTP status code, so we do not have to do anything
                 * special
                 */
                return;
            }
        }

        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
            CatalinaLogger.AUTH_LOGGER.debug(" Calling accessControl()");
        }
        if (!realm.hasResourcePermission(request, response,
                                         constraints,
                                         this.context)) {
            if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
                CatalinaLogger.AUTH_LOGGER.debug(" Failed accessControl() test");
            }
            /*
             * ASSERT: AccessControl method has already set the
             * appropriate HTTP status code, so we do not have to do
             * anything special
             */
            return;
        }

        // Any and all specified constraints have been satisfied
        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
            CatalinaLogger.AUTH_LOGGER.debug(" Successfully passed all security constraints");
        }
        getNext().invoke(request, response);

    }

    // ------------------------------------------------------ Protected Methods

    /**
     * Associate the specified single sign on identifier with the
     * specified Session.
     *
     * @param ssoId Single sign on identifier
     * @param session Session to be associated
     */
    protected void associate(String ssoId, Session session) {

        if (sso == null)
            return;
        sso.associate(ssoId, session);

    }

    /**
     * Authenticate the user making this request, based on the specified
     * login configuration.  Return true if any specified
     * constraint has been satisfied, or false if we have
     * created a response challenge already.
     *
     * @param request Request we are processing
     * @param response Response we are creating
     * @param config    Login configuration describing how authentication
     *              should be performed
     *
     * @exception IOException if an input/output error occurs
     */
    protected abstract boolean authenticate(Request request,
                                            HttpServletResponse response,
                                            LoginConfig config)
        throws IOException;

    /**
     * Generate and return a new session identifier for the cookie that
     * identifies an SSO principal.
     */
    protected synchronized String generateSessionId(Random random) {

        byte[] bytes = new byte[SESSION_ID_BYTES];
        random.nextBytes(bytes);
        // Encode the result
        char[] id = ManagerBase.encode(bytes);
        return String.valueOf(id);

    }

    /**
     * Attempts reauthentication to the Realm using
     * the credentials included in argument entry.
     *
     * @param ssoId identifier of SingleSignOn session with which the
     *              caller is associated
     * @param request   the request that needs to be authenticated
     */
    protected boolean reauthenticateFromSSO(String ssoId, Request request) {

        if (sso == null || ssoId == null)
            return false;

        boolean reauthenticated = false;

        Container parent = getContainer();
        if (parent != null) {
            Realm realm = parent.getRealm();
            if (realm != null) {
                reauthenticated = sso.reauthenticate(ssoId, realm, request);
            }
        }

        if (reauthenticated) {
            associate(ssoId, request.getSessionInternal(true));

            if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
                CatalinaLogger.AUTH_LOGGER.debug(" Reauthenticated cached principal '" +
                          request.getUserPrincipal().getName() +
                          "' with auth type '" +  request.getAuthType() + "'");
            }
        }

        return reauthenticated;
    }

    /**
     * Register an authenticated Principal and authentication type in our
     * request, in the current session (if there is one), and with our
     * SingleSignOn valve, if there is one.  Set the appropriate cookie
     * to be returned.
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are generating
     * @param principal The authenticated Principal to be registered
     * @param authType The authentication type to be registered
     * @param username Username used to authenticate (if any)
     * @param password Password used to authenticate (if any)
     */
    protected void register(Request request, HttpServletResponse response,
                            Principal principal, String authType,
                            String username, String password) {

        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled())
            CatalinaLogger.AUTH_LOGGER.debug("Authenticated '" + principal.getName() + "' with type '"
                + authType + "'");

        // Cache the authentication information in our request
        request.setAuthType(authType);
        request.setUserPrincipal(principal);

        Session session = request.getSessionInternal(false);
        if (session != null) {
            if (changeSessionIdOnAuthentication) {
                Manager manager = request.getContext().getManager();
                manager.changeSessionId(session, request.getRandom());
                request.changeSessionId(session.getId());
            }
        } else if (alwaysUseSession) {
            session = request.getSessionInternal(true);
        }

        // Cache the authentication information in our session, if any
        if (cache) {
            if (session != null) {
                session.setAuthType(authType);
                session.setPrincipal(principal);
                if (username != null)
                    session.setNote(Constants.SESS_USERNAME_NOTE, username);
                else
                    session.removeNote(Constants.SESS_USERNAME_NOTE);
                if (password != null)
                    session.setNote(Constants.SESS_PASSWORD_NOTE, password);
                else
                    session.removeNote(Constants.SESS_PASSWORD_NOTE);
            }
        }

        // Construct a cookie to be returned to the client
        if (sso == null)
            return;

        // Only create a new SSO entry if the SSO did not already set a note
        // for an existing entry (as it would do with subsequent requests
        // for DIGEST and SSL authenticated contexts)
        String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
        if (ssoId == null) {
            // Construct a cookie to be returned to the client
            ssoId = generateSessionId(request.getRandom());
            Cookie cookie = new Cookie(Constants.SINGLE_SIGN_ON_COOKIE, ssoId);
            cookie.setMaxAge(-1);
            cookie.setPath("/");

            // Bugzilla 41217
            cookie.setSecure(request.isSecure());

            if (sso.isCookieHttpOnly()) {
                cookie.setHttpOnly(true);
            }

            // Bugzilla 34724
            String ssoDomain = sso.getCookieDomain();
            if(ssoDomain != null) {
                cookie.setDomain(ssoDomain);
            }

            response.addCookie(cookie);

            // Register this principal with our SSO valve
            sso.register(ssoId, principal, authType, username, password);
            request.setNote(Constants.REQ_SSOID_NOTE, ssoId);

        } else {
            // Update the SSO session with the latest authentication data
            sso.update(ssoId, principal, authType, username, password);
        }

        // Fix for Bug 10040
        // Always associate a session with a new SSO reqistration.
        // SSO entries are only removed from the SSO registry map when
        // associated sessions are destroyed; if a new SSO entry is created
        // above for this request and the user never revisits the context, the
        // SSO entry will never be cleared if we don't associate the session
        if (session == null)
            session = request.getSessionInternal(true);
        sso.associate(ssoId, session);

    }

    /**
     * Register an authenticated Principal and authentication type in our
     * request, in the current session (if there is one), and with our
     * SingleSignOn valve, if there is one.  Set the appropriate cookie
     * to be returned.
     *
     * @param request The servlet request we are processing
     * @param response The servlet response we are generating
     * @param principal The authenticated Principal to be registered
     * @param authType The authentication type to be registered
     * @param username Username used to authenticate (if any)
     * @param password Password used to authenticate (if any)
     */
    protected void unregister(Request request, HttpServletResponse response) {

        // Remove the authentication information from our request
        request.setAuthType(null);
        request.setUserPrincipal(null);

        Session session = request.getSessionInternal(false);
        // Cache the authentication information in our session, if any
        if (cache && session != null) {
            session.setAuthType(null);
            session.setPrincipal(null);
            session.removeNote(Constants.SESS_USERNAME_NOTE);
            session.removeNote(Constants.SESS_PASSWORD_NOTE);
        }

        // Construct a cookie to be returned to the client
        if (sso == null)
            return;

        String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE);
        if (ssoId != null) {
            // Update the SSO session with the latest authentication data
            if (unregisterSsoOnLogout) {
                request.removeNote(Constants.REQ_SSOID_NOTE);
                sso.deregister(ssoId);
            } else {
                if (cache && session != null) {
                    sso.removeLogin(ssoId);
                }
            }
        }

    }

    // ------------------------------------------------------ Lifecycle Methods

    /**
     * Add a lifecycle event listener to this component.
     *
     * @param listener The listener to add
     */
    public void addLifecycleListener(LifecycleListener listener) {

        lifecycle.addLifecycleListener(listener);

    }

    /**
     * Get the lifecycle listeners associated with this lifecycle. If this
     * Lifecycle has no listeners registered, a zero-length array is returned.
     */
    public LifecycleListener[] findLifecycleListeners() {

        return lifecycle.findLifecycleListeners();

    }

    /**
     * Remove a lifecycle event listener from this component.
     *
     * @param listener The listener to remove
     */
    public void removeLifecycleListener(LifecycleListener listener) {

        lifecycle.removeLifecycleListener(listener);

    }

    /**
     * Prepare for the beginning of active use of the public methods of this
     * component.  This method should be called after configure(),
     * and before any of the public methods of the component are utilized.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents this component from being used
     */
    public void start() throws LifecycleException {

        // Validate and update our current component state
        if (started)
            throw new LifecycleException(MESSAGES.authenticatorAlreadyStarted());
        lifecycle.fireLifecycleEvent(START_EVENT, null);
        started = true;

        // Look up the SingleSignOn implementation in our request processing
        // path, if there is one
        Container parent = context.getParent();
        while ((sso == null) && (parent != null)) {
            if (!(parent instanceof Pipeline)) {
                parent = parent.getParent();
                continue;
            }
            Valve valves[] = ((Pipeline) parent).getValves();
            for (int i = 0; i < valves.length; i++) {
                if (valves[i] instanceof SingleSignOn) {
                    sso = (SingleSignOn) valves[i];
                    break;
                }
            }
            if (sso == null)
                parent = parent.getParent();
        }
        if (CatalinaLogger.AUTH_LOGGER.isDebugEnabled()) {
            if (sso != null)
                CatalinaLogger.AUTH_LOGGER.debug("Found SingleSignOn Valve at " + sso);
            else
                CatalinaLogger.AUTH_LOGGER.debug("No SingleSignOn Valve is present");
        }

    }

    /**
     * Gracefully terminate the active use of the public methods of this
     * component.  This method should be the last one called on a given
     * instance of this component.
     *
     * @exception LifecycleException if this component detects a fatal error
     *  that needs to be reported
     */
    public void stop() throws LifecycleException {

        // Validate and update our current component state
        if (!started)
            throw new LifecycleException(MESSAGES.authenticatorNotStarted());
        lifecycle.fireLifecycleEvent(STOP_EVENT, null);
        started = false;

        sso = null;

    }

}


text:
/**
 * This package contains the classes that implement the unit tests.
 */
package com.btmatthews.maven.plugins.inmemdb.test;


text:
messages_str = "/home/mike/catkin_ws/src/husky_msgs/msg/HuskyStatus.msg"
services_str = ""
pkg_name = "husky_msgs"
dependencies_str = "std_msgs"
langs = "gencpp;genlisp;genpy"
dep_include_paths_str = "husky_msgs;/home/mike/catkin_ws/src/husky_msgs/msg;std_msgs;/opt/ros/indigo/share/std_msgs/cmake/../msg"
PYTHON_EXECUTABLE = "/usr/bin/python"
package_has_static_sources = '' == 'TRUE'
genmsg_check_deps_script = "/opt/ros/indigo/share/genmsg/cmake/../../../lib/genmsg/genmsg_check_deps.py"


text:
from argparse import ArgumentParser
import ast
import datetime
import fnmatch
import os
import sys

from api_extractor import APIExtractor

def pseudo_relative_name(path, mark):
    """ Return the given path shorten until a directory name contains a
    given mark (i.e. matches a substring)."""
    short_rel_path = ''
    condition = True
    head = os.path.abspath(path)
    while condition:
        head, tail = os.path.split(head)
        condition = tail != '' and not fnmatch.fnmatch(tail, "*%s*" % mark)
        if short_rel_path:
            short_rel_path = os.path.join(tail, short_rel_path)
        else:
            short_rel_path = tail
    return short_rel_path

def conpaas_path_name(path):
    return pseudo_relative_name(path, "conpaas")

def indent_except_sections(text):
    """Indent text except if restructured text section definition lines."""
    ret_text = []
    previous_line = None
    for line in text.split('\n'):
        if len(set(line)) == 1 \
                and previous_line is not None \
                and len(line) >= len(previous_line) \
                and len(previous_line) > 1:
            ret_text.append(previous_line)  # un-indented section title
            ret_text.append(line)  # un-indented section adornment
            previous_line = None
        else:
            if previous_line is not None:
                ret_text.append('  ' + previous_line)  # indentation
            previous_line = line
    if previous_line is not None:
        ret_text.append('  ' + previous_line)
    return '\n'.join(ret_text)

def gen_functions_doc(functions, file_as_title=False):
    file_title = None
    functions_doc = []
    for func in functions:
        if file_as_title:
            basename = os.path.basename(func['source_file'])
            func_file, _ = os.path.splitext(basename)
            if func_file != file_title:
                file_title = func_file
                functions_doc.append('\n')
                functions_doc.append('-' * len(file_title))
                functions_doc.append('\n')
                functions_doc.append(file_title)
                functions_doc.append('\n')
                functions_doc.append('-' * len(file_title))
                functions_doc.append('\n')
        functions_doc.append('\n')
        func_doc = gen_func_doc(func)
        functions_doc.extend(func_doc)
    return functions_doc

def gen_func_doc(func):
    doc = []
    if len(func['names']) == 1:
        name, methods = func['names'][0]
        doc.append(name)
        doc.append('\n')
        doc.append('=' * len(name))
        doc.append('\n')
        doc.append('HTTP methods')
        doc.append('\n')
        doc.append('  %s' % methods)
        doc.append('\n')
    else:
        all_names = ''
        for name, methods in func['names']:
            all_names += name + " " + methods + " "
        doc.append(all_names)
        doc.append('\n')
        doc.append('-' * len(all_names))
        doc.append('\n')

    doc.append('Source file')
    doc.append('\n')
    doc.append('  %s' % conpaas_path_name(func['source_file']))
    doc.append('\n')
    if 'certificate' in func:
        doc.append('* ' + func['certificate'])
        doc.append('\n')
    doc.append('Description')
    doc.append('\n')
    #fun_doc = func['doc']
    fun_doc = indent_except_sections(func['doc'])
    #doc.append('\n  '.join(fun_doc.split('\n')))
    doc.append(fun_doc)
    doc.append('\n')
    return doc

def gen_classes_doc(classes):
    classes_doc = []
    for cpsclass in classes:
        classes_doc.append('\n')
        class_doc = gen_class_doc(cpsclass)
        classes_doc.extend(class_doc)
    return classes_doc

def gen_class_doc(cpsclass):
    class_doc = []
    if cpsclass['entries']:
        class_name = cpsclass['name']
        class_doc.append('-' * len(class_name))
        class_doc.append('\n')
        class_doc.append(class_name)
        class_doc.append('\n')
        class_doc.append('-' * len(class_name))
        class_doc.append('\n')
        class_doc.append('Source file')
        class_doc.append('\n')
        class_doc.append('  %s' % conpaas_path_name(cpsclass['source_file']))
        class_doc.append('\n')
        if cpsclass['extends']:
            class_doc.append('Extends')
            class_doc.append('\n')
            for extclass in cpsclass['extends']:
                class_doc.append('  %s' % extclass)
            class_doc.append('\n')
        functions_doc = gen_functions_doc(cpsclass['entries'])
        class_doc.extend(functions_doc)
    return class_doc

def gen_doc(visitor):
    doc = []
    if visitor.all_functions_doc:
        # public entries defined outside any class (case of ConPaaS director)
        functions_doc = gen_functions_doc(visitor.all_functions_doc,
                                          file_as_title=True)
        doc.extend(functions_doc)

    if visitor.classes_doc:
        # public entries defined inside classes (case of ConPaaS managers and agents)
        doc.extend(gen_classes_doc(visitor.classes_doc))

    return doc

def print_doc(visitor):
    doc = gen_doc(visitor)
    print ''.join(doc)

def print_title(root_dir, title):
    print "=" * len(title)
    print title
    print "=" * len(title)
    print
    print "Source code root directory: %s" % conpaas_path_name(root_dir)

def print_toc():
    print
    print '.. contents::'
    print

def print_date():
    print
    print 'This document was generated on %s' % datetime.date.today()
    print

def class_comparator():
    def compare(class1, class2):
        class1_name = class1['name']
        class2_name = class2['name']
        if class1_name in class2['extends']:
            return 1
        if class2_name in class1['extends']:
            return -1
        if class1_name < class2_name:
            return -1
        if class1_name > class2_name:
            return 1
        return 0
    return compare

def sort_entries(visitor):
    if visitor.all_functions_doc:
        entries = visitor.all_functions_doc
        entries = sorted(entries, key=lambda k: k['source_file'] + k['names'][0][0])
        visitor.all_functions_doc = entries
    if visitor.classes_doc:
        # sort classes
        sorted_classes = visitor.classes_doc
        sorted_classes = sorted(sorted_classes, cmp=class_comparator())
        visitor.classes_doc = sorted_classes
        # sort entries inside classes
        for class_doc in visitor.classes_doc:
            entries = class_doc['entries']
            entries = sorted(entries, key=lambda k: k['names'][0][0])
            class_doc['entries'] = entries

def get_source_files(root_dir):
    if not os.path.isdir(root_dir):
        raise Exception("Error: %s is not a readable directory." % root_dir)
    py_src_files = []
    for root, _dirnames, filenames in os.walk(root_dir):
        for filename in fnmatch.filter(filenames, '*.py'):
            py_src_files.append(os.path.join(root, filename))
    return py_src_files

def main():
    # Parse command line argument
    parser = ArgumentParser(description='Tool to extract ConPaaS HTTP APIs from source code')
    parser.add_argument('DIR', help='root directory of source code to parse')
    parser.add_argument('--title', default='ConPaaS API',
                        help='Title of the extracted API.')
    args = parser.parse_args(sys.argv[1:])
    root_dir = args.DIR

    py_src_files = get_source_files(root_dir)
    visitor = APIExtractor()
    for src_file in py_src_files:
        source_file = open(src_file)
        source = source_file.read()
        source_file.close()
        mod = ast.parse(source)
        visitor.source_file = src_file
        visitor.visit(mod)

    sort_entries(visitor)

    print_title(root_dir, args.title)
    print_date()
    print_toc()
    print_doc(visitor)

if __name__ == '__main__':
    main()


text:
package org.jboss.integration.fuse.karaf.itest.workitem;

import org.apache.commons.io.FileUtils;
import org.drools.core.process.instance.WorkItem;
import org.drools.core.process.instance.impl.DefaultWorkItemManager;
import org.drools.core.process.instance.impl.WorkItemImpl;
import org.jbpm.process.workitem.camel.CamelHandler;
import org.jbpm.process.workitem.camel.CamelHandlerFactory;
import org.jbpm.process.workitem.camel.request.RequestPayloadMapper;
import org.jbpm.process.workitem.camel.uri.FileURIMapper;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.api.runtime.process.WorkItemManager;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerClass;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.inject.Inject;
import org.apache.karaf.features.FeaturesService;

import org.jboss.integration.fuse.karaf.itest.KarafConfigUtil;
import org.ops4j.pax.exam.Configuration;

/**
 * Uploading a file via File endpoint using Camel in Karaf.
 */
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class CamelFileTest {

    private static File tempDir;
    private static File testDir;
    private static File testFile;

    private KieServices kieServices;

    private KieSession kieSession;

    @Inject
    FeaturesService fs;

    @Configuration
    public static Option[] configure() {
        return KarafConfigUtil.karafConfiguration();
    }

    @BeforeClass
    public static void initialize() {
        tempDir = new File(System.getProperty("java.io.tmpdir"));
        testDir = new File(tempDir, "test_dir");
        String fileName = "test_file_" + CamelFileTest.class.getName() + "_" + UUID.randomUUID().toString();
        testFile = new File(tempDir, fileName);
    }

    @AfterClass
    public static void clean() throws IOException {
        FileUtils.deleteDirectory(testDir);
    }

    @Before
    public void prepare() {
        this.kieServices = KieServices.Factory.get();
        final KieContainer kieContainer = this.kieServices.newKieClasspathContainer(this.getClass().getClassLoader());
        this.kieSession = kieContainer.newKieSession("camel-workitem-ksession");
        assertNotNull(this.kieSession);
    }

    @After
    public void cleanup() {
        if (this.kieSession != null) {
            this.kieSession.dispose();
        }
    }

    /**
     * Test with entire BPMN process.
     * @throws java.io.IOException
     */
    @Test
    public void testSingleFileProcess() throws IOException {
        final String testData = "test-data";

        CamelHandler handler = CamelHandlerFactory.fileHandler();
        kieSession.getWorkItemManager().registerWorkItemHandler("CamelFile", handler);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("payloadVar", testData);
        params.put("pathVar", tempDir.getAbsolutePath());
        params.put("fileNameVar", testFile.getName());

        ProcessInstance pi = kieSession.startProcess("camelFileProcess", params);

        ProcessInstance result = kieSession.getProcessInstance(pi.getId());
        assertNull(result);

        assertTrue(testFile.exists());

        String resultText = FileUtils.readFileToString(testFile);
        assertEquals(testData,resultText);
    }

    /**
     * File to upload has been specified by Camel header.
     *
     * @throws java.io.IOException */
    @Test
    public void testSingleFileWithHeaders() throws IOException {
        Set<String> headers = new HashSet<String>();
        headers.add("CamelFileName");
        CamelHandler handler = new CamelHandler(new FileURIMapper(), new RequestPayloadMapper("payload", headers));

        final String testData = "test-data";
        final WorkItem workItem = new WorkItemImpl();
        workItem.setParameter("path", tempDir.getAbsolutePath());
        workItem.setParameter("payload", testData);
        workItem.setParameter("CamelFileName", testFile.getName());

        WorkItemManager manager = new DefaultWorkItemManager(null);
        handler.executeWorkItem(workItem, manager);

        assertTrue(testFile.exists());

        String resultText = FileUtils.readFileToString(testFile);
        assertEquals(testData,resultText);
    }
}


text:
module Hipbot
  module Plugins
    class Help
      include Hipbot::Plugin

      desc 'lists all standard emoticons'
      on /^emoticons/ do
        reply ":-) :o :$ :( :-* :# :'( ;-) (embarrassed) :Z :p 8) O:) :-D (oops) :| (thumbsup) (thumbsdown) (allthethings) (android) (areyoukiddingme)" +
              " (arrington) (ashton) (awyeah) (badpokerface) (basket) (beer) (bumble) (bunny) (cadbury) (cake) (candycorn) (caruso) (cereal)" +
              " (challengeaccepted) (chewie) (chocobunny) (chompy) (chris) (coffee) (content) (cornelius) (dealwithit) (derp)" +
              " (disapproval) (dosequis) (ducreux) (dumb) (facepalm) (fap) (foreveralone) (freddie) (fry) (fu) (fuckyeah) (garret) (gates) (ghost) (goodnews)"
        # splitted for better formatting under Adobe AIR clients
        reply "(greenbeer) (gtfo) (haveaseat) (heart) (hipchat) (hipster) (huh) (ilied) (itsatrap) (jackie) (jobs) (kennypowers) (krang) (kwanzaa) (lincoln)" +
              " (lol) (lolwut) (megusta) (menorah) (notbad) (nothingtodohere) (ohcrap) (okay) (omg) (orly) (pbr) (pete) (philosoraptor) (pirate) (pokerface)" +
              " (poo) (present) (pumpkin) (rageguy) (rebeccablack) (reddit) (rudolph) (sadpanda) (sadtroll) (samuel) (santa) (scumbag) (seomoz) (shamrock)" +
              " (skyrim) (stare) (sweetjesus) (taft) (tree) (troll) (truestory) (turkey) (washington) (wat) (wtf) (yey) (yodawg) (yuno) (zoidberg) (zzz)"
      end

      desc 'generates help for all reactions'
      on /^help$/ do
        reactions_with_description = Hipbot.reactions.reject{ |reaction| reaction.desc.nil? }
        help = reactions_with_description.map do |reaction|
          "#{reaction.plugin_name}: #{reaction.readable_command} - #{reaction.desc}"
        end
        reply help.join("\n")
      end

      desc 'returns more info on given command'
      on /^help (.+)/ do |subject|
        reactions = Hipbot.reactions.select do |reaction|
          [reaction.plugin_name, reaction.readable_command, reaction.desc].any?{ |v| v =~ /#{subject}/i }
        end
        help = []
        reactions.each do |reaction|
          help << "#{reaction.plugin_name}: #{reaction.readable_command}"
          if !reaction.desc.nil?
            help << "  - #{reaction.desc}"
          end

          if reaction.to_private_message?
            help << "  - Private only"
          elsif reaction.in_any_room?
            help << "  - Room only"
          elsif reaction.rooms.any?
            help << "  - Only in: #{reaction.rooms.to_sentence}"
          else
            help << "  - All rooms and private messages"
          end

          if !reaction.options[:from].nil?
            help << "  - Only for: #{reaction.users.to_sentence}"
          else
            help << "  - From anybody"
          end

          if reaction.global?
            help << "  - Without mention"
          end
        end
        reply help.join("\n")
      end
    end
  end
end


text:
<?php

/**
 * Created by PhpStorm.
 * User: Krasen
 * Date: 16/5/18
 * Time: 15:59
 * Email: jhasheng@hotmail.com
 */

namespace Purple\Render;

use Symfony\Component\HttpFoundation\Response;

class JavascriptRender
{
    protected $content;

    /**
     * @var $response \Symfony\Component\HttpFoundation\Response
     */
    protected $response;

    protected $headStyle = [];

    protected $footerScript = [];

    public function __construct(Response $response)
    {
        $this->content  = $response->getContent();
        $this->response = $response;
    }

    public function renderPurpleButton()
    {
        $this->renderHead();
        $this->renderFooter();
    }

    protected function getHeadPos()
    {
        return stripos($this->content, '');
    }

    protected function getFootPos()
    {
        return stripos($this->content, '');
    }

    protected function renderHead()
    {
        if (false !== $this->getHeadPos()) {
            $styleHtml = "";
            foreach ($this->headStyle as $style) {
                $styleHtml .= sprintf('<link href="%s" rel="stylesheet" />', $style) . "\n";
            }
            $content   = substr($this->content, 0, $this->getHeadPos()) . $styleHtml . substr($this->content, $this->getHeadPos());
            $this->response->setContent($content);
        }
    }

    protected function renderFooter()
    {
        if (false !== $this->getFootPos()) {
            $scriptHtml = "";
            foreach ($this->footerScript as $script) {
                $scriptHtml .= sprintf('', $script) . "\n";
            }
            $content    = substr($this->content, 0, $this->getFootPos()) . $scriptHtml . substr($this->content, $this->getFootPos());
            $this->response->setContent($content);
        }
    }

}


text:
/**
 * @author adrian
 */
package anonymize;