text:
package com.tddrampup.databases;

import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;

import com.tddrampup.contentProviders.YellowContentProvider;
import com.tddrampup.models.Address;
import com.tddrampup.models.GeoCode;
import com.tddrampup.models.Listing;

import java.util.List;

/**
 * Created by: WX009-PC
 * on: 2/26/14.
 */
public class ListingsTableHelper {

    public static final String[] listingsTableAdapterProjection = {
        ListingsTable.COLUMN_ID,
        ListingsTable.COLUMN_NAME,
        ListingsTable.COLUMN_STREET,
        ListingsTable.COLUMN_CITY
    };

    public static final String[] listingsTableMapProjection = {
        ListingsTable.COLUMN_NAME,
        ListingsTable.COLUMN_LATITUDE,
        ListingsTable.COLUMN_LONGITUDE
    };

    public static final String[] listingsTableItemClickProjection = {
            ListingsTable.COLUMN_LISTING_ID,
            ListingsTable.COLUMN_MERCHANT_URL,
            ListingsTable.COLUMN_LONGITUDE
    };

    public static final String[] listingsTableDetailProjection = {
            ListingsTable.COLUMN_NAME,
            ListingsTable.COLUMN_STREET,
            ListingsTable.COLUMN_CITY,
            ListingsTable.COLUMN_MERCHANT_URL,
    };

    public static void addListings(List<Listing> listings, Context context) {
        Uri uri = YellowContentProvider.CONTENT_URI_LISTINGS;
        context.getContentResolver().delete(uri, null, null);

        for (Listing listing : listings) {
            addListing(listing, context);
        }
    }

    private static void addListing(Listing listing, Context context) { // TODO: do with SQL?
        ContentValues values = new ContentValues();
        String id = listing.getId();
        if (id != null) {
            values.put(ListingsTable.COLUMN_LISTING_ID, id);
        } else {
            values.put(ListingsTable.COLUMN_LISTING_ID, "");
        }

        String name = listing.getName();
        if (name != null) {
            values.put(ListingsTable.COLUMN_NAME, name);
        } else {
            values.put(ListingsTable.COLUMN_NAME, "");
        }

        final Address address = listing.getAddress();
        if (address != null) {
            String street = address.getStreet();
            if (street != null) {
                values.put(ListingsTable.COLUMN_STREET, street);
            } else {
                values.put(ListingsTable.COLUMN_STREET, "");
            }

            String city = address.getCity();
            if (city != null) {
                values.put(ListingsTable.COLUMN_CITY, city);
            } else {
                values.put(ListingsTable.COLUMN_CITY, "");
            }
        } else {
            values.put(ListingsTable.COLUMN_STREET, "");
            values.put(ListingsTable.COLUMN_CITY, "");
        }

        String url = listing.getMerchantUrl(); // Will be null
        if (url != null) {
            values.put(ListingsTable.COLUMN_MERCHANT_URL, url);
        } else {
            values.put(ListingsTable.COLUMN_MERCHANT_URL, "");
        }

        final GeoCode geoCode = listing.getGeoCode();
        if (geoCode != null) {
            String latitude = geoCode.getLatitude();
            if (latitude != null) {
                values.put(ListingsTable.COLUMN_LATITUDE, latitude);
            } else {
                values.put(ListingsTable.COLUMN_LATITUDE, "");
            }

            String longitude = geoCode.getLongitude();
            if (longitude != null) {
                values.put(ListingsTable.COLUMN_LONGITUDE, longitude);
            } else {
                values.put(ListingsTable.COLUMN_LONGITUDE, "");
            }
        } else {
            values.put(ListingsTable.COLUMN_LATITUDE, "");
            values.put(ListingsTable.COLUMN_LONGITUDE, "");
        }

        context.getContentResolver().insert(YellowContentProvider.CONTENT_URI_LISTINGS, values);
    }

    public static void updateListing(Listing listing, Context context) {
        String listingId = listing.getId();
        String merchantUrl = listing.getMerchantUrl();

        ContentValues values = new ContentValues();
        if (merchantUrl != null) {
            values.put(ListingsTable.COLUMN_MERCHANT_URL, merchantUrl);
        } else {
            values.put(ListingsTable.COLUMN_MERCHANT_URL, "");
        }
        context.getContentResolver().update(YellowContentProvider.CONTENT_URI_LISTINGS, values, ListingsTable.COLUMN_LISTING_ID + "=" + listingId, null);
    }
}


text:
import json
import logging
import signal
import time

import pystache
import redis

from celery.exceptions import SoftTimeLimitExceeded, TimeLimitExceeded
from celery.result import AsyncResult
from celery.utils.log import get_task_logger
from six import text_type
from redash import models, redis_connection, settings, statsd_client, utils
from redash.query_runner import InterruptException
from redash.utils import gen_query_hash
from redash.worker import celery
from redash.tasks.alerts import check_alerts_for_query

logger = get_task_logger(__name__)

def _job_lock_id(query_hash, data_source_id):
    return "query_hash_job:%s:%s" % (data_source_id, query_hash)

def _unlock(query_hash, data_source_id):
    redis_connection.delete(_job_lock_id(query_hash, data_source_id))

# TODO:
# There is some duplication between this class and QueryTask, but I wanted to implement the monitoring features without
# much changes to the existing code, so ended up creating another object. In the future we can merge them.
class QueryTaskTracker(object):
    DONE_LIST = 'query_task_trackers:done'
    WAITING_LIST = 'query_task_trackers:waiting'
    IN_PROGRESS_LIST = 'query_task_trackers:in_progress'
    ALL_LISTS = (DONE_LIST, WAITING_LIST, IN_PROGRESS_LIST)

    def __init__(self, data):
        self.data = data

    @classmethod
    def create(cls, task_id, state, query_hash, data_source_id, scheduled, metadata):
        data = dict(task_id=task_id, state=state,
                    query_hash=query_hash, data_source_id=data_source_id,
                    scheduled=scheduled,
                    username=metadata.get('Username', 'unknown'),
                    query_id=metadata.get('Query ID', 'unknown'),
                    retries=0,
                    scheduled_retries=0,
                    created_at=time.time(),
                    started_at=None,
                    run_time=None)

        return cls(data)

    def save(self, connection=None):
        if connection is None:
            connection = redis_connection

        self.data['updated_at'] = time.time()
        key_name = self._key_name(self.data['task_id'])
        connection.set(key_name, utils.json_dumps(self.data))
        connection.zadd(self._get_list(), time.time(), key_name)

        for l in self.ALL_LISTS:
            if l != self._get_list():
                connection.zrem(l, key_name)

    # TOOD: this is not thread/concurrency safe. In current code this is not an issue, but better to fix this.
    def update(self, **kwargs):
        self.data.update(kwargs)
        self.save()

    @staticmethod
    def _key_name(task_id):
        return 'query_task_tracker:{}'.format(task_id)

    def _get_list(self):
        if self.state in ('finished', 'failed', 'cancelled'):
            return self.DONE_LIST

        if self.state in ('created'):
            return self.WAITING_LIST

        return self.IN_PROGRESS_LIST

    @classmethod
    def get_by_task_id(cls, task_id, connection=None):
        if connection is None:
            connection = redis_connection

        key_name = cls._key_name(task_id)
        data = connection.get(key_name)
        return cls.create_from_data(data)

    @classmethod
    def create_from_data(cls, data):
        if data:
            data = json.loads(data)
            return cls(data)

        return None

    @classmethod
    def all(cls, list_name, offset=0, limit=-1):
        if limit != -1:
            limit -= 1

        if offset != 0:
            offset -= 1

        ids = redis_connection.zrevrange(list_name, offset, limit)
        pipe = redis_connection.pipeline()
        for id in ids:
            pipe.get(id)

        tasks = [cls.create_from_data(data) for data in pipe.execute()]
        return tasks

    @classmethod
    def prune(cls, list_name, keep_count, max_keys=100):
        count = redis_connection.zcard(list_name)
        if count <= keep_count:
            return 0

        remove_count = min(max_keys, count - keep_count)
        keys = redis_connection.zrange(list_name, 0, remove_count - 1)
        redis_connection.delete(*keys)
        redis_connection.zremrangebyrank(list_name, 0, remove_count - 1)
        return remove_count

    def __getattr__(self, item):
        return self.data[item]

    def __contains__(self, item):
        return item in self.data

class QueryTask(object):
    # TODO: this is mapping to the old Job class statuses. Need to update the client side and remove this
    STATUSES = {
        'PENDING': 1,
        'STARTED': 2,
        'SUCCESS': 3,
        'FAILURE': 4,
        'REVOKED': 4
    }

    def __init__(self, job_id=None, async_result=None):
        if async_result:
            self._async_result = async_result
        else:
            self._async_result = AsyncResult(job_id, app=celery)

    @property
    def id(self):
        return self._async_result.id

    def to_dict(self):
        task_info = self._async_result._get_task_meta()
        result, task_status = task_info['result'], task_info['status']
        if task_status == 'STARTED':
            updated_at = result.get('start_time', 0)
        else:
            updated_at = 0

        status = self.STATUSES[task_status]

        if isinstance(result, (TimeLimitExceeded, SoftTimeLimitExceeded)):
            error = "Query exceeded Redash query execution time limit."
            status = 4
        elif isinstance(result, Exception):
            error = result.message
            status = 4
        elif task_status == 'REVOKED':
            error = 'Query execution cancelled.'
        else:
            error = ''

        if task_status == 'SUCCESS' and not error:
            query_result_id = result
        else:
            query_result_id = None

        return {
            'id': self._async_result.id,
            'updated_at': updated_at,
            'status': status,
            'error': error,
            'query_result_id': query_result_id,
        }

    @property
    def is_cancelled(self):
        return self._async_result.status == 'REVOKED'

    @property
    def celery_status(self):
        return self._async_result.status

    def ready(self):
        return self._async_result.ready()

    def cancel(self):
        return self._async_result.revoke(terminate=True, signal='SIGINT')

def enqueue_query(query, data_source, user_id, scheduled_query=None, metadata={}):
    query_hash = gen_query_hash(query)
    logging.info("Inserting job for %s with metadata=%s", query_hash, metadata)
    try_count = 0
    job = None

    while try_count < 5:
        try_count += 1

        pipe = redis_connection.pipeline()
        try:
            pipe.watch(_job_lock_id(query_hash, data_source.id))
            job_id = pipe.get(_job_lock_id(query_hash, data_source.id))
            if job_id:
                logging.info("[%s] Found existing job: %s", query_hash, job_id)

                job = QueryTask(job_id=job_id)

                if job.ready():
                    logging.info("[%s] job found is ready (%s), removing lock", query_hash, job.celery_status)
                    redis_connection.delete(_job_lock_id(query_hash, data_source.id))
                    job = None

            if not job:
                pipe.multi()

                time_limit = None

                if scheduled_query:
                    queue_name = data_source.scheduled_queue_name
                    scheduled_query_id = scheduled_query.id
                else:
                    queue_name = data_source.queue_name
                    scheduled_query_id = None
                    time_limit = settings.ADHOC_QUERY_TIME_LIMIT

                result = execute_query.apply_async(args=(query, data_source.id, metadata, user_id, scheduled_query_id),
                                                   queue=queue_name,
                                                   time_limit=time_limit)
                job = QueryTask(async_result=result)
                tracker = QueryTaskTracker.create(
                    result.id, 'created', query_hash, data_source.id,
                    scheduled_query is not None, metadata)
                tracker.save(connection=pipe)

                logging.info("[%s] Created new job: %s", query_hash, job.id)
                pipe.set(_job_lock_id(query_hash, data_source.id), job.id, settings.JOB_EXPIRY_TIME)
                pipe.execute()
            break

        except redis.WatchError:
            continue

    if not job:
        logging.error("[Manager][%s] Failed adding job for query.", query_hash)

    return job

@celery.task(name="redash.tasks.refresh_queries")
def refresh_queries():
    logger.info("Refreshing queries...")

    outdated_queries_count = 0
    query_ids = []

    with statsd_client.timer('manager.outdated_queries_lookup'):
        for query in models.Query.outdated_queries():
            if settings.FEATURE_DISABLE_REFRESH_QUERIES:
                logging.info("Disabled refresh queries.")
            elif query.org.is_disabled:
                logging.info("Skipping refresh of %s because org is disabled.", query.id)
            elif query.data_source is None:
                logging.info("Skipping refresh of %s because the datasource is none.", query.id)
            elif query.data_source.paused:
                logging.info("Skipping refresh of %s because datasource - %s is paused (%s).", query.id, query.data_source.name, query.data_source.pause_reason)
            else:
                if query.options and len(query.options.get('parameters', [])) > 0:
                    query_params = {p['name']: p.get('value')
                                    for p in query.options['parameters']}
                    query_text = pystache.render(query.query_text, query_params)
                else:
                    query_text = query.query_text

                enqueue_query(query_text, query.data_source, query.user_id,
                              scheduled_query=query,
                              metadata={'Query ID': query.id, 'Username': 'Scheduled'})

                query_ids.append(query.id)
                outdated_queries_count += 1

    statsd_client.gauge('manager.outdated_queries', outdated_queries_count)

    logger.info("Done refreshing queries. Found %d outdated queries: %s" % (outdated_queries_count, query_ids))

    status = redis_connection.hgetall('redash:status')
    now = time.time()

    redis_connection.hmset('redash:status', {
        'outdated_queries_count': outdated_queries_count,
        'last_refresh_at': now,
        'query_ids': json.dumps(query_ids)
    })

    statsd_client.gauge('manager.seconds_since_refresh', now - float(status.get('last_refresh_at', now)))

@celery.task(name="redash.tasks.cleanup_tasks")
def cleanup_tasks():
    in_progress = QueryTaskTracker.all(QueryTaskTracker.IN_PROGRESS_LIST)
    for tracker in in_progress:
        result = AsyncResult(tracker.task_id)

        if result.ready():
            logging.info("in progress tracker %s finished", tracker.query_hash)
            _unlock(tracker.query_hash, tracker.data_source_id)
            tracker.update(state='finished')

    waiting = QueryTaskTracker.all(QueryTaskTracker.WAITING_LIST)
    for tracker in waiting:
        result = AsyncResult(tracker.task_id)

        if result.ready():
            logging.info("waiting tracker %s finished", tracker.query_hash)
            _unlock(tracker.query_hash, tracker.data_source_id)
            tracker.update(state='finished')

    # Maintain constant size of the finished tasks list:
    removed = 1000
    while removed > 0:
        removed = QueryTaskTracker.prune(QueryTaskTracker.DONE_LIST, 1000)

@celery.task(name="redash.tasks.cleanup_query_results")
def cleanup_query_results():
    """
    Job to cleanup unused query results -- such that no query links to them anymore, and older than
    settings.QUERY_RESULTS_MAX_AGE (a week by default, so it's less likely to be open in someone's browser and be used).

    Each time the job deletes only settings.QUERY_RESULTS_CLEANUP_COUNT (100 by default) query results so it won't choke
    the database in case of many such results.
    """

    logging.info("Running query results clean up (removing maximum of %d unused results, that are %d days old or more)",
                 settings.QUERY_RESULTS_CLEANUP_COUNT, settings.QUERY_RESULTS_CLEANUP_MAX_AGE)

    unused_query_results = models.QueryResult.unused(settings.QUERY_RESULTS_CLEANUP_MAX_AGE).limit(settings.QUERY_RESULTS_CLEANUP_COUNT)
    deleted_count = models.QueryResult.query.filter(
        models.QueryResult.id.in_(unused_query_results.subquery())
    ).delete(synchronize_session=False)
    models.db.session.commit()
    logger.info("Deleted %d unused query results.", deleted_count)

@celery.task(name="redash.tasks.refresh_schema", time_limit=90, soft_time_limit=60)
def refresh_schema(data_source_id):
    ds = models.DataSource.get_by_id(data_source_id)
    logger.info(u"task=refresh_schema state=start ds_id=%s", ds.id)
    start_time = time.time()
    try:
        ds.get_schema(refresh=True)
        logger.info(u"task=refresh_schema state=finished ds_id=%s runtime=%.2f", ds.id, time.time() - start_time)
        statsd_client.incr('refresh_schema.success')
    except SoftTimeLimitExceeded:
        logger.info(u"task=refresh_schema state=timeout ds_id=%s runtime=%.2f", ds.id, time.time() - start_time)
        statsd_client.incr('refresh_schema.timeout')
    except Exception:
        logger.warning(u"Failed refreshing schema for the data source: %s", ds.name, exc_info=1)
        statsd_client.incr('refresh_schema.error')
        logger.info(u"task=refresh_schema state=failed ds_id=%s runtime=%.2f", ds.id, time.time() - start_time)

@celery.task(name="redash.tasks.refresh_schemas")
def refresh_schemas():
    """
    Refreshes the data sources schemas.
    """
    blacklist = [int(ds_id) for ds_id in redis_connection.smembers('data_sources:schema:blacklist') if ds_id]
    global_start_time = time.time()

    logger.info(u"task=refresh_schemas state=start")

    for ds in models.DataSource.query:
        if ds.paused:
            logger.info(u"task=refresh_schema state=skip ds_id=%s reason=paused(%s)", ds.id, ds.pause_reason)
        elif ds.id in blacklist:
            logger.info(u"task=refresh_schema state=skip ds_id=%s reason=blacklist", ds.id)
        elif ds.org.is_disabled:
            logger.info(u"task=refresh_schema state=skip ds_id=%s reason=org_disabled", ds.id)
        else:
            refresh_schema.apply_async(args=(ds.id,), queue="schemas")

    logger.info(u"task=refresh_schemas state=finish total_runtime=%.2f", time.time() - global_start_time)

def signal_handler(*args):
    raise InterruptException

class QueryExecutionError(Exception):
    pass

# We could have created this as a celery.Task derived class, and act as the task itself. But this might result in weird
# issues as the task class created once per process, so decided to have a plain object instead.
class QueryExecutor(object):
    def __init__(self, task, query, data_source_id, user_id, metadata,
                 scheduled_query):
        self.task = task
        self.query = query
        self.data_source_id = data_source_id
        self.metadata = metadata
        self.data_source = self._load_data_source()
        if user_id is not None:
            self.user = models.User.query.get(user_id)
        else:
            self.user = None
        # Close DB connection to prevent holding a connection for a long time while the query is executing.
        models.db.session.close()
        self.query_hash = gen_query_hash(self.query)
        self.scheduled_query = scheduled_query
        # Load existing tracker or create a new one if the job was created before code update:
        self.tracker = (
            QueryTaskTracker.get_by_task_id(task.request.id) or
            QueryTaskTracker.create(
                task.request.id,
                'created',
                self.query_hash,
                self.data_source_id,
                False,
                metadata
            )
        )
        if self.tracker.scheduled:
            models.scheduled_queries_executions.update(self.tracker.query_id)

    def run(self):
        signal.signal(signal.SIGINT, signal_handler)
        self.tracker.update(started_at=time.time(), state='started')

        logger.debug("Executing query:\n%s", self.query)
        self._log_progress('executing_query')

        query_runner = self.data_source.query_runner
        annotated_query = self._annotate_query(query_runner)

        try:
            data, error = query_runner.run_query(annotated_query, self.user)
        except Exception as e:
            error = text_type(e)
            data = None
            logging.warning('Unexpected error while running query:', exc_info=1)

        run_time = time.time() - self.tracker.started_at
        self.tracker.update(error=error, run_time=run_time, state='saving_results')

        logger.info(u"task=execute_query query_hash=%s data_length=%s error=[%s]", self.query_hash, data and len(data), error)

        _unlock(self.query_hash, self.data_source.id)

        if error:
            self.tracker.update(state='failed')
            result = QueryExecutionError(error)
            if self.scheduled_query is not None:
                self.scheduled_query = models.db.session.merge(self.scheduled_query, load=False)
                self.scheduled_query.schedule_failures += 1
                models.db.session.add(self.scheduled_query)
            models.db.session.commit()
            raise result
        else:
            if (self.scheduled_query and self.scheduled_query.schedule_failures > 0):
                self.scheduled_query = models.db.session.merge(self.scheduled_query, load=False)
                self.scheduled_query.schedule_failures = 0
                models.db.session.add(self.scheduled_query)
            query_result, updated_query_ids = models.QueryResult.store_result(
                self.data_source.org_id, self.data_source,
                self.query_hash, self.query, data,
                run_time, utils.utcnow())
            models.db.session.commit()  # make sure that alert sees the latest query result
            self._log_progress('checking_alerts')
            for query_id in updated_query_ids:
                check_alerts_for_query.delay(query_id)
            self._log_progress('finished')

            result = query_result.id
            models.db.session.commit()
            return result

    def _annotate_query(self, query_runner):
        if query_runner.annotate_query():
            self.metadata['Task ID'] = self.task.request.id
            self.metadata['Query Hash'] = self.query_hash
            self.metadata['Queue'] = self.task.request.delivery_info['routing_key']

            annotation = u", ".join([u"{}: {}".format(k, v) for k, v in self.metadata.iteritems()])
            annotated_query = u"/* {} */ {}".format(annotation, self.query)
        else:
            annotated_query = self.query
        return annotated_query

    def _log_progress(self, state):
        logger.info(
            u"task=execute_query state=%s query_hash=%s type=%s ds_id=%d  "
            "task_id=%s queue=%s query_id=%s username=%s",
            state, self.query_hash, self.data_source.type, self.data_source.id,
            self.task.request.id,
            self.task.request.delivery_info['routing_key'],
            self.metadata.get('Query ID', 'unknown'),
            self.metadata.get('Username', 'unknown'))
        self.tracker.update(state=state)

    def _load_data_source(self):
        logger.info("task=execute_query state=load_ds ds_id=%d", self.data_source_id)
        return models.DataSource.query.get(self.data_source_id)

# user_id is added last as a keyword argument for backward compatability -- to support executing previously submitted
# jobs before the upgrade to this version.
@celery.task(name="redash.tasks.execute_query", bind=True, track_started=True)
def execute_query(self, query, data_source_id, metadata, user_id=None,
                  scheduled_query_id=None):
    if scheduled_query_id is not None:
        scheduled_query = models.Query.query.get(scheduled_query_id)
    else:
        scheduled_query = None
    return QueryExecutor(self, query, data_source_id, user_id, metadata,
                         scheduled_query).run()

redpajama_set_name: RedPajamaGithub


text:
package org.springframework.security.ldap.userdetails;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.ldap.SpringSecurityLdapTemplate;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.util.Assert;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.naming.directory.SearchControls;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * The default strategy for obtaining user role information from the directory.
 *

 * It obtains roles by performing a search for "groups" the user is a member of.
 *

 * A typical group search scenario would be where each group/role is specified using the <tt>groupOfNames</tt>
 * (or <tt>groupOfUniqueNames</tt>) LDAP objectClass and the user's DN is listed in the <tt>member</tt> (or
 * <tt>uniqueMember</tt>) attribute to indicate that they should be assigned that role. The following LDIF sample has
 * the groups stored under the DN <tt>ou=groups,dc=springframework,dc=org</tt> and a group called "developers" with
 * "ben" and "luke" as members:
 *

 * dn: ou=groups,dc=springframework,dc=org
 * objectClass: top
 * objectClass: organizationalUnit
 * ou: groups
 *
 * dn: cn=developers,ou=groups,dc=springframework,dc=org
 * objectClass: groupOfNames
 * objectClass: top
 * cn: developers
 * description: Spring Security Developers
 * member: uid=ben,ou=people,dc=springframework,dc=org
 * member: uid=luke,ou=people,dc=springframework,dc=org
 * ou: developer
 *

 *

 * The group search is performed within a DN specified by the <tt>groupSearchBase</tt> property, which should
 * be relative to the root DN of its <tt>InitialDirContextFactory</tt>. If the search base is null, group searching is
 * disabled. The filter used in the search is defined by the <tt>groupSearchFilter</tt> property, with the filter
 * argument {0} being the full DN of the user. You can also optionally use the parameter {1}, which will be substituted
 * with the username. You can also specify which attribute defines the role name by setting
 * the <tt>groupRoleAttribute</tt> property (the default is "cn").
 *

 * The configuration below shows how the group search might be performed with the above schema.
 *

 * <bean id="ldapAuthoritiesPopulator"
 *       class="org.springframework.security.authentication.ldap.populator.DefaultLdapAuthoritiesPopulator">
 *   <constructor-arg ref="contextSource"/>
 *   <constructor-arg value="ou=groups"/>
 *   <property name="groupRoleAttribute" value="ou"/>
 * <!-- the following properties are shown with their default values -->
 *   <property name="searchSubTree" value="false"/>
 *   <property name="rolePrefix" value="ROLE_"/>
 *   <property name="convertToUpperCase" value="true"/>
 * </bean>
 *

 * A search for roles for user "uid=ben,ou=people,dc=springframework,dc=org" would return the single granted authority
 * "ROLE_DEVELOPER".
 *

 * The single-level search is performed by default. Setting the <tt>searchSubTree</tt> property to true will enable
 * a search of the entire subtree under <tt>groupSearchBase</tt>.
 *
 * @author Luke Taylor
 */
public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator {
    //~ Static fields/initializers =====================================================================================

    private static final Log logger = LogFactory.getLog(DefaultLdapAuthoritiesPopulator.class);

    //~ Instance fields ================================================================================================

    /**
     * A default role which will be assigned to all authenticated users if set
     */
    private GrantedAuthority defaultRole;

    private SpringSecurityLdapTemplate ldapTemplate;

    /**
     * Controls used to determine whether group searches should be performed over the full sub-tree from the
     * base DN. Modified by searchSubTree property
     */
    private SearchControls searchControls = new SearchControls();

    /**
     * The ID of the attribute which contains the role name for a group
     */
    private String groupRoleAttribute = "cn";

    /**
     * The base DN from which the search for group membership should be performed
     */
    private String groupSearchBase;

    /**
     * The pattern to be used for the user search. {0} is the user's DN
     */
    private String groupSearchFilter = "(member={0})";

    /**
     * Attributes of the User's LDAP Object that contain role name information.
     */

//    private String[] userRoleAttributes = null;
    private String rolePrefix = "ROLE_";
    private boolean convertToUpperCase = true;

    //~ Constructors ===================================================================================================

    /**
     * Constructor for group search scenarios. <tt>userRoleAttributes</tt> may still be
     * set as a property.
     *
     * @param contextSource supplies the contexts used to search for user roles.
     * @param groupSearchBase          if this is an empty string the search will be performed from the root DN of the
     *                                 context factory.
     */
    public DefaultLdapAuthoritiesPopulator(ContextSource contextSource, String groupSearchBase) {
        Assert.notNull(contextSource, "contextSource must not be null");
        ldapTemplate = new SpringSecurityLdapTemplate(contextSource);
        ldapTemplate.setSearchControls(searchControls);
        setGroupSearchBase(groupSearchBase);
    }

    //~ Methods ========================================================================================================

    /**
     * This method should be overridden if required to obtain any additional
     * roles for the given user (on top of those obtained from the standard
     * search implemented by this class).
     *
     * @param user the context representing the user who's roles are required
     * @return the extra roles which will be merged with those returned by the group search
     */

    protected Set<GrantedAuthority> getAdditionalRoles(DirContextOperations user, String username) {
        return null;
    }

    /**
     * Obtains the authorities for the user who's directory entry is represented by
     * the supplied LdapUserDetails object.
     *
     * @param user the user who's authorities are required
     * @return the set of roles granted to the user.
     */
    public final Collection<GrantedAuthority> getGrantedAuthorities(DirContextOperations user, String username) {
        String userDn = user.getNameInNamespace();

        if (logger.isDebugEnabled()) {
            logger.debug("Getting authorities for user " + userDn);
        }

        Set<GrantedAuthority> roles = getGroupMembershipRoles(userDn, username);

        Set<GrantedAuthority> extraRoles = getAdditionalRoles(user, username);

        if (extraRoles != null) {
            roles.addAll(extraRoles);
        }

        if (defaultRole != null) {
            roles.add(defaultRole);
        }

        List<GrantedAuthority> result = new ArrayList<GrantedAuthority>(roles.size());
        result.addAll(roles);

        return result;
    }

    public Set<GrantedAuthority> getGroupMembershipRoles(String userDn, String username) {
        if (getGroupSearchBase() == null) {
            return Collections.emptySet();
        }

        Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();

        if (logger.isDebugEnabled()) {
            logger.debug("Searching for roles for user '" + username + "', DN = " + "'" + userDn + "', with filter "
                    + groupSearchFilter + " in search base '" + getGroupSearchBase() + "'");
        }

        Set<String> userRoles = ldapTemplate.searchForSingleAttributeValues(getGroupSearchBase(), groupSearchFilter,
                new String[]{userDn, username}, groupRoleAttribute);

        if (logger.isDebugEnabled()) {
            logger.debug("Roles from search: " + userRoles);
        }

        for (String role : userRoles) {

            if (convertToUpperCase) {
                role = role.toUpperCase();
            }

            authorities.add(new GrantedAuthorityImpl(rolePrefix + role));
        }

        return authorities;
    }

    protected ContextSource getContextSource() {
        return ldapTemplate.getContextSource();
    }

    /**
     * Set the group search base (name to search under)
     *
     * @param groupSearchBase if this is an empty string the search will be performed from the root DN of the context
     *                        factory.
     */
    private void setGroupSearchBase(String groupSearchBase) {
        Assert.notNull(groupSearchBase, "The groupSearchBase (name to search under), must not be null.");
        this.groupSearchBase = groupSearchBase;
        if (groupSearchBase.length() == 0) {
            logger.info("groupSearchBase is empty. Searches will be performed from the context source base");
        }
    }

    protected String getGroupSearchBase() {
        return groupSearchBase;
    }

    public void setConvertToUpperCase(boolean convertToUpperCase) {
        this.convertToUpperCase = convertToUpperCase;
    }

    /**
     * The default role which will be assigned to all users.
     *
     * @param defaultRole the role name, including any desired prefix.
     */
    public void setDefaultRole(String defaultRole) {
        Assert.notNull(defaultRole, "The defaultRole property cannot be set to null");
        this.defaultRole = new GrantedAuthorityImpl(defaultRole);
    }

    public void setGroupRoleAttribute(String groupRoleAttribute) {
        Assert.notNull(groupRoleAttribute, "groupRoleAttribute must not be null");
        this.groupRoleAttribute = groupRoleAttribute;
    }

    public void setGroupSearchFilter(String groupSearchFilter) {
        Assert.notNull(groupSearchFilter, "groupSearchFilter must not be null");
        this.groupSearchFilter = groupSearchFilter;
    }

    /**
     * Sets the prefix which will be prepended to the values loaded from the directory.
     * Defaults to "ROLE_" for compatibility with <tt>RoleVoter/tt>.
     */
    public void setRolePrefix(String rolePrefix) {
        Assert.notNull(rolePrefix, "rolePrefix must not be null");
        this.rolePrefix = rolePrefix;
    }

    /**
     * If set to true, a subtree scope search will be performed. If false a single-level search is used.
     *
     * @param searchSubtree set to true to enable searching of the entire tree below the <tt>groupSearchBase</tt>.
     */
    public void setSearchSubtree(boolean searchSubtree) {
        int searchScope = searchSubtree ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE;
        searchControls.setSearchScope(searchScope);
    }

    /**
     * Sets the corresponding property on the underlying template, avoiding specific issues with Active Directory.
     *
     *   @see LdapTemplate#setIgnoreNameNotFoundException(boolean)
     */
    public void setIgnorePartialResultException(boolean ignore) {
        ldapTemplate.setIgnorePartialResultException(ignore);
    }
}


text:
<?php

namespace nord\yii\imagemanager\providers\cloudinary;

use Imagine\Filter\Transformation;
use yii\base\Component;

class Parameters extends Component
{
    const RESOURCE_TYPE_IMAGE = 'image';
    const RESOURCE_TYPE_RAW = 'raw';
    const RESOURCE_TYPE_AUTO = 'auto';

    const TYPE_UPLOAD = 'upload';
    const TYPE_PRIVATE = 'private';
    const TYPE_AUTHENTICATED = 'authenticated';

    const RAW_CONVERT_ASPOSE = 'aspose';

    const CATEGORIZATION_REKOGNITION_SCENE = 'rekognition_scene';

    const DETECTION_REKOGNITION_FACE = 'rekognition_face';

    const MODERATION_MANUAL = 'manual';
    const MODERATION_WEBPURIFY = 'webpurify';

    /**
     * @var string
     */
    public $publicId;
    /**
     * @var string
     */
    public $resourceType;
    /**
     * @var string
     */
    public $type;
    /**
     * @var array
     */
    public $tags;
    /**
     * @var array
     */
    public $context;
    /**
     * @var Transformation|array
     */
    public $transformation;
    /**
     * @var string
     */
    public $format;
    /**
     * @var string|array
     */
    public $allowedFormats;
    /**
     * @var array
     */
    public $eager;
    /**
     * @var boolean
     */
    public $eagerAsync;
    /**
     * @var string
     */
    public $proxy;
    /**
     * @var string|array
     */
    public $headers;
    /**
     * @var string
     */
    public $callback;
    /**
     * @var string
     */
    public $notificationUrl;
    /**
     * @var string
     */
    public $eagerNotificationUrl;
    /**
     * @var boolean
     */
    public $backup;
    /**
     * @var boolean
     */
    public $returnDeleteToken;
    /**
     * @var boolean
     */
    public $faces;
    /**
     * @var boolean
     */
    public $exif;
    /**
     * @var boolean
     */
    public $colors;
    /**
     * @var boolean
     */
    public $imageMetadata;
    /**
     * @var boolean
     */
    public $pHash;
    /**
     * @var boolean
     */
    public $invalidate;
    /**
     * @var boolean
     */
    public $useFilename;
    /**
     * @var boolean
     */
    public $uniqueFilename;
    /**
     * @var string
     */
    public $folder;
    /**
     * @var boolean
     */
    public $overwrite;
    /**
     * @var boolean
     */
    public $discardOriginalFilename;
    /**
     * @var string
     */
    public $faceCoordinates;
    /**
     * @var string
     */
    public $customCoordinates;
    /**
     * @var string
     */
    public $rawConvert;
    /**
     * @var string
     */
    public $categorization;
    /**
     * @var float
     */
    public $autoTagging;
    /**
     * @var string
     */
    public $detection;
    /**
     * @var string
     */
    public $moderation;
    /**
     * @var string
     */
    public $uploadPreset;
    /**
     * @var array
     */
    public $html;

    public function toArray()
    {
        $array = [];
        foreach (array_keys(get_object_vars($this)) as $property) {
            if ($this->$property === null) {
                continue;
            }
            switch ($property) {
                case 'transformation':
                    if ($this->transformation instanceof Transformation) {
                        $this->transformation = $this->transformation->toArray();
                    }
                    $array[$property] = $this->transformation;
                    break;
                case 'allowedFormats':
                    $array['allowed_formats'] = implode(',', $this->allowedFormats);
                    break;
                default:
                    $array[$this->camelCaseToUnderscore($property)] = $this->$property;
                    break;
            }
        }
        return $array;
    }

    /**
     * @param string $string
     * @return string
     */
    protected function camelCaseToUnderscore($string)
    {
        return strtolower(preg_replace('/(?<!^)([A-Z])/', '_$1', $string));
    }
}


text:
package uk.gov.hmrc.crypto

import com.typesafe.config.ConfigFactory
import org.mockito.MockitoSugar
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

import java.util.Base64
import scala.collection.JavaConverters._

@annotation.nowarn("msg=deprecated")
class CompositeOneWayCryptoSpec extends AnyWordSpecLike with Matchers with MockitoSugar {

  private val baseConfigKey = "crypto.spec"

  private object CurrentKey {
    val configKey        = baseConfigKey + ".key"
    val encryptionKey    = Base64.getEncoder.encodeToString(Array[Byte](0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15))
    val aeadText         = Base64.getEncoder.encodeToString("some additional text".getBytes)
    val plainMessage     = "this is my message"
    val encryptedMessage = "up/76On5j54pAjzqZR1mqM5E28skTl8Aw0GkKi+zjkk="
  }

  "A correctly constructed one way encrypter" should {
    "encrypt and verify a password" in {
      val config = ConfigFactory.parseMap(
        Map(
          CurrentKey.configKey -> CurrentKey.encryptionKey
        ).asJava
      )
      val cryptor = new CompositeOneWayCrypto(baseConfigKey, config)

      val encrypted = cryptor.hash(PlainText("myPassword"))

      cryptor.verify(PlainText("myPassword"), encrypted) should be(true)
    }
  }

  "Constructing a one way encrypter without current or previous keys" should {
    "throw a SecurityException on construction" in {
      intercept[SecurityException] {
        new CompositeOneWayCrypto(baseConfigKey, ConfigFactory.empty)
      }
    }
  }
}


text:
'use strict';

require('configureForRelayOSS');

jest
  .unmock('GraphQLRange')
  .unmock('GraphQLSegment');

const GraphQLMutatorConstants = require('GraphQLMutatorConstants');
const Relay = require('Relay');
const RelayConnectionInterface = require('RelayConnectionInterface');
const RelayMockCacheManager = require('RelayMockCacheManager');
const RelayMutationType = require('RelayMutationType');
const RelayStoreData = require('RelayStoreData');
const RelayTestUtils = require('RelayTestUtils');

const transformRelayQueryPayload = require('transformRelayQueryPayload');

describe('RelayStoreData', function() {
  let cacheManager;
  let storeData;

  const {getNode} = RelayTestUtils;
  let CLIENT_MUTATION_ID, HAS_NEXT_PAGE, HAS_PREV_PAGE, PAGE_INFO;

  function getPathToRecord(dataID) {
    return storeData.getRecordStore().getPathToRecord(dataID);
  }

  function getRangeForRecord(dataID) {
    const nodeData = storeData.getNodeData();
    expect(Object.keys(nodeData)).toContain(dataID);
    return nodeData[dataID].__range__;
  }

  beforeEach(() => {
    jest.resetModules();

    ({
      CLIENT_MUTATION_ID,
      HAS_NEXT_PAGE,
      HAS_PREV_PAGE,
      PAGE_INFO,
    } = RelayConnectionInterface);

    cacheManager = RelayMockCacheManager.genCacheManager();
    storeData = new RelayStoreData();
    storeData.injectCacheManager(cacheManager);

    jasmine.addMatchers({
      toContainCalledMethods: () => ({
        compare: (actual, calls) => {
          let message;
          const pass = Object.keys(calls).every(methodName => {
            const expected = calls[methodName];
            const value = actual[methodName].mock.calls.length;
            const eachPass = expected === value;

            const expTimes = expected + ' time' + (expected === 1 ? '' : 's');
            const actTimes = value + ' time' + (value === 1 ? '' : 's');
            const not = eachPass ? 'not ' : '';
            message = 'Expected `' + methodName + '` ' + not + 'to be called ' +
              expTimes + ', was called ' + actTimes + '.';
            return eachPass;
          });
          return {pass, message};
        },
      }),
      toBeCalledWithNodeFields: (util, customEqualityTesters) => ({
        compare: (actual, nodeFields) => {
          let message;
          const pass = Object.keys(nodeFields).every(
            expectedID => Object.keys(nodeFields[expectedID]).every(
              expectedFieldName => {
                message =
                  'Expected function to be called with (' +
                  expectedID + ', ' +
                  expectedFieldName + ', ' +
                  nodeFields[expectedID][expectedFieldName] + ').';
                return actual.mock.calls.some(
                  ([actualID, actualFieldName, actualFieldValue]) => (
                    actualID === expectedID &&
                    actualFieldName === expectedFieldName &&
                    util.equals(
                      actualFieldValue,
                      nodeFields[expectedID][actualFieldName],
                      customEqualityTesters
                    )
                  )
                );
              }
            )
          );
          return {pass, message};
        },
      }),
    });
  });

  it('caches node metadata', () => {
    const query = getNode(Relay.QL`query{node(id:"123"){id}}`);
    const response = {
      node: {
        __typename: 'User',
        id: '123',
      },
    };
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 3,
      writeRootCall: 0,
    });
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        __dataID__: '123',
        __typename: 'User',
        id: '123',
      },
    });
  });

  it('caches custom root calls', () => {
    const query = getNode(Relay.QL`query{username(name:"yuzhi"){id}}`);
    const response = {
      username: {
        __typename: 'User',
        id: '123',
      },
    };
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 3,
      writeRootCall: 1,
    });
    expect(queryWriter.writeRootCall).toBeCalledWith(
      'username',
      'yuzhi',
      '123'
    );
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        __dataID__: '123',
        __typename: 'User',
        id: '123',
      },
    });
  });

  it('caches nodes with client IDs', () => {
    const query = getNode(Relay.QL`query{viewer{isFbEmployee}}`);
    const response = {
      viewer: {
        __typename: 'User',
        isFbEmployee: true,
      },
    };
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 2,
      writeRootCall: 1,
    });
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      'client:1': {
        __dataID__: 'client:1',
        // __typename: 'User',
        isFbEmployee: true,
      },
    });
  });

  it('caches linked records', () => {
    const query = getNode(Relay.QL`
      query {
        node(id:"123") {
          id
          hometown {
            id
            url
          }
        }
      }
    `);
    const response = {
      node: {
        __typename: 'User',
        id: '123',
        hometown: {
          __typename: 'Page',
          id: '456',
          url: 'http://...',
        },
      },
    };
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 7,
      writeRootCall: 0,
    });
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        __dataID__: '123',
        __typename: 'User',
        id: '123',
        hometown: {__dataID__: '456'},
      },
      '456': {
        __dataID__: '456',
        // __typename: 'Page',
        id: '456',
        url: 'http://...',
      },
    });
  });

  it('caches plural fields', () => {
    const query = getNode(Relay.QL`
      query {
        node(id:"123") {
          id
          screennames {
            service
          }
        }
      }
    `);
    const response = {
      node: {
        __typename: 'User',
        id: '123',
        screennames: [
          {service: 'GTALK'},
          {service: 'TWITTER'},
        ],
      },
    };
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(getPathToRecord('client:1')).toEqual(getPathToRecord('client:2'));
    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 8,
      writeRootCall: 0,
    });
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        __dataID__: '123',
        __typename: 'User',
        id: '123',
        screennames: [
          {__dataID__: 'client:1'},
          {__dataID__: 'client:2'},
        ],
      },
      'client:1': {
        __dataID__: 'client:1',
        // __typename: 'Screenname',
        service: 'GTALK',
      },
      'client:2': {
        __dataID__: 'client:2',
        // __typename: 'Screenname',
        service: 'TWITTER',
      },
    });
  });

  it('caches connection fields', () => {
    const query = getNode(Relay.QL`
      query {
        node(id:"123") {
          id
          friends(first: 2) {
            edges {
              node {
                id
              }
              cursor
            }
            pageInfo {
              hasPreviousPage
              hasNextPage
            }
          }
        }
      }
    `);
    const response = transformRelayQueryPayload(query, {
      node: {
        __typename: 'User',
        id: '123',
        friends: {
          edges: [
            {
              node: {
                __typename: 'User',
                id: '1',
              },
              cursor: '1',
            },
            {
              node: {
                __typename: 'User',
                id: '2',
              },
              cursor: '2',
            },
          ],
          [PAGE_INFO]: {
            [HAS_PREV_PAGE]: false,
            [HAS_NEXT_PAGE]: true,
          },
        },
      },
    });
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 19,
      writeRootCall: 0,
    });
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        __dataID__: '123',
        __typename: 'User',
        id: '123',
        friends: {__dataID__: 'client:1'},
      },
      'client:1': {
        __dataID__: 'client:1',
        __filterCalls__: [],
        __forceIndex__: 0,
        __range__: getRangeForRecord('client:1'),
        // __typename: 'FriendsConnection',
      },
      'client:client:1:1': {
        __dataID__: 'client:client:1:1',
        // __typename: 'FriendsEdge',
        node: {__dataID__: '1'},
        cursor: '1',
      },
      '1': {
        __dataID__: '1',
        // __typename: 'User',
        id: '1',
      },
      'client:client:1:2': {
        __dataID__: 'client:client:1:2',
        // __typename: 'FriendsEdge',
        node: {__dataID__: '2'},
        cursor: '2',
      },
      '2': {
        __dataID__: '2',
        // __typename: 'User',
        id: '2',
      },
    });
  });

  it('caches connection fields with no edges', () => {
    const query = getNode(Relay.QL`
      query {
        node(id:"123") {
          id
          friends(first: 2) {
            edges {
              node {
                id
              }
              cursor
            }
            pageInfo {
              hasPreviousPage
              hasNextPage
            }
          }
        }
      }
    `);
    const response = transformRelayQueryPayload(query, {
      node: {
        __typename: 'User',
        id: '123',
        friends: {
          edges: [],
          [PAGE_INFO]: {
            [HAS_PREV_PAGE]: false,
            [HAS_NEXT_PAGE]: true,
          },
        },
      },
    });
    storeData.handleQueryPayload(query, response);
    const {queryWriter} = cacheManager.mocks;

    expect(queryWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 9,
      writeRootCall: 0,
    });
    expect(queryWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        __dataID__: '123',
        id: '123',
        friends: {__dataID__: 'client:1'},
      },
      'client:1': {
        __dataID__: 'client:1',
        __filterCalls__: [],
        __forceIndex__: 0,
        __range__: getRangeForRecord('client:1'),
        // __typename: 'FriendsConnection',
      },
    });
  });

  it('caches simple mutations', () => {
    const query = getNode(Relay.QL`query{node(id:"123"){id,doesViewerLike}}`);
    const response = {
      node: {
        __typename: 'User',
        id: '123',
        doesViewerLike: false,
      },
    };
    storeData.handleQueryPayload(query, response);
    const {mutationWriter} = cacheManager.mocks;

    const mutationQuery = getNode(Relay.QL`
      mutation {
        feedbackLike(input:$input) {
          clientMutationId
          feedback {
            id
            doesViewerLike
          }
        }
      }
    `);
    const payload = {
      [CLIENT_MUTATION_ID]: 'abc',
      feedback: {
        id: '123',
        doesViewerLike: true,
      },
    };
    storeData.handleUpdatePayload(
      mutationQuery,
      payload,
      {configs: [], isOptimisticUpdate: false}
    );

    expect(mutationWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 2, // both scalar fields are updated
      writeRootCall: 0,
    });
    expect(mutationWriter.writeField).toBeCalledWithNodeFields({
      '123': {
        doesViewerLike: true,
      },
    });
  });

  it('caches mutation that inserts an edge', () => {
    const query = getNode(Relay.QL`
      query {
        node(id:"123") {
          id
          comments(first: 1) {
            count
            edges {
              node {
                id
              }
              cursor
            }
            pageInfo {
              hasPreviousPage
              hasNextPage
            }
          }
        }
      }
    `);
    const response = transformRelayQueryPayload(query, {
      node: {
        __typename: 'Story',
        id: '123',
        comments: {
          count: 2,
          edges: [
            {
              node: {
                id: '1',
              },
              cursor: '1',
            },
          ],
          [PAGE_INFO]: {
            [HAS_PREV_PAGE]: false,
            [HAS_NEXT_PAGE]: true,
          },
        },
      },
    });
    storeData.handleQueryPayload(query, response);
    const {mutationWriter} = cacheManager.mocks;

    const configs = [{
      type: RelayMutationType.RANGE_ADD,
      connectionName: 'comments',
      edgeName: 'feedbackCommentEdge',
      rangeBehaviors: {'': GraphQLMutatorConstants.PREPEND},
    }];

    const mutationQuery = getNode(Relay.QL`
      mutation {
        commentCreate(input:$input) {
          clientMutationId
          feedback {
            id
            comments {
              count
            }
          }
          feedbackCommentEdge {
            node {
              id
            }
            cursor
            source {
              id
            }
          }
        }
      }
    `);
    const payload = {
      [CLIENT_MUTATION_ID]: 'abc',
      feedback: {
        comments: {
          count: 3,
        },
        id: '123',
      },
      feedbackCommentEdge: {
        __typename: 'User',
        node: {
          id: '2',
        },
        cursor: '2',
        source: {
          id: '123',
        },
      },
    };
    storeData.handleUpdatePayload(
      mutationQuery,
      payload,
      {configs, isOptimisticUpdate: false}
    );

    expect(mutationWriter).toContainCalledMethods({
      writeNode: 0,
      writeField: 11,
      writeRootCall: 0,
    });
    expect(mutationWriter.writeField).toBeCalledWithNodeFields({
      'client:1': {
        __range__: getRangeForRecord('client:1'),
        count: 3,
      },
      'client:client:1:2': {
        __dataID__: 'client:client:1:2',
        node: {__dataID__: '2'},
        cursor: '2',
        source: {__dataID__: '123'},
      },
      '2': {
        __dataID__: '2',
        id: '2',
      },
    });
  });

  it('caches mutation that deletes an edge', () => {
    const query = getNode(Relay.QL`
      query {
        node(id:"123") {
          id
          comments(first: 1) {
            count
            edges {
              node {
                id
              }
              cursor
            }
            pageInfo {
              hasPreviousPage
              hasNextPage
            }
          }
        }
      }
    `);
    const response = transformRelayQueryPayload(query, {
      node: {
        __typename: 'Story',
        id: '123',
        comments: {
          count: 2,
          edges: [
            {
              node: {
                id: '1',
              },
              cursor: '1',
            },
          ],
          [PAGE_INFO]: {
            [HAS_PREV_PAGE]: false,
            [HAS_NEXT_PAGE]: true,
          },
        },
      },
    });
    storeData.handleQueryPayload(query, response);
    const {mutationWriter} = cacheManager.mocks;

    const configs = [{
      type: RelayMutationType.RANGE_DELETE,
      pathToConnection: ['feedback', 'comments'],
      deletedIDFieldName: 'deletedCommentId',
    }];

    const mutationQuery = getNode(Relay.QL`
      mutation {
        commentDelete(input:$input) {
          clientMutationId
          deletedCommentId
          feedback {
            id
            comments {
              count
            }
          }
        }
      }
    `);
    const payload = {
      [CLIENT_MUTATION_ID]: 'abc',
      deletedCommentId: '1',
      feedback: {
        id: '123',
        comments: {
          count: 1,
        },
      },
    };
    storeData.handleUpdatePayload(
      mutationQuery,
      payload,
      {configs, isOptimisticUpdate: false}
    );

    expect(mutationWriter).toContainCalledMethods({
      writeNode: 1,
      writeField: 4,
      writeRootCall: 0,
    });
    expect(mutationWriter.writeField).toBeCalledWithNodeFields({
      'client:1': {
        __range__: getRangeForRecord('client:1'),
        count: 1,
      },
    });
  });

  it('clears cache manager', () => {
    storeData.clearCacheManager();
    expect(storeData.hasCacheManager()).toBe(false);
  });
});


text:
require 'rolify/adapters/base'

module Rolify
  module Adapter
    class ResourceAdapter < ResourceAdapterBase
      def find_roles(role_name, relation, user)
        roles = user && (user != :any) ? user.roles : self.role_class
        roles = roles.where('resource_type IN (?)', self.relation_types_for(relation))
        roles = roles.where(:name => role_name.to_s) if role_name && (role_name != :any)
        roles
      end

      def resources_find(roles_table, relation, role_name)
        klasses   = self.relation_types_for(relation)
        relations = klasses.inject('') do |str, klass|
          str = "#{str}'#{klass.to_s}'"
          str << ', ' unless klass == klasses.last
          str
        end

        resources = relation.joins("INNER JOIN #{quote_table(roles_table)} ON #{quote_table(roles_table)}.resource_type IN (#{relations}) AND
                                    (#{quote_table(roles_table)}.resource_id IS NULL OR #{quote_table(roles_table)}.resource_id = #{quote_table(relation.table_name)}.#{quote_column(relation.primary_key)})")
        resources = resources.where("#{quote_table(roles_table)}.name IN (?) AND #{quote_table(roles_table)}.resource_type IN (?)", Array(role_name), klasses)
        resources = resources.select("#{quote_table(relation.table_name)}.*")
        resources
      end

      def in(relation, user, role_names)
        roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}")
        relation.where("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)} IN (?) AND ((#{quote_table(role_class.table_name)}.resource_id = #{quote_table(relation.table_name)}.#{quote_column(relation.primary_key)}) OR (#{quote_table(role_class.table_name)}.resource_id IS NULL))", roles)
      end

      def applied_roles(relation, children)
        if children
          relation.role_class.where('resource_type IN (?) AND resource_id IS NULL', self.relation_types_for(relation))
        else
          relation.role_class.where('resource_type = ? AND resource_id IS NULL', relation.to_s)
        end
      end

      def all_except(resource, excluded_obj)
        prime_key = resource.primary_key.to_sym
        resource.where.not(prime_key => excluded_obj.pluck(prime_key))
      end

      private

      def quote_column(column)
        ActiveRecord::Base.connection.quote_column_name column
      end

      def quote_table(table)
        ActiveRecord::Base.connection.quote_table_name table
      end

    end
  end
end


text:
<?xml version="1.0" ?><para version="5.0" xml:lang="zh" xmlns="http://docbook.org/ns/docbook">

Description of GridFS configuration options

    <col width="50%"/>
    <col width="50%"/>

        Configuration option = Default value
        描述

        [glance_store]

        <option>mongodb_store_db</option> = <replaceable>无</replaceable>
        (StrOpt) Database to use

        <option>mongodb_store_uri</option> = <replaceable>无</replaceable>
        (StrOpt) Hostname or IP address of the instance to connect to, or a mongodb URI, or a list of hostnames / mongodb URIs. If host is an IPv6 literal it must be enclosed in '[' and ']' characters following the RFC2732 URL syntax (e.g. '[::1]' for localhost)

</para>


text:
<?php

class Drivertool_model extends CI_Model{

	private $idDriverTool;
	private $idMatch;
	private $idMembre;
	private $tookHisCar;
    private $travelCost;

	public function __construct($idDriverTool ='', $idMatch ='', $idMembre ='', $tookHisCar ='',$travelCost=''){
		parent::__construct();
		$this->idDriverTool = $idDriverTool;
		$this->idMatch = $idMatch;
		$this->idMembre = $idMembre;
		$this->tookHisCar = $tookHisCar;
        $this->travelCost = $travelCost;
	}

    public function hydrate($obj){

        $this->setIdDriverTool($obj->id_driver_tool);
        $this->setIdMatch($obj->id_match);
        $this->setIdMembre($obj->id_membre);
        $this->setTookHisCar($obj->tookhiscar);
        $this->setTravelCost($obj->travelcost);

        return $this;
    }

    /**
     * Gets the value of idDriverTool.
     *
     * @return mixed
     */
    public function getIdDriverTool()
    {
        return $this->idDriverTool;
    }

    /**
     * Sets the value of idDriverTool.
     *
     * @param mixed $idDriverTool the id driver tool
     *
     * @return self
     */
    public function setIdDriverTool($idDriverTool)
    {
        $this->idDriverTool = $idDriverTool;

        return $this;
    }

    /**
     * Gets the value of idMatch.
     *
     * @return mixed
     */
    public function getIdMatch()
    {
        return $this->idMatch;
    }

    /**
     * Sets the value of idMatch.
     *
     * @param mixed $idMatch the id match
     *
     * @return self
     */
    public function setIdMatch($idMatch)
    {
        $this->idMatch = $idMatch;

        return $this;
    }

    /**
     * Gets the value of idMembre.
     *
     * @return mixed
     */
    public function getIdMembre()
    {
        return $this->idMembre;
    }

    /**
     * Sets the value of idMembre.
     *
     * @param mixed $idMembre the id membre
     *
     * @return self
     */
    public function setIdMembre($idMembre)
    {
        $this->idMembre = $idMembre;

        return $this;
    }

    /**
     * Gets the value of tookHisCar.
     *
     * @return mixed
     */
    public function getTookHisCar()
    {
        return $this->tookHisCar;
    }

    /**
     * Sets the value of tookHisCar.
     *
     * @param mixed $tookHisCar the took his car
     *
     * @return self
     */
    public function setTookHisCar($tookHisCar)
    {
        $this->tookHisCar = $tookHisCar;

        return $this;
    }

    /**
     * Gets the value of travelCost.
     *
     * @return mixed
     */
    public function getTravelCost()
    {
        return $this->travelCost;
    }

    /**
     * Sets the value of travelCost.
     *
     * @param mixed $travelCost
     *
     * @return self
     */
    public function setTravelCost($travelCost)
    {
        $this->travelCost = $travelCost;

        return $this;
    }

}


text:
<?php

namespace Org_Heigl\FileFinder\Filter;

use SplFileInfo;
use Exception;

class ClassHasTrait extends ClassIsInstanceof
{
    protected $useautoload = true;

    /**
     * Set flag if use autoload in filter
     */
    public function setFlagUseAutoload(bool $value)
    {
        $this->useautoload = $value;
    }

    /**
     * Check whether the given file should be included in the final Filelist
     *
     * @param SplFileInfo $file
     *
     * @return boolean
     */
    public function filter(SplFileInfo $file)
    {
        try {
            $class = $this->getClassName($file->getPathname());
        } catch (Exception $e){
            return false;
        }

        $usedtraits = class_uses($class, $this->useautoload);

        foreach ($this->instances as $instance) {
            if (in_array($instance, $usedtraits)) {
                return true;
            }
        }

        return false;
    }
}


text:
"""The pytest-ansible initialization."""

__version__ = "2.2.2"
__author__ = "James Laska"
__author_email__ = "<jlaska@ansible.com>"


text:
ImageAnnotator
--------------------------------

.. automodule:: google.cloud.vision_v1p2beta1.services.image_annotator
    :members:
    :inherited-members:


text:
import cgi, os,sys,traceback,logging
import wsgiref.handlers
##os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
##from django.conf import settings
##settings._target = None
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from django.utils.translation import check_for_language, activate, to_locale, get_language
from django.conf import settings
settings._target = None

from google.appengine.ext.webapp import template, \
	WSGIApplication
from google.appengine.api import users
#import app.webapp as webapp2
from google.appengine.ext import db
from google.appengine.ext import zipserve
from google.appengine.api import urlfetch
from google.appengine.api import memcache
from google.appengine.api import taskqueue
from datetime import datetime ,timedelta
import base64,random,math,zipfile
from django.utils import simplejson
import pickle
from base import *
from model import *

from app.pingback import autoPingback
from app.trackback import TrackBack
import xmlrpclib
from xmlrpclib import Fault

class Error404(BaseRequestHandler):
	#@printinfo
	def get(self,slug=None):
		self.render2('views/admin/404.html')

class setlanguage(BaseRequestHandler):
	def get(self):
		lang_code = self.param('language')
		next = self.param('next')
		if (not next) and os.environ.has_key('HTTP_REFERER'):
			next = os.environ['HTTP_REFERER']
		if not next:
			next = '/'
		os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
		from django.utils.translation import check_for_language, activate, to_locale, get_language
		from django.conf import settings
		settings._target = None

		if lang_code and check_for_language(lang_code):
			g_blog.language=lang_code
			activate(g_blog.language)
			g_blog.save()
		self.redirect(next)

##			if hasattr(request, 'session'):
##				request.session['django_language'] = lang_code
##			else:

##			cookiestr='django_language=%s;expires=%s;domain=%s;path=/'%( lang_code,
##					   (datetime.now()+timedelta(days=100)).strftime("%a, %d-%b-%Y %H:%M:%S GMT"),
##					   ''
##					   )
##			self.write(cookiestr)

			#self.response.headers.add_header('Set-Cookie', cookiestr)

def fetch_result(target_uri):
	for RETRY in range(5):
		try:
			response = urlfetch.fetch(target_uri)
			return response
		except urlfetch.DownloadError:
			logging.info('Download Error, Retry %s times'%RETRY)
			continue
		except:
			raise PingbackError(16)
	else:
		logging.info('Times Over')
		raise PingbackError(16)

class admin_do_action(BaseRequestHandler):
	@requires_admin
	def get(self,slug=None):
		try:
			func=getattr(self,'action_'+slug)
			if func and callable(func):
				func()
			else:
				self.render2('views/admin/error.html',{'message':_('This operate has not defined!')})
		except:
			 self.render2('views/admin/error.html',{'message':_('This operate has not defined!')})

	def post(self,slug=None):
		try:
			func=getattr(self,'action_'+slug)
			if func and callable(func):
				func()
			else:
				self.render2('views/admin/error.html',{'message':_('This operate has not defined!')})
		except:
			 self.render2('views/admin/error.html',{'message':_('This operate has not defined!')})

	@requires_admin
	def action_test(self):
		self.write(os.environ)

	@requires_admin
	def action_cacheclear(self):
		memcache.flush_all()
		self.write(_('"Cache cleared successful"'))

	@requires_admin
	def action_updatecomments(self):
		for entry in Entry.all():
			cnt=entry.comments().count()
			if cnt<>entry.commentcount:
				entry.commentcount=cnt
				entry.put()
		self.write(_('"All comments updated"'))

	@requires_admin
	def action_updatecommentno(self):
		for entry in Entry.all():
			entry.update_commentno()
		self.write(_('"All comments number Updates."'))

	@requires_admin
	def action_updatelink(self):
		link_format=self.param('linkfmt')

		if link_format:
			link_format=link_format.strip()
			g_blog.link_format=link_format
			g_blog.save()
			for entry in Entry.all():
				vals={'year':entry.date.year,'month':str(entry.date.month).zfill(2),'day':entry.date.day,
				'postname':entry.slug,'post_id':entry.post_id}

				if entry.slug:
					newlink=link_format%vals
				else:
					newlink=g_blog.default_link_format%vals

				if entry.link<>newlink:
					entry.link=newlink
					entry.put()
			self.write(_('"Link formated succeed"'))
		else:
			self.write(_('"Please input url format."'))

	@requires_admin
	def action_init_blog(self,slug=None):

		for com in Comment.all():
			com.delete()

		for entry in Entry.all():
			entry.delete()

		g_blog.entrycount=0
		self.write(_('"Init has succeed."'))

	@requires_admin
	def action_update_tags(self,slug=None):
		for tag in Tag.all():
			tag.delete()
		for entry in Entry.all().filter('entrytype =','post'):
			if entry.tags:
				for t in entry.tags:
					try:
						Tag.add(t)
					except:
						traceback.print_exc()

		self.write(_('"All tags for entry have been updated."'))

	@requires_admin
	def action_update_archives(self,slug=None):
		for archive in Archive.all():
			archive.delete()
		entries=Entry.all().filter('entrytype =','post')

		archives={}

		for entry in entries:
			my = entry.date.strftime('%B %Y') # September-2008
			sy = entry.date.strftime('%Y') #2008
			sm = entry.date.strftime('%m') #09
			if archives.has_key(my):
				archive=archives[my]
				archive.entrycount+=1
			else:
				archive = Archive(monthyear=my,year=sy,month=sm,entrycount=1)
				archives[my]=archive

		for ar in archives.values():
			ar.put()

		self.write(_('"All entries have been updated."'))

	def action_trackback_ping(self):
		tbUrl=self.param('tbUrl')
		title=self.param('title')
		excerpt=self.param('excerpt')
		url=self.param('url')
		blog_name=self.param('blog_name')
		tb=TrackBack(tbUrl,title,excerpt,url,blog_name)
		tb.ping()

	def action_pingback_ping(self):
		"""Try to notify the server behind `target_uri` that `source_uri`
		points to `target_uri`.  If that fails an `PingbackError` is raised.
		"""
		source_uri=self.param('source')
		target_uri=self.param('target')
		try:
			#response =urlfetch.fetch(target_uri)
			response=fetch_result(target_uri) #retry up to 5 times
		except:
			raise PingbackError(32)

		try:
			pingback_uri = response.headers['X-Pingback']
		except KeyError:
			_pingback_re = re.compile(r'<link rel="pingback" href="([^"]+)" ?/?>(?i)')
			match = _pingback_re.search(response.content)
			if match is None:
				raise PingbackError(33)
			pingback_uri =urldecode(match.group(1))

		rpc = xmlrpclib.ServerProxy(pingback_uri)
		try:
			return rpc.pingback.ping(source_uri, target_uri)
		except Fault, e:
			raise PingbackError(e.faultCode)
		except:
			raise PingbackError(32)

class admin_tools(BaseRequestHandler):
	def __init__(self):
		self.current="config"

	@requires_admin
	def get(self,slug=None):
		self.render2('views/admin/tools.html')

class admin_sitemap(BaseRequestHandler):
	def __init__(self):
		self.current="config"

	@requires_admin
	def get(self,slug=None):
		self.render2('views/admin/sitemap.html')

	@requires_admin
	def post(self):
		str_options= self.param('str_options').split(',')
		for name in str_options:
			value=self.param(name)
			setattr(g_blog,name,value)

		bool_options= self.param('bool_options').split(',')
		for name in bool_options:
			value=self.param(name)=='on'
			setattr(g_blog,name,value)

		int_options= self.param('int_options').split(',')
		for name in int_options:
			try:
				value=int( self.param(name))
				setattr(g_blog,name,value)
			except:
				pass
		float_options= self.param('float_options').split(',')
		for name in float_options:
			try:
				value=float( self.param(name))
				setattr(g_blog,name,value)
			except:
				pass

		g_blog.save()
		self.render2('views/admin/sitemap.html',{})

class admin_import(BaseRequestHandler):
	def __init__(self):
		self.current='config'

	@requires_admin
	def get(self,slug=None):
		gblog_init()
		self.render2('views/admin/import.html',{'importitems':
			self.blog.plugins.filter('is_import_plugin',True)})

##	def post(self):
##		try:
##			queue=taskqueue.Queue("import")
##			wpfile=self.param('wpfile')
##			#global imt
##			imt=import_wordpress(wpfile)
##			imt.parse()
##			memcache.set("imt",imt)
##
####			import_data=OptionSet.get_or_insert(key_name="import_data")
####			import_data.name="import_data"
####			import_data.bigvalue=pickle.dumps(imt)
####			import_data.put()
##
##			queue.add(taskqueue.Task( url="/admin/import_next"))
##			self.render2('views/admin/import.html',
##						{'postback':True})
##			return
##			memcache.set("import_info",{'count':len(imt.entries),'msg':'Begin import...','index':1})
##			#self.blog.import_info={'count':len(imt.entries),'msg':'Begin import...','index':1}
##			if imt.categories:
##				queue.add(taskqueue.Task( url="/admin/import_next",params={'cats': pickle.dumps(imt.categories),'index':1}))
##
##			return
##			index=0
##			if imt.entries:
##				for entry in imt.entries :
##					try:
##						index=index+1
##						queue.add(taskqueue.Task(url="/admin/import_next",params={'entry':pickle.dumps(entry),'index':index}))
##					except:
##						pass
##
##		except:
##			self.render2('views/admin/import.html',{'error':'import faiure.'})

class admin_setup(BaseRequestHandler):
	def __init__(self):
		self.current='config'

	@requires_admin
	def get(self,slug=None):
		vals={'themes':ThemeIterator()}
		self.render2('views/admin/setup.html',vals)

	@requires_admin
	def post(self):
		old_theme=g_blog.theme_name
		str_options= self.param('str_options').split(',')
		for name in str_options:
			value=self.param(name)
			setattr(g_blog,name,value)

		bool_options= self.param('bool_options').split(',')
		for name in bool_options:
			value=self.param(name)=='on'
			setattr(g_blog,name,value)

		int_options= self.param('int_options').split(',')
		for name in int_options:
			try:
				value=int( self.param(name))
				setattr(g_blog,name,value)
			except:
				pass
		float_options= self.param('float_options').split(',')
		for name in float_options:
			try:
				value=float( self.param(name))
				setattr(g_blog,name,value)
			except:
				pass

		if old_theme !=g_blog.theme_name:
			g_blog.get_theme()

		g_blog.owner=self.login_user
		g_blog.author=g_blog.owner.nickname()
		g_blog.save()
		gblog_init()
		vals={'themes':ThemeIterator()}
		memcache.flush_all()
		self.render2('views/admin/setup.html',vals)

class admin_entry(BaseRequestHandler):
	def __init__(self):
		self.current='write'

	@requires_admin
	def get(self,slug='post'):
		action=self.param("action")
		entry=None
		cats=Category.all()
		alltags=Tag.all()
		if action and  action=='edit':
				try:
					key=self.param('key')
					entry=Entry.get(key)

				except:
					pass
		else:
			action='add'

		def mapit(cat):
			return {'name':cat.name,'slug':cat.slug,'select':entry and cat.key() in entry.categorie_keys}

		vals={'action':action,'entry':entry,'entrytype':slug,'cats':map(mapit,cats),'alltags':alltags}
		self.render2('views/admin/entry.html',vals)

	@requires_admin
	def post(self,slug='post'):
		action=self.param("action")
		title=self.param("post_title")
		content=self.param('content')
		tags=self.param("tags")
		cats=self.request.get_all('cats')
		key=self.param('key')
		if self.param('publish')!='':
			published=True
		elif self.param('unpublish')!='':
			published=False
		else:
			published=self.param('published')=='True'

		allow_comment=self.parambool('allow_comment')
		allow_trackback=self.parambool('allow_trackback')
		entry_slug=self.param('slug')
		entry_parent=self.paramint('entry_parent')
		menu_order=self.paramint('menu_order')
		entry_excerpt=self.param('excerpt').replace('\n','
')
		password=self.param('password')
		sticky=self.parambool('sticky')

		is_external_page=self.parambool('is_external_page')
		target=self.param('target')
		external_page_address=self.param('external_page_address')

		def mapit(cat):
			return {'name':cat.name,'slug':cat.slug,'select':cat.slug in cats}

		vals={'action':action,'postback':True,'cats':Category.all(),'entrytype':slug,
			  'cats':map(mapit,Category.all()),
			  'entry':{ 'title':title,'content':content,'strtags':tags,'key':key,'published':published,
						 'allow_comment':allow_comment,
						 'allow_trackback':allow_trackback,
						'slug':entry_slug,
						'entry_parent':entry_parent,
						'excerpt':entry_excerpt,
						'menu_order':menu_order,
						'is_external_page':is_external_page,
						'target':target,
						'external_page_address':external_page_address,
						'password':password,
						'sticky':sticky}
			  }

		if not (title and (content or (is_external_page and external_page_address))):
			vals.update({'result':False, 'msg':_('Please input title and content.')})
			self.render2('views/admin/entry.html',vals)
		else:
			if action=='add':
				entry= Entry(title=title,content=content)
				entry.settags(tags)
				entry.entrytype=slug
				entry.slug=entry_slug.replace(" ","-")
				entry.entry_parent=entry_parent
				entry.menu_order=menu_order
				entry.excerpt=entry_excerpt
				entry.is_external_page=is_external_page
				entry.target=target
				entry.external_page_address=external_page_address
				newcates=[]
				entry.allow_comment=allow_comment
				entry.allow_trackback=allow_trackback
				entry.author=self.author.user
				entry.author_name=self.author.dispname
				entry.password=password
				entry.sticky=sticky
				if cats:

					for cate in cats:
						c=Category.all().filter('slug =',cate)
						if c:
							newcates.append(c[0].key())
				entry.categorie_keys=newcates;

				entry.save(published)
				if published:
					smsg=_('Saved ok. View it now!')
				else:
					smsg=_('Saved ok.')

				vals.update({'action':'edit','result':True,'msg':smsg%{'link':str(entry.link)},'entry':entry})
				self.render2('views/admin/entry.html',vals)
				if published and entry.allow_trackback and g_blog.allow_pingback:
					try:
						autoPingback(str(entry.fullurl),HTML=content)
					except:
						pass
			elif action=='edit':
				try:
					entry=Entry.get(key)
					entry.title=title
					entry.content=content
					entry.slug=entry_slug.replace(' ','-')
					entry.entry_parent=entry_parent
					entry.menu_order=menu_order
					entry.excerpt=entry_excerpt
					entry.is_external_page=is_external_page
					entry.target=target
					entry.external_page_address=external_page_address
					entry.settags(tags)
					entry.author=self.author.user
					entry.author_name=self.author.dispname
					entry.password=password
					entry.sticky=sticky
					newcates=[]

					if cats:

						for cate in cats:
							c=Category.all().filter('slug =',cate)
							if c:
								newcates.append(c[0].key())
					entry.categorie_keys=newcates;
					entry.allow_comment=allow_comment
					entry.allow_trackback=allow_trackback

					entry.save(published)

					if published:
						smsg=_('Saved ok. View it now!')
					else:
						smsg=_('Saved ok.')
					vals.update({'result':True,'msg':smsg%{'link':str(urlencode( entry.link))},'entry':entry})

					self.render2('views/admin/entry.html',vals)

				except:
					vals.update({'result':False,'msg':_('Error:Entry can''t been saved.')})
					self.render2('views/admin/entry.html',vals)

class admin_entries(BaseRequestHandler):
	@requires_admin
	def get(self,slug='post'):
		try:
			page_index=int(self.param('page'))
		except:
			page_index=1

		entries=Entry.all().filter('entrytype =',slug).order('-date')
		entries,links=Pager(query=entries,items_per_page=15).fetch(page_index)

		self.render2('views/admin/'+slug+'s.html',
		 {
		   'current':slug+'s',
		   'entries':entries,
		   'pager':links
		  }
		)

	@requires_admin
	def post(self,slug='post'):
		try:
			linkcheck= self.request.get_all('checks')
			for id in linkcheck:
				kid=int(id)

				entry=Entry.get_by_id(kid)

				#delete it's comments
				#entry.delete_comments()

				entry.delete()
				g_blog.entrycount-=1
		finally:

			self.redirect('/admin/entries/'+slug)

class admin_categories(BaseRequestHandler):
	@requires_admin
	def get(self,slug=None):
		try:
			page_index=int(self.param('page'))
		except:
			page_index=1

		cats=Category.allTops()
		entries,pager=Pager(query=cats,items_per_page=15).fetch(page_index)

		self.render2('views/admin/categories.html',
		 {
		   'current':'categories',
		   'cats':cats,
		   'pager':pager
		  }
		)

	@requires_admin
	def post(self,slug=None):
		try:
			linkcheck= self.request.get_all('checks')
			for key in linkcheck:

				cat=Category.get(key)
				if cat:
					cat.delete()
		finally:
			self.redirect('/admin/categories')

class admin_comments(BaseRequestHandler):
	@requires_admin
	def get(self,slug=None):
		try:
			page_index=int(self.param('page'))
		except:
			page_index=1

		cq=self.param('cq')
		cv=self.param('cv')
		if cq and cv:
			query=Comment.all().filter(cq+' =',cv).order('-date')
		else:
			query=Comment.all().order('-date')
		comments,pager=Pager(query=query,items_per_page=15).fetch(page_index)

		self.render2('views/admin/comments.html',
		 {
		   'current':'comments',
		   'comments':comments,
		   'pager':pager,
		   'cq':cq,
		   'cv':cv
		  }
		)

	@requires_admin
	def post(self,slug=None):
		try:
			linkcheck= self.request.get_all('checks')
			entrykeys=[]
			for key in linkcheck:

				comment=Comment.get(key)
				comment.delit()
				entrykeys.append(comment.entry.key())
			entrykeys=set(entrykeys)
			for key in entrykeys:
				e=Entry.get(key)
				e.update_commentno()
				e.removecache()
			memcache.delete("/feed/comments")
		finally:
			self.redirect(self.request.uri)

class admin_links(BaseRequestHandler):
	@requires_admin
	def get(self,slug=None):
		self.render2('views/admin/links.html',
		 {
		  'current':'links',
		  'links':Link.all().filter('linktype =','blogroll')#.order('-createdate')
		  }
		)
	@requires_admin
	def post(self):
		linkcheck= self.request.get_all('linkcheck')
		for link_id in linkcheck:
			kid=int(link_id)
			link=Link.get_by_id(kid)
			link.delete()
		self.redirect('/admin/links')

class admin_link(BaseRequestHandler):
	@requires_admin
	def get(self,slug=None):
		action=self.param("action")
		vals={'current':'links'}
		if action and  action=='edit':
				try:
					action_id=int(self.param('id'))
					link=Link.get_by_id(action_id)
					vals.update({'link':link})
				except:
					pass
		else:
			action='add'
		vals.update({'action':action})

		self.render2('views/admin/link.html',vals)

	@requires_admin
	def post(self):
		action=self.param("action")
		name=self.param("link_name")
		url=self.param("link_url")
		comment = self.param("link_comment")

		vals={'action':action,'postback':True,'current':'links'}
		if not (name and url):
			vals.update({'result':False,'msg':_('Please input name and url.')})
			self.render2('views/admin/link.html',vals)
		else:
			if action=='add':
			   link= Link(linktext=name,href=url,linkcomment=comment)
			   link.put()
			   vals.update({'result':True,'msg':'Saved ok'})
			   self.render2('views/admin/link.html',vals)
			elif action=='edit':
				try:
					action_id=int(self.param('id'))
					link=Link.get_by_id(action_id)
					link.linktext=name
					link.href=url
					link.linkcomment = comment
					link.put()
					#goto link manage page
					self.redirect('/admin/links')

				except:
					vals.update({'result':False,'msg':_('Error:Link can''t been saved.')})
					self.render2('views/admin/link.html',vals)

class admin_category(BaseRequestHandler):
	def __init__(self):
		self.current='categories'

	@requires_admin
	def get(self,slug=None):
		action=self.param("action")
		key=self.param('key')
		category=None
		if action and  action=='edit':
				try:

					category=Category.get(key)

				except:
					pass
		else:
			action='add'
		vals={'action':action,'category':category,'key':key,'categories':[c for c in Category.all() if not category or c.key()!=category.key()]}
		self.render2('views/admin/category.html',vals)

	@requires_admin
	def post(self):
		def check(cate):
			parent=cate.parent_cat
			skey=cate.key()
			while parent:
				if parent.key()==skey:
					return False
				parent=parent.parent_cat
			return True

		action=self.param("action")
		name=self.param("name")
		slug=self.param("slug")
		parentkey=self.param('parentkey')
		key=self.param('key')

		vals={'action':action,'postback':True}

		try:

				if action=='add':
					cat= Category(name=name,slug=slug)
					if not (name and slug):
						raise Exception(_('Please input name and slug.'))
					if parentkey:
						cat.parent_cat=Category.get(parentkey)

					cat.put()
					self.redirect('/admin/categories')

					#vals.update({'result':True,'msg':_('Saved ok')})
					#self.render2('views/admin/category.html',vals)
				elif action=='edit':

						cat=Category.get(key)
						cat.name=name
						cat.slug=slug
						if not (name and slug):
							raise Exception(_('Please input name and slug.'))
						if parentkey:
							cat.parent_cat=Category.get(parentkey)
							if not check(cat):
								raise Exception(_('A circle declaration found.'))
						else:
							cat.parent_cat=None
						cat.put()
						self.redirect('/admin/categories')

		except Exception ,e :
			if cat.is_saved():
				cates=[c for c in Category.all() if c.key()!=cat.key()]
			else:
				cates= Category.all()

			vals.update({'result':False,'msg':e.message,'category':cat,'key':key,'categories':cates})
			self.render2('views/admin/category.html',vals)

class admin_status(BaseRequestHandler):
	@requires_admin
	def get(self):
		self.render2('views/admin/status.html',{'cache':memcache.get_stats(),'current':'status','environ':os.environ})
class admin_authors(BaseRequestHandler):
	@requires_admin
	def get(self):
		try:
			page_index=int(self.param('page'))
		except:
			page_index=1

		authors=User.all().filter('isAuthor =',True)
		entries,pager=Pager(query=authors,items_per_page=15).fetch(page_index)

		self.render2('views/admin/authors.html',
		 {
		   'current':'authors',
		   'authors':authors,
		   'pager':pager
		  }
		)

	@requires_admin
	def post(self,slug=None):
		try:
			linkcheck= self.request.get_all('checks')
			for key in linkcheck:

				author=User.get(key)
				author.delete()
		finally:
			self.redirect('/admin/authors')
class admin_author(BaseRequestHandler):
	def __init__(self):
		self.current='authors'

	@requires_admin
	def get(self,slug=None):
		action=self.param("action")
		author=None
		if action and  action=='edit':
				try:
					key=self.param('key')
					author=User.get(key)

				except:
					pass
		else:
			action='add'
		vals={'action':action,'author':author}
		self.render2('views/admin/author.html',vals)

	@requires_admin
	def post(self):
		action=self.param("action")
		name=self.param("name")
		slug=self.param("email")

		vals={'action':action,'postback':True}
		if not (name and slug):
			vals.update({'result':False,'msg':_('Please input dispname and email.')})
			self.render2('views/admin/author.html',vals)
		else:
			if action=='add':
			   author= User(dispname=name,email=slug	)
			   author.user=db.users.User(slug)
			   author.put()
			   vals.update({'result':True,'msg':'Saved ok'})
			   self.render2('views/admin/author.html',vals)
			elif action=='edit':
				try:
					key=self.param('key')
					author=User.get(key)
					author.dispname=name
					author.email=slug
					author.user=db.users.User(slug)
					author.put()
					if author.isadmin:
						g_blog.author=name
					self.redirect('/admin/authors')

				except:
					vals.update({'result':False,'msg':_('Error:Author can''t been saved.')})
					self.render2('views/admin/author.html',vals)
class admin_plugins(BaseRequestHandler):
	def __init__(self):
		self.current='plugins'

	@requires_admin
	def get(self,slug=None):
		vals={'plugins':self.blog.plugins}
		self.render2('views/admin/plugins.html',vals)

	@requires_admin
	def post(self):
		action=self.param("action")
		name=self.param("plugin")
		ret=self.param("return")
		self.blog.plugins.activate(name,action=="activate")
		if ret:
			self.redirect(ret)
		else:
			vals={'plugins':self.blog.plugins}
			self.render2('views/admin/plugins.html',vals)

class admin_plugins_action(BaseRequestHandler):
	def __init__(self):
		self.current='plugins'

	@requires_admin
	def get(self,slug=None):
		plugin=self.blog.plugins.getPluginByName(slug)
		if not plugin :
			self.error(404)
			return
		plugins=self.blog.plugins.filter('active',True)
		if not plugin.active:
			pcontent=_('''
Plugin '%(name)s' havn't actived!

<form method="post" action="/admin/plugins?action=activate&plugin=%(iname)s&return=/admin/plugins/%(iname)s"><input type="submit" value="Activate Now"/></form>''')%{'name':plugin.name,'iname':plugin.iname}
			plugins.insert(0,plugin)
		else:
			pcontent=plugin.get(self)

		vals={'plugins':plugins,
			  'plugin':plugin,
			  'pcontent':pcontent}

		self.render2('views/admin/plugin_action.html',vals)

	@requires_admin
	def post(self,slug=None):

		plugin=self.blog.plugins.getPluginByName(slug)
		if not plugin :
			self.error(404)
			return
		plugins=self.blog.plugins.filter('active',True)
		if not plugin.active:
			pcontent=_('''
Plugin '%(name)s' havn't actived!

<form method="post" action="/admin/plugins?action=activate&plugin=%(iname)s&return=/admin/plugins/%(iname)s"><input type="submit" value="Activate Now"/></form>''')%{'name':plugin.name,'iname':plugin.iname}
			plugins.insert(0,plugin)
		else:
			pcontent=plugin.post(self)

		vals={'plugins':plugins,
			  'plugin':plugin,
			  'pcontent':pcontent}

		self.render2('views/admin/plugin_action.html',vals)

class WpHandler(BaseRequestHandler):
	@requires_admin
	def get(self,tags=None):
		try:
			all=self.param('all')
		except:
			all=False

		if(all):
			entries = Entry.all().order('-date')
			filename='micolog.%s.xml'%datetime.now().strftime('%Y-%m-%d')
		else:
			str_date_begin=self.param('date_begin')
			str_date_end=self.param('date_end')
			try:
				date_begin=datetime.strptime(str_date_begin,"%Y-%m-%d")
				date_end=datetime.strptime(str_date_end,"%Y-%m-%d")
				entries = Entry.all().filter('date >=',date_begin).filter('date <',date_end).order('-date')
				filename='micolog.%s.%s.xml'%(str(str_date_begin),str(str_date_end))
			except:
				self.render2('views/admin/404.html')
				return

		cates=Category.all()
		tags=Tag.all()

		self.response.headers['Content-Type'] = 'binary/octet-stream'#'application/atom+xml'
		self.response.headers['Content-Disposition'] = 'attachment; filename=%s'%filename
		self.render2('views/wordpress.xml',{'entries':entries,'cates':cates,'tags':tags})

class Upload(BaseRequestHandler):

	@requires_admin
	def post(self):
		name = self.param('filename')
		mtype = self.param('fileext')
		bits = self.param('upfile')
		Media(name = name, mtype = mtype, bits = bits).put()

		self.redirect('/admin/filemanager')

class UploadEx(BaseRequestHandler):
	@requires_admin
	def get(self):
		extstr=self.param('ext')
		ext=extstr.split('|')
		files=Media.all()
		if extstr!='*':
			files=files.filter('mtype IN',ext)
		self.render2('views/admin/upload.html',{'ext':extstr,'files':files})

	@requires_admin
	def post(self):
		ufile=self.request.params['userfile']
		#if ufile:
		name=ufile.filename
		mtype =os.path.splitext(name)[1][1:]
		bits = self.param('userfile')
		media=Media(name = name, mtype = mtype, bits = bits)
		media.put()
		self.write(simplejson.dumps({'name':media.name,'size':media.size,'id':str(media.key())}))

class FileManager(BaseRequestHandler):

	def __init__(self):
		self.current='files'

	@requires_admin
	def get(self):
		try:
			page_index=int(self.param('page'))
		except:
			page_index=1
		files = Media.all().order('-date')
		files,links=Pager(query=files,items_per_page=15).fetch(page_index)
		self.render2('views/admin/filemanager.html',{'files' : files,'pager':links})

	@requires_admin
	def post(self): # delete files
		delids = self.request.POST.getall('del')
		if delids:
			for id in delids:
				file = Media.get_by_id(int(id))
				file.delete()

		self.redirect('/admin/filemanager')

class admin_main(BaseRequestHandler):
	@requires_admin
	def get(self,slug=None):
		if self.is_admin:
			self.redirect('/admin/setup')
		else:
			self.redirect('/admin/entries/post')

class admin_ThemeEdit(BaseRequestHandler):
	@requires_admin
	def get(self,slug):
		zfile=zipfile.ZipFile(os.path.join(rootpath,"themes",slug+".zip"))
		newfile=zipfile.ZipFile('')
		for item  in zfile.infolist():
			self.write(item.filename+"
")

def main():
	webapp.template.register_template_library('filter')
	webapp.template.register_template_library('app.recurse')

	application = webapp.WSGIApplication(
					[
					('/admin/{0,1}',admin_main),
					('/admin/setup',admin_setup),
					('/admin/entries/(post|page)',admin_entries),
					('/admin/links',admin_links),
					('/admin/categories',admin_categories),
					('/admin/comments',admin_comments),
					('/admin/link',admin_link),
					('/admin/category',admin_category),
					 ('/admin/(post|page)',admin_entry),
					 ('/admin/status',admin_status),
					 ('/admin/authors',admin_authors),
					 ('/admin/author',admin_author),
					 ('/admin/import',admin_import),
					 ('/admin/tools',admin_tools),
					 ('/admin/plugins',admin_plugins),
					 ('/admin/plugins/(\w+)',admin_plugins_action),
					 ('/admin/sitemap',admin_sitemap),
					 ('/admin/export/micolog.xml',WpHandler),
					 ('/admin/do/(\w+)',admin_do_action),
					 ('/admin/lang',setlanguage),
					 ('/admin/theme/edit/(\w+)',admin_ThemeEdit),

					 ('/admin/upload', Upload),
					 ('/admin/filemanager', FileManager),

					 ('/admin/uploadex', UploadEx),

					 ('.*',Error404),
					 ],debug=True)
	g_blog.application=application
	g_blog.plugins.register_handlerlist(application)
	wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
	main()


text:
<!DOCTYPE html>

    <meta http-equiv="X-Clacks-Overhead" content="GNU Terry Pratchett">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="AEWS Click Through Demonstration">
    <meta name="author" content="Stephen Gault">

    <title>AEWS Click Through</title>

    <link rel='shortcut icon' type='image/x-icon' href='img/csfs.jpg' />

    <link href="css/bootstrap.min.css" rel="stylesheet">

    <link href="css/AEWSClick.css" rel="stylesheet">

                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    Toggle navigation

                </button>

                        Navigation

Login<tml/li>

Home Page

Company Set-Up Overview

Company Set-Up Pension Data

Company Set-Up Pension Date Continued

Company Set-Up Pension Data Complete

Company Set-Up Building Your Company Profile

Company Set-Up Payroll Mapping

Company Set-Up Payroll Mapping Continued

Payroll Mapping Summary

Company Set-Up Overview Page

Home, Set-Up Complete

Start Certification

Certification Overview Start

Certification Overview

Modelling & certification Starting Point

Modelling & certification Starting End

Certification Overview End

Compliance Check Start

Compliance Data Load

Compliance Results

Compliance Results Options 1

Compliance Results Options 2

Compliance Communications

Compliance Results 1

Compliance Results 2

Download Files

Home Page End

Company Set-Up Overview

                        Page Notes

<map name="Map" id="Map">
    <area alt="" title="" href="CS2.html" shape="poly" coords="316,127,1276,123,1282,1049,318,1050" />

                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

About this page

Every section of AEWS has a main overview page, which shows you the current status and any work you need to do.

Company set-up creates the basis of the AEWS system for your organisation. There are two main sections here. You must complete them both to continue.

Features

Help with completing this part of the site.

Progress indicator

Breakdown of your workforce into auto-enrolment worker status.

Support from CSFS as you need it.


text:
exports.setEnvironment = function() {
  process.env['AZURE_TEST_LOCATION'] = 'japaneast';
  process.env['AZURE_AUTOSTORAGE'] = 'testaccountfornode';
  process.env['AZURE_SUBSCRIPTION_ID'] = 'f30ef677-64a9-4768-934f-5fbbc0e1ad27';
};

exports.scopes = [[function (nock) {
var result =
nock('https://management.azure.com:443')
  .filteringRequestBody(function (path) { return '*';})
.patch('/subscriptions/f30ef677-64a9-4768-934f-5fbbc0e1ad27/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/batchtestnodesdk/applications/my_application_id?api-version=2020-05-01', '*')
  .reply(409, "{\"error\":{\"code\":\"RequestedDefaultVersionNotActive\",\"message\":\"The application package corresponding to the requested default version is not active.\\nRequestId:d9f13ded-18d4-4656-9129-5ec1a922bf0e\\nTime:2020-06-04T06:22:47.3833328Z\",\"target\":\"BatchAccount\"}}", { 'cache-control': 'no-cache',
  pragma: 'no-cache',
  'content-length': '258',
  'content-type': 'application/json; charset=utf-8',
  expires: '-1',
  'x-ms-correlation-request-id': '96b909ac-06f6-425b-b684-707f0701c606',
  'x-ms-request-id': 'd9f13ded-18d4-4656-9129-5ec1a922bf0e',
  'strict-transport-security': 'max-age=31536000; includeSubDomains',
  'x-content-type-options': 'nosniff',
  'x-ms-ratelimit-remaining-subscription-writes': '1199',
  server: 'Microsoft-HTTPAPI/2.0',
  'x-ms-routing-request-id':
   'WESTUS:20200604T062247Z:96b909ac-06f6-425b-b684-707f0701c606',
  date: 'Thu, 04 Jun 2020 06:22:46 GMT',
  connection: 'close' });
 return result; }]];