text:
package mesos_scheduler

import proto "code.google.com/p/goprotobuf/proto"
import json "encoding/json"
import math "math"
import mesos "github.com/twitter/gozer/proto/mesos.pb"

// Reference proto, json, and math imports to suppress error if they are not otherwise used.
var _ = proto.Marshal
var _ = &json.SyntaxError{}
var _ = math.Inf

type Event_Type int32

const (
	Event_REGISTERED   Event_Type = 1
	Event_REREGISTERED Event_Type = 2
	Event_OFFERS       Event_Type = 3
	Event_RESCIND      Event_Type = 4
	Event_UPDATE       Event_Type = 5
	Event_MESSAGE      Event_Type = 6
	Event_FAILURE      Event_Type = 7
	Event_ERROR        Event_Type = 8
)

var Event_Type_name = map[int32]string{
	1: "REGISTERED",
	2: "REREGISTERED",
	3: "OFFERS",
	4: "RESCIND",
	5: "UPDATE",
	6: "MESSAGE",
	7: "FAILURE",
	8: "ERROR",
}
var Event_Type_value = map[string]int32{
	"REGISTERED":   1,
	"REREGISTERED": 2,
	"OFFERS":       3,
	"RESCIND":      4,
	"UPDATE":       5,
	"MESSAGE":      6,
	"FAILURE":      7,
	"ERROR":        8,
}

func (x Event_Type) Enum() *Event_Type {
	p := new(Event_Type)
	*p = x
	return p
}
func (x Event_Type) String() string {
	return proto.EnumName(Event_Type_name, int32(x))
}
func (x Event_Type) MarshalJSON() ([]byte, error) {
	return json.Marshal(x.String())
}
func (x *Event_Type) UnmarshalJSON(data []byte) error {
	value, err := proto.UnmarshalJSONEnum(Event_Type_value, data, "Event_Type")
	if err != nil {
		return err
	}
	*x = Event_Type(value)
	return nil
}

type Call_Type int32

const (
	Call_REGISTER    Call_Type = 1
	Call_REREGISTER  Call_Type = 2
	Call_UNREGISTER  Call_Type = 3
	Call_REQUEST     Call_Type = 4
	Call_DECLINE     Call_Type = 5
	Call_REVIVE      Call_Type = 6
	Call_LAUNCH      Call_Type = 7
	Call_KILL        Call_Type = 8
	Call_ACKNOWLEDGE Call_Type = 9
	Call_RECONCILE   Call_Type = 10
	Call_MESSAGE     Call_Type = 11
)

var Call_Type_name = map[int32]string{
	1:  "REGISTER",
	2:  "REREGISTER",
	3:  "UNREGISTER",
	4:  "REQUEST",
	5:  "DECLINE",
	6:  "REVIVE",
	7:  "LAUNCH",
	8:  "KILL",
	9:  "ACKNOWLEDGE",
	10: "RECONCILE",
	11: "MESSAGE",
}
var Call_Type_value = map[string]int32{
	"REGISTER":    1,
	"REREGISTER":  2,
	"UNREGISTER":  3,
	"REQUEST":     4,
	"DECLINE":     5,
	"REVIVE":      6,
	"LAUNCH":      7,
	"KILL":        8,
	"ACKNOWLEDGE": 9,
	"RECONCILE":   10,
	"MESSAGE":     11,
}

func (x Call_Type) Enum() *Call_Type {
	p := new(Call_Type)
	*p = x
	return p
}
func (x Call_Type) String() string {
	return proto.EnumName(Call_Type_name, int32(x))
}
func (x Call_Type) MarshalJSON() ([]byte, error) {
	return json.Marshal(x.String())
}
func (x *Call_Type) UnmarshalJSON(data []byte) error {
	value, err := proto.UnmarshalJSONEnum(Call_Type_value, data, "Call_Type")
	if err != nil {
		return err
	}
	*x = Call_Type(value)
	return nil
}

type Event struct {
	Type             *Event_Type         `protobuf:"varint,1,req,name=type,enum=mesos.scheduler.Event_Type" json:"type,omitempty"`
	Registered       *Event_Registered   `protobuf:"bytes,2,opt,name=registered" json:"registered,omitempty"`
	Reregistered     *Event_Reregistered `protobuf:"bytes,3,opt,name=reregistered" json:"reregistered,omitempty"`
	Offers           *Event_Offers       `protobuf:"bytes,4,opt,name=offers" json:"offers,omitempty"`
	Rescind          *Event_Rescind      `protobuf:"bytes,5,opt,name=rescind" json:"rescind,omitempty"`
	Update           *Event_Update       `protobuf:"bytes,6,opt,name=update" json:"update,omitempty"`
	Message          *Event_Message      `protobuf:"bytes,7,opt,name=message" json:"message,omitempty"`
	Failure          *Event_Failure      `protobuf:"bytes,8,opt,name=failure" json:"failure,omitempty"`
	Error            *Event_Error        `protobuf:"bytes,9,opt,name=error" json:"error,omitempty"`
	XXX_unrecognized []byte              `json:"-"`
}

func (m *Event) Reset()         { *m = Event{} }
func (m *Event) String() string { return proto.CompactTextString(m) }
func (*Event) ProtoMessage()    {}

func (m *Event) GetType() Event_Type {
	if m != nil && m.Type != nil {
		return *m.Type
	}
	return 0
}

func (m *Event) GetRegistered() *Event_Registered {
	if m != nil {
		return m.Registered
	}
	return nil
}

func (m *Event) GetReregistered() *Event_Reregistered {
	if m != nil {
		return m.Reregistered
	}
	return nil
}

func (m *Event) GetOffers() *Event_Offers {
	if m != nil {
		return m.Offers
	}
	return nil
}

func (m *Event) GetRescind() *Event_Rescind {
	if m != nil {
		return m.Rescind
	}
	return nil
}

func (m *Event) GetUpdate() *Event_Update {
	if m != nil {
		return m.Update
	}
	return nil
}

func (m *Event) GetMessage() *Event_Message {
	if m != nil {
		return m.Message
	}
	return nil
}

func (m *Event) GetFailure() *Event_Failure {
	if m != nil {
		return m.Failure
	}
	return nil
}

func (m *Event) GetError() *Event_Error {
	if m != nil {
		return m.Error
	}
	return nil
}

type Event_Registered struct {
	FrameworkId      *mesos.FrameworkID `protobuf:"bytes,1,req,name=framework_id" json:"framework_id,omitempty"`
	MasterInfo       *mesos.MasterInfo  `protobuf:"bytes,2,req,name=master_info" json:"master_info,omitempty"`
	XXX_unrecognized []byte             `json:"-"`
}

func (m *Event_Registered) Reset()         { *m = Event_Registered{} }
func (m *Event_Registered) String() string { return proto.CompactTextString(m) }
func (*Event_Registered) ProtoMessage()    {}

func (m *Event_Registered) GetFrameworkId() *mesos.FrameworkID {
	if m != nil {
		return m.FrameworkId
	}
	return nil
}

func (m *Event_Registered) GetMasterInfo() *mesos.MasterInfo {
	if m != nil {
		return m.MasterInfo
	}
	return nil
}

type Event_Reregistered struct {
	FrameworkId      *mesos.FrameworkID `protobuf:"bytes,1,req,name=framework_id" json:"framework_id,omitempty"`
	MasterInfo       *mesos.MasterInfo  `protobuf:"bytes,2,req,name=master_info" json:"master_info,omitempty"`
	XXX_unrecognized []byte             `json:"-"`
}

func (m *Event_Reregistered) Reset()         { *m = Event_Reregistered{} }
func (m *Event_Reregistered) String() string { return proto.CompactTextString(m) }
func (*Event_Reregistered) ProtoMessage()    {}

func (m *Event_Reregistered) GetFrameworkId() *mesos.FrameworkID {
	if m != nil {
		return m.FrameworkId
	}
	return nil
}

func (m *Event_Reregistered) GetMasterInfo() *mesos.MasterInfo {
	if m != nil {
		return m.MasterInfo
	}
	return nil
}

type Event_Offers struct {
	Offers           []*mesos.Offer `protobuf:"bytes,1,rep,name=offers" json:"offers,omitempty"`
	XXX_unrecognized []byte         `json:"-"`
}

func (m *Event_Offers) Reset()         { *m = Event_Offers{} }
func (m *Event_Offers) String() string { return proto.CompactTextString(m) }
func (*Event_Offers) ProtoMessage()    {}

func (m *Event_Offers) GetOffers() []*mesos.Offer {
	if m != nil {
		return m.Offers
	}
	return nil
}

type Event_Rescind struct {
	OfferId          *mesos.OfferID `protobuf:"bytes,1,req,name=offer_id" json:"offer_id,omitempty"`
	XXX_unrecognized []byte         `json:"-"`
}

func (m *Event_Rescind) Reset()         { *m = Event_Rescind{} }
func (m *Event_Rescind) String() string { return proto.CompactTextString(m) }
func (*Event_Rescind) ProtoMessage()    {}

func (m *Event_Rescind) GetOfferId() *mesos.OfferID {
	if m != nil {
		return m.OfferId
	}
	return nil
}

type Event_Update struct {
	Uuid             []byte            `protobuf:"bytes,1,req,name=uuid" json:"uuid,omitempty"`
	Status           *mesos.TaskStatus `protobuf:"bytes,2,req,name=status" json:"status,omitempty"`
	XXX_unrecognized []byte            `json:"-"`
}

func (m *Event_Update) Reset()         { *m = Event_Update{} }
func (m *Event_Update) String() string { return proto.CompactTextString(m) }
func (*Event_Update) ProtoMessage()    {}

func (m *Event_Update) GetUuid() []byte {
	if m != nil {
		return m.Uuid
	}
	return nil
}

func (m *Event_Update) GetStatus() *mesos.TaskStatus {
	if m != nil {
		return m.Status
	}
	return nil
}

type Event_Message struct {
	SlaveId          *mesos.SlaveID    `protobuf:"bytes,1,req,name=slave_id" json:"slave_id,omitempty"`
	ExecutorId       *mesos.ExecutorID `protobuf:"bytes,2,req,name=executor_id" json:"executor_id,omitempty"`
	Data             []byte            `protobuf:"bytes,3,req,name=data" json:"data,omitempty"`
	XXX_unrecognized []byte            `json:"-"`
}

func (m *Event_Message) Reset()         { *m = Event_Message{} }
func (m *Event_Message) String() string { return proto.CompactTextString(m) }
func (*Event_Message) ProtoMessage()    {}

func (m *Event_Message) GetSlaveId() *mesos.SlaveID {
	if m != nil {
		return m.SlaveId
	}
	return nil
}

func (m *Event_Message) GetExecutorId() *mesos.ExecutorID {
	if m != nil {
		return m.ExecutorId
	}
	return nil
}

func (m *Event_Message) GetData() []byte {
	if m != nil {
		return m.Data
	}
	return nil
}

type Event_Failure struct {
	SlaveId          *mesos.SlaveID    `protobuf:"bytes,1,opt,name=slave_id" json:"slave_id,omitempty"`
	ExecutorId       *mesos.ExecutorID `protobuf:"bytes,2,opt,name=executor_id" json:"executor_id,omitempty"`
	Status           *int32            `protobuf:"varint,3,opt,name=status" json:"status,omitempty"`
	XXX_unrecognized []byte            `json:"-"`
}

func (m *Event_Failure) Reset()         { *m = Event_Failure{} }
func (m *Event_Failure) String() string { return proto.CompactTextString(m) }
func (*Event_Failure) ProtoMessage()    {}

func (m *Event_Failure) GetSlaveId() *mesos.SlaveID {
	if m != nil {
		return m.SlaveId
	}
	return nil
}

func (m *Event_Failure) GetExecutorId() *mesos.ExecutorID {
	if m != nil {
		return m.ExecutorId
	}
	return nil
}

func (m *Event_Failure) GetStatus() int32 {
	if m != nil && m.Status != nil {
		return *m.Status
	}
	return 0
}

type Event_Error struct {
	Message          *string `protobuf:"bytes,1,req,name=message" json:"message,omitempty"`
	XXX_unrecognized []byte  `json:"-"`
}

func (m *Event_Error) Reset()         { *m = Event_Error{} }
func (m *Event_Error) String() string { return proto.CompactTextString(m) }
func (*Event_Error) ProtoMessage()    {}

func (m *Event_Error) GetMessage() string {
	if m != nil && m.Message != nil {
		return *m.Message
	}
	return ""
}

type Call struct {
	FrameworkInfo    *mesos.FrameworkInfo `protobuf:"bytes,1,req,name=framework_info" json:"framework_info,omitempty"`
	Type             *Call_Type           `protobuf:"varint,2,req,name=type,enum=mesos.scheduler.Call_Type" json:"type,omitempty"`
	Request          *Call_Request        `protobuf:"bytes,3,opt,name=request" json:"request,omitempty"`
	Decline          *Call_Decline        `protobuf:"bytes,4,opt,name=decline" json:"decline,omitempty"`
	Launch           *Call_Launch         `protobuf:"bytes,5,opt,name=launch" json:"launch,omitempty"`
	Kill             *Call_Kill           `protobuf:"bytes,6,opt,name=kill" json:"kill,omitempty"`
	Acknowledge      *Call_Acknowledge    `protobuf:"bytes,7,opt,name=acknowledge" json:"acknowledge,omitempty"`
	Reconcile        *Call_Reconcile      `protobuf:"bytes,8,opt,name=reconcile" json:"reconcile,omitempty"`
	Message          *Call_Message        `protobuf:"bytes,9,opt,name=message" json:"message,omitempty"`
	XXX_unrecognized []byte               `json:"-"`
}

func (m *Call) Reset()         { *m = Call{} }
func (m *Call) String() string { return proto.CompactTextString(m) }
func (*Call) ProtoMessage()    {}

func (m *Call) GetFrameworkInfo() *mesos.FrameworkInfo {
	if m != nil {
		return m.FrameworkInfo
	}
	return nil
}

func (m *Call) GetType() Call_Type {
	if m != nil && m.Type != nil {
		return *m.Type
	}
	return 0
}

func (m *Call) GetRequest() *Call_Request {
	if m != nil {
		return m.Request
	}
	return nil
}

func (m *Call) GetDecline() *Call_Decline {
	if m != nil {
		return m.Decline
	}
	return nil
}

func (m *Call) GetLaunch() *Call_Launch {
	if m != nil {
		return m.Launch
	}
	return nil
}

func (m *Call) GetKill() *Call_Kill {
	if m != nil {
		return m.Kill
	}
	return nil
}

func (m *Call) GetAcknowledge() *Call_Acknowledge {
	if m != nil {
		return m.Acknowledge
	}
	return nil
}

func (m *Call) GetReconcile() *Call_Reconcile {
	if m != nil {
		return m.Reconcile
	}
	return nil
}

func (m *Call) GetMessage() *Call_Message {
	if m != nil {
		return m.Message
	}
	return nil
}

type Call_Request struct {
	Requests         []*mesos.Request `protobuf:"bytes,1,rep,name=requests" json:"requests,omitempty"`
	XXX_unrecognized []byte           `json:"-"`
}

func (m *Call_Request) Reset()         { *m = Call_Request{} }
func (m *Call_Request) String() string { return proto.CompactTextString(m) }
func (*Call_Request) ProtoMessage()    {}

func (m *Call_Request) GetRequests() []*mesos.Request {
	if m != nil {
		return m.Requests
	}
	return nil
}

type Call_Decline struct {
	OfferIds         []*mesos.OfferID `protobuf:"bytes,1,rep,name=offer_ids" json:"offer_ids,omitempty"`
	Filters          *mesos.Filters   `protobuf:"bytes,2,opt,name=filters" json:"filters,omitempty"`
	XXX_unrecognized []byte           `json:"-"`
}

func (m *Call_Decline) Reset()         { *m = Call_Decline{} }
func (m *Call_Decline) String() string { return proto.CompactTextString(m) }
func (*Call_Decline) ProtoMessage()    {}

func (m *Call_Decline) GetOfferIds() []*mesos.OfferID {
	if m != nil {
		return m.OfferIds
	}
	return nil
}

func (m *Call_Decline) GetFilters() *mesos.Filters {
	if m != nil {
		return m.Filters
	}
	return nil
}

type Call_Launch struct {
	TaskInfos        []*mesos.TaskInfo `protobuf:"bytes,1,rep,name=task_infos" json:"task_infos,omitempty"`
	OfferIds         []*mesos.OfferID  `protobuf:"bytes,2,rep,name=offer_ids" json:"offer_ids,omitempty"`
	Filters          *mesos.Filters    `protobuf:"bytes,3,opt,name=filters" json:"filters,omitempty"`
	XXX_unrecognized []byte            `json:"-"`
}

func (m *Call_Launch) Reset()         { *m = Call_Launch{} }
func (m *Call_Launch) String() string { return proto.CompactTextString(m) }
func (*Call_Launch) ProtoMessage()    {}

func (m *Call_Launch) GetTaskInfos() []*mesos.TaskInfo {
	if m != nil {
		return m.TaskInfos
	}
	return nil
}

func (m *Call_Launch) GetOfferIds() []*mesos.OfferID {
	if m != nil {
		return m.OfferIds
	}
	return nil
}

func (m *Call_Launch) GetFilters() *mesos.Filters {
	if m != nil {
		return m.Filters
	}
	return nil
}

type Call_Kill struct {
	TaskId           *mesos.TaskID `protobuf:"bytes,1,req,name=task_id" json:"task_id,omitempty"`
	XXX_unrecognized []byte        `json:"-"`
}

func (m *Call_Kill) Reset()         { *m = Call_Kill{} }
func (m *Call_Kill) String() string { return proto.CompactTextString(m) }
func (*Call_Kill) ProtoMessage()    {}

func (m *Call_Kill) GetTaskId() *mesos.TaskID {
	if m != nil {
		return m.TaskId
	}
	return nil
}

type Call_Acknowledge struct {
	SlaveId          *mesos.SlaveID `protobuf:"bytes,1,req,name=slave_id" json:"slave_id,omitempty"`
	TaskId           *mesos.TaskID  `protobuf:"bytes,2,req,name=task_id" json:"task_id,omitempty"`
	Uuid             []byte         `protobuf:"bytes,3,req,name=uuid" json:"uuid,omitempty"`
	XXX_unrecognized []byte         `json:"-"`
}

func (m *Call_Acknowledge) Reset()         { *m = Call_Acknowledge{} }
func (m *Call_Acknowledge) String() string { return proto.CompactTextString(m) }
func (*Call_Acknowledge) ProtoMessage()    {}

func (m *Call_Acknowledge) GetSlaveId() *mesos.SlaveID {
	if m != nil {
		return m.SlaveId
	}
	return nil
}

func (m *Call_Acknowledge) GetTaskId() *mesos.TaskID {
	if m != nil {
		return m.TaskId
	}
	return nil
}

func (m *Call_Acknowledge) GetUuid() []byte {
	if m != nil {
		return m.Uuid
	}
	return nil
}

type Call_Reconcile struct {
	Statuses         []*mesos.TaskStatus `protobuf:"bytes,1,rep,name=statuses" json:"statuses,omitempty"`
	XXX_unrecognized []byte              `json:"-"`
}

func (m *Call_Reconcile) Reset()         { *m = Call_Reconcile{} }
func (m *Call_Reconcile) String() string { return proto.CompactTextString(m) }
func (*Call_Reconcile) ProtoMessage()    {}

func (m *Call_Reconcile) GetStatuses() []*mesos.TaskStatus {
	if m != nil {
		return m.Statuses
	}
	return nil
}

type Call_Message struct {
	SlaveId          *mesos.SlaveID    `protobuf:"bytes,1,req,name=slave_id" json:"slave_id,omitempty"`
	ExecutorId       *mesos.ExecutorID `protobuf:"bytes,2,req,name=executor_id" json:"executor_id,omitempty"`
	Data             []byte            `protobuf:"bytes,3,req,name=data" json:"data,omitempty"`
	XXX_unrecognized []byte            `json:"-"`
}

func (m *Call_Message) Reset()         { *m = Call_Message{} }
func (m *Call_Message) String() string { return proto.CompactTextString(m) }
func (*Call_Message) ProtoMessage()    {}

func (m *Call_Message) GetSlaveId() *mesos.SlaveID {
	if m != nil {
		return m.SlaveId
	}
	return nil
}

func (m *Call_Message) GetExecutorId() *mesos.ExecutorID {
	if m != nil {
		return m.ExecutorId
	}
	return nil
}

func (m *Call_Message) GetData() []byte {
	if m != nil {
		return m.Data
	}
	return nil
}

func init() {
	proto.RegisterEnum("mesos.scheduler.Event_Type", Event_Type_name, Event_Type_value)
	proto.RegisterEnum("mesos.scheduler.Call_Type", Call_Type_name, Call_Type_value)
}


text:
<?php

namespace Zicht\Bundle\PageBundle\Type;

use Doctrine\Bundle\DoctrineBundle\Registry;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Zicht\Util\Str;

/**
 * Provides a dropdown to select a type specified by doctrine's discriminator map.
 */
class DiscriminatorMapType extends ChoiceType
{
    /** @var Registry|null */
    private $doctrine = null;

    public function __construct(Registry $registry)
    {
        parent::__construct();
        $this->doctrine = $registry;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        parent::configureOptions($resolver);

        /** @var $em \Doctrine\ORM\EntityManager */
        $em = $this->doctrine->getManager();

        $choiceCallback = function (Options $options) use ($em) {
            $ret = [];
            foreach ($em->getClassMetadata($options['entity'])->discriminatorMap as $className) {
                $placeholder = 'content_item.type.' . strtolower(str_replace(' ', '_', Str::humanize($className)));
                $ret[$className] = $placeholder;
            }
            if (is_callable($options['choice_filter'])) {
                $ret = call_user_func($options['choice_filter'], $ret);
            }
            return $ret;
        };

        $resolver
            ->setRequired(['entity'])
            ->setDefaults(
                [
                    'choices' => $choiceCallback,
                    'choice_filter' => '',
                    'translation_domain' => 'admin',
                ]
            );
    }

    public function getParent()
    {
        return ChoiceType::class;
    }

    public function getBlockPrefix()
    {
        return 'zicht_discriminator_map';
    }
}

redpajama_set_name: RedPajamaGithub


text:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>

#include "decoding.h"
#include "decoding.h"
#include "matrix.h"
#include "fichier.h"
#include "poly.h"
#include "param.h"
#include "util.h"
#include "randombytes.h"

/**
 * @file key_gen.h
 * @brief File that contains the key pair generation.
 *
 *The file contains the key generation elements, i.e,
 *The quasi-dyadic-signature and cauchy support  generation.
 */

/**
 * @brief check if the vectors are disjoint
 * @param u - input vector.
 * @param v - the other vector to check.
 *
 * @return @result if it is disjoint it will be 0 if not wil return -1.
 */
int disjoint_test(gf *u, gf *v);

/**
 * @brief Method to generate a random vector.
 * @param m size of random bits.
 * @param vect pointer that will be written the bits.
 */
void generate_random_vector(int m, gf *vect);

/**
 * @brief Method to initialize a vector.
 * @param U vector that will be initialize.
 *
 */
void init_random_element(gf *U);

/**
 * @brief Binary quasi dyadic signature
 * @param m size of code word.
 * @param n value to check when stop at the first non-zero element of V.
 * @param t
 * @param b auxiliar.
 * @param h_sig element that will receive the signature.
 * @param w element to be signed.
 *
 */
void binary_quasi_dyadic_sig(int m, int n, int t, int *b, gf *h_sig, gf *w);

/**
 * @brief Binary Cauchy support
 * @param support element to be the support
 * @param u input vector to be used
 * @param w input vector to be used
 *
 */
void cauchy_support(gf *support, gf *u, gf *w);

/**
 * @brief Key pair generation
 * @param pk string that will be stored the public key
 * @param sk string that will be sotred the secret key
 *
 * @return It will back 0 if it was possible to generate both keys
 * and it will return != 0 if it wasn't possible to generate keys.
 *
 */
int key_pair(unsigned char *pk, unsigned char *sk);


text:
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2016-2018. All Rights Reserved.
* SPDX-License-Identifier: MIT
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""

__author__ = 'VMware, Inc.'
__vcenter_version__ = '6.5+'

from vmware.vapi.vsphere.client import create_vsphere_client

from com.vmware.vcenter.vm.hardware.adapter_client import Sata
from samples.vsphere.common.sample_util import pp, \
    parse_cli_args_vm
from samples.vsphere.vcenter.setup import testbed

from samples.vsphere.vcenter.helper.vm_helper import get_vm
from samples.vsphere.common.ssl_helper import get_unverified_session

"""
Demonstrates how to configure virtual SATA adapters of a virtual machine.

Sample Prerequisites:
The sample needs an existing VM.
"""

vm = None
vm_name = None
client = None
cleardata = False
satas_to_delete = []
orig_sata_summaries = None

def setup(context=None):
    global vm, vm_name, client, cleardata
    if context:
        # Run sample suite via setup script
        client = context.client
        vm_name = testbed.config['VM_NAME_DEFAULT']
    else:
        # Run sample in standalone mode
        server, username, password, cleardata, skip_verification, vm_name = \
            parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
        session = get_unverified_session() if skip_verification else None

        # Connect to vSphere client
        client = create_vsphere_client(server=server,
                                       username=username,
                                       password=password,
                                       session=session)

def run():
    global vm
    vm = get_vm(client, vm_name)
    if not vm:
        raise Exception('Sample requires an existing vm with name ({}). '
                        'Please create the vm first.'.format(vm_name))
    print("Using VM '{}' ({}) for SATA Sample".format(vm_name, vm))

    print('\n# Example: List all SATA adapters for a VM')
    sata_summaries = client.vcenter.vm.hardware.adapter.Sata.list(vm=vm)
    print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))

    # Save current list of SATA adapters to verify that we have cleaned up
    # properly
    global orig_sata_summaries
    orig_sata_summaries = sata_summaries

    # Get information for each SATA adapter on the VM
    for sata_summary in sata_summaries:
        sata = sata_summary.adapter
        sata_info = client.vcenter.vm.hardware.adapter.Sata.get(vm=vm, adapter=sata)
        print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.
              format(vm, sata, pp(sata_info)))

    global satas_to_delete

    print('\n# Example: Create SATA adapter with defaults')
    sata_create_spec = Sata.CreateSpec()
    sata = client.vcenter.vm.hardware.adapter.Sata.create(vm, sata_create_spec)
    print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.
          format(vm, sata_create_spec, sata))
    satas_to_delete.append(sata)
    sata_info = client.vcenter.vm.hardware.adapter.Sata.get(vm, sata)
    print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.
          format(vm, sata, pp(sata_info)))

    print('\n# Example: Create SATA adapter with a specific bus')
    sata_create_spec = Sata.CreateSpec(bus=2)
    sata = client.vcenter.vm.hardware.adapter.Sata.create(vm, sata_create_spec)
    print('vm.hardware.adapter.Sata.create({}, {}) -> {}'.
          format(vm, sata_create_spec, sata))
    satas_to_delete.append(sata)
    sata_info = client.vcenter.vm.hardware.adapter.Sata.get(vm, sata)
    print('vm.hardware.adapter.Sata.get({}, {}) -> {}'.
          format(vm, sata, pp(sata_info)))

    # List all SATA adapters for a VM
    sata_summaries = client.vcenter.vm.hardware.adapter.Sata.list(vm=vm)
    print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))

def cleanup():
    print('\n# Cleanup: Delete VM SATA adapters that were added')
    for sata in satas_to_delete:
        client.vcenter.vm.hardware.adapter.Sata.delete(vm, sata)
        print('vm.hardware.adapter.Sata.delete({}, {})'.format(vm, sata))

    sata_summaries = client.vcenter.vm.hardware.adapter.Sata.list(vm)
    print('vm.hardware.adapter.Sata.list({}) -> {}'.format(vm, sata_summaries))
    if set(orig_sata_summaries) != set(sata_summaries):
        print('vm.hardware.adapter.Sata WARNING: '
              'Final SATA adapters info does not match original')

def main():
    setup()
    run()
    if cleardata:
        cleanup()

if __name__ == '__main__':
    main()


text:
from __future__ import absolute_import, division, print_function

import os

import pytest
import xmltodict

from ramlfications import parser as pw
from ramlfications.config import setup_config
from ramlfications.raml import RootNode, ResourceTypeNode, TraitNode
from ramlfications._helpers import load_file

from .base import EXAMPLES

@pytest.fixture(scope="session")
def loaded_raml():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    return load_file(raml_file)

@pytest.fixture(scope="session")
def root():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.create_root(loaded_raml_file, config)

def test_parse_raml(loaded_raml):
    config = setup_config(EXAMPLES + "test-config.ini")
    root = pw.parse_raml(loaded_raml, config)
    assert isinstance(root, RootNode)

def test_create_root(root):
    assert isinstance(root, RootNode)

def test_base_uri(root):
    expected = "https://{subdomain}.example.com/v1/{communityPath}"
    assert expected == root.base_uri

def test_protocols(root):
    expected = ["HTTPS"]
    assert expected == root.protocols

def test_docs(root):
    exp_title = "Example Web API Docs"
    exp_content = ("Welcome to the _Example Web API_ demo specification. "
                   "This is *not* the complete API\nspecification, and is "
                   "meant for testing purposes within this RAML "
                   "specification.\n")

    assert exp_title == root.documentation[0].title.raw
    assert exp_title == repr(root.documentation[0].title)
    assert exp_content == root.documentation[0].content.raw
    assert exp_content == repr(root.documentation[0].content)

    title_html = "
Example Web API Docs
\n"
    content_html = ("
Welcome to the Example Web API demo "
                    "specification. This is not the complete API\n"
                    "specification, and is meant for testing purposes within "
                    "this RAML specification.
\n")
    assert title_html == root.documentation[0].title.html
    assert content_html == root.documentation[0].content.html

def test_base_uri_params(root):
    exp_name = "subdomain"
    exp_desc = "subdomain of API"
    exp_desc_html = "
subdomain of API
\n"
    exp_default = "api"

    assert exp_name == root.base_uri_params[0].name
    assert exp_desc == root.base_uri_params[0].description.raw
    assert exp_desc_html == root.base_uri_params[0].description.html
    assert exp_default == root.base_uri_params[0].default

def test_uri_params(root):
    assert root.uri_params[0].name == "communityPath"
    assert root.uri_params[0].display_name == "Community Path"
    assert root.uri_params[0].type == "string"
    assert root.uri_params[0].min_length == 1
    assert root.uri_params[0].description is None
    assert not hasattr(root.uri_params[0].description, "raw")
    assert not hasattr(root.uri_params[0].description, "html")
    assert root.uri_params[0].default is None
    assert root.uri_params[0].enum is None
    assert root.uri_params[0].example is None

def test_title(root):
    exp_name = "Example Web API"
    assert exp_name == root.title

def test_version(root):
    exp_version = "v1"
    assert exp_version == root.version

def test_schemas(root):
    thingy_json_schema = {'Thingy': {'name': 'New Thingy', 'public': False}}
    assert thingy_json_schema == root.schemas[0]

    thingy_xsd_schema = {
        'ThingyXsd': {
            'xs:schema': {
                '@attributeFormDefault': 'unqualified',
                '@elementFormDefault': 'qualified',
                '@xmlns:xs': 'http://www.w3.org/2001/XMLSchema',
                'xs:element': {
                    '@name': 'thingy',
                    '@type': 'thingyType'
                },
                'xs:complexType': {
                    '@name': 'thingyType',
                    'xs:sequence': {
                        'xs:element': {
                            '@type': 'xs:string',
                            '@name': 'name',
                            '@minOccurs': '1',
                            '@maxOccurs': '1'
                        }
                    }
                }
            }
        }
    }
    assert thingy_xsd_schema == root.schemas[1]

    thingy_xsd_list_schema = {
        'ThingyListXsd': {
            'xs:schema': {
                '@attributeFormDefault': 'unqualified',
                '@elementFormDefault': 'qualified',
                '@xmlns:xs': 'http://www.w3.org/2001/XMLSchema',
                'xs:include': {
                    '@schemaLocation': './thingy.xsd'
                },
                'xs:element': {
                    '@name': 'thingies',
                    'xs:complexType': {
                        'xs:sequence': {
                            '@minOccurs': '0',
                            '@maxOccurs': 'unbounded',
                            'xs:element': {
                                '@type': 'thingyType',
                                '@name': 'thingy'
                            }
                        }
                    }
                }
            }
        }
    }
    assert thingy_xsd_list_schema == root.schemas[2]

def test_media_type(root):
    exp_media_type = "application/json"
    assert exp_media_type == root.media_type

@pytest.fixture(scope="session")
def api():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)

#####
# Test Security Schemes
#####
@pytest.fixture(scope="session")
def sec_schemes():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    api = pw.parse_raml(loaded_raml_file, config)
    return api.security_schemes

def test_create_security_schemes(sec_schemes):
    assert len(sec_schemes) == 3
    assert sec_schemes[0].name == "oauth_2_0"
    assert sec_schemes[0].type == "OAuth 2.0"

    desc = ("Example API supports OAuth 2.0 for authenticating all API "
            "requests.\n")
    assert sec_schemes[0].description.raw == desc

    assert len(sec_schemes[0].headers) == 2
    assert sec_schemes[0].headers[0].name == "Authorization"
    assert sec_schemes[0].headers[1].name == "X-Foo-Header"

    assert len(sec_schemes[0].responses) == 2
    assert sec_schemes[0].responses[0].code == 401

    desc = ("Bad or expired token. This can happen if the user revoked a "
            "token or\nthe access token has expired. You should "
            "re-authenticate the user.\n")
    assert sec_schemes[0].responses[0].description.raw == desc

    assert sec_schemes[0].responses[1].code == 403

    desc = ("Bad OAuth request (wrong consumer key, bad nonce, expired\n"
            "timestamp...). Unfortunately, re-authenticating the user won't "
            "help here.\n")
    assert sec_schemes[0].responses[1].description.raw == desc

    settings = {
        "authorizationUri": "https://accounts.example.com/authorize",
        "accessTokenUri": "https://accounts.example.com/api/token",
        "authorizationGrants": ["code", "token"],
        "scopes": [
            "user-public-profile",
            "user-email",
            "user-activity",
            "nsa-level-privacy"
        ]
    }
    assert sec_schemes[0].settings == settings

def test_create_security_schemes_custom(sec_schemes):
    custom = sec_schemes[1]

    assert custom.name == "custom_auth"
    assert custom.type == "Custom Auth"
    assert len(custom.uri_params) == 1
    assert len(custom.form_params) == 1
    assert len(custom.query_params) == 1
    assert len(custom.body) == 1

    assert custom.uri_params[0].name == "subDomain"
    assert custom.query_params[0].name == "fooQParam"
    assert custom.form_params[0].name == "fooFormParam"
    assert custom.body[0].mime_type == "application/x-www-form-urlencoded"

    assert custom.documentation[0].title.raw == "foo docs"
    assert custom.documentation[0].content.raw == "foo content"

def test_security_scheme_no_desc(sec_schemes):
    no_desc = sec_schemes[2]

    assert no_desc.name == "no_desc"
    assert no_desc.description is None

#####
# Test Traits
#####
@pytest.fixture(scope="session")
def traits():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    api = pw.parse_raml(loaded_raml_file, config)
    return api.traits

def test_create_traits(api):
    for trait in api.traits:
        assert isinstance(trait, TraitNode)

def test_trait_query_params(traits):
    trait = traits[0]
    assert trait.name == "filterable"
    assert trait.usage == "Some description about using filterable"
    assert trait.query_params[0].name == "fields"
    assert trait.query_params[0].type == "string"
    assert trait.query_params[0].display_name == "Fields"

    example = "gizmos.items(added_by.id,gizmo(name,href,widget(name,href)))"
    assert trait.query_params[0].example == example

def test_trait_headers(traits):
    trait = traits[0]
    assert trait.headers[0].name == "X-example-header"
    assert trait.headers[0].description.raw == "An example of a trait header"
    html_desc = "
An example of a trait header
\n"
    assert trait.headers[0].description.html == html_desc

def test_trait_body(traits):
    trait = traits[0]
    assert trait.body[0].mime_type == "application/json"
    assert trait.body[0].schema == {"name": "string"}
    assert trait.body[0].example == {"name": "example body for trait"}

def test_trait_uri_params(traits):
    trait = traits[4]
    assert trait.uri_params[0].name == "communityPath"
    assert trait.uri_params[0].type == "string"
    assert trait.uri_params[0].example == 'baz-community'

    desc = "The community path URI params trait"
    assert trait.uri_params[0].description.raw == desc
    assert repr(trait.uri_params[0].description) == desc

    desc_html = "
The community path URI params trait
\n"
    assert trait.uri_params[0].description.html == desc_html

def test_trait_form_params(traits):
    trait = traits[2]
    assert trait.form_params[0].name == "foo"
    assert trait.form_params[0].display_name == "Foo"
    assert trait.form_params[0].type == "string"
    assert trait.form_params[0].default == "bar"
    assert trait.form_params[0].min_length == 5
    assert trait.form_params[0].max_length == 50
    assert trait.form_params[0].description.raw == "The Foo Form Field"

    trait_desc = "A description of a trait with form parameters"
    assert trait.description.raw == trait_desc
    media_type = "application/x-www-form-urlencoded"
    assert trait.media_type == media_type

def test_trait_base_uri_params(traits):
    trait = traits[3]
    assert trait.base_uri_params[0].name == "communityPath"
    assert trait.base_uri_params[0].display_name == "Community Path trait"
    assert trait.base_uri_params[0].type == "string"
    assert trait.base_uri_params[0].example == "baz-community"

    param_desc = "The community path base URI trait"
    assert trait.base_uri_params[0].description.raw == param_desc

    trait_desc = "A description of a trait with base URI parameters"
    assert trait.description.raw == trait_desc

#####
# Test Resource Types
#####
@pytest.fixture(scope="session")
def resource_types():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    api = pw.parse_raml(loaded_raml_file, config)
    return api.resource_types

def test_create_resource_types(api):
    for res_type in api.resource_types:
        assert isinstance(res_type, ResourceTypeNode)

def test_resource_type(resource_types):
    resource_type = resource_types[0]
    assert resource_type.name == "base"
    assert resource_type.method == "get"
    assert resource_type.optional
    assert resource_type.is_ is None
    assert resource_type.traits is None

    header = resource_type.headers[0]
    assert header.name == "Accept"
    assert header.method == "get"
    assert header.type == "string"
    assert header.description.raw == "Is used to set specified media type."
    assert header.example is None
    assert header.default is None
    assert header.required is False

    body = resource_type.body[0]
    assert body.mime_type == "application/json"
    assert body.schema == {"name": "string"}
    assert body.example == {"name": "Foo Bar"}
    assert body.form_params is None

    response = resource_type.responses[0]
    assert response.code == 403

    desc = ("API rate limit exceeded.\n")
    assert response.description.raw == desc
    assert response.method == "get"

    resp_header = response.headers[0]
    assert resp_header.name == "X-waiting-period"

    resp_desc = ("The number of seconds to wait before you can attempt to "
                 "make a request again.\n")
    assert resp_header.description.raw == resp_desc
    assert resp_header.type == "integer"
    assert resp_header.required

    # TODO: add types to Header object
    assert resp_header.minimum == 1
    assert resp_header.maximum == 3600
    assert resp_header.example == 34

    resp_body = response.body[0]
    assert resp_body.mime_type == "application/json"
    assert resp_body.schema == {"name": "string"}
    assert resp_body.example == {"name": "Foo Bar"}
    assert resp_body.form_params is None

def test_resource_type_method_protocol(resource_types):
    resource = resource_types[-4]
    assert resource.name == "protocolExampleType"
    assert resource.protocols == ["HTTP"]

def test_resource_type_uri_params(resource_types):
    uri_param = resource_types[0].uri_params[0]
    assert uri_param.name == "mediaTypeExtension"

    desc = "Use .json to specify application/json media type."
    assert uri_param.description.raw == desc
    assert uri_param.enum == [".json"]
    assert uri_param.min_length is None
    assert uri_param.type == "string"
    assert uri_param.required
    assert uri_param.default is None

def test_resource_type_query_params(resource_types):
    res = resource_types[3]
    assert res.name == "queryParamType"
    query_param = res.query_params[0]
    assert query_param.name == "ids"
    assert query_param.description.raw == "A comma-separated list of IDs"
    assert query_param.display_name == "Some sort of IDs"
    assert query_param.type == "string"
    assert query_param.required

def test_resource_type_form_params(resource_types):
    res = resource_types[4]
    assert res.name == "formParamType"
    form_param = res.form_params[0]
    assert form_param.name == "aFormParam"
    assert form_param.description.raw == "An uncreative form parameter"
    assert form_param.display_name == "Some sort of Form Parameter"
    assert form_param.type == "string"
    assert form_param.required

def test_resource_type_base_uri_params(resource_types):
    res = resource_types[5]
    assert res.name == "baseUriType"
    base_uri_params = res.base_uri_params[0]
    assert base_uri_params.name == "subdomain"

    desc = "subdomain for the baseUriType resource type"
    assert base_uri_params.description.raw == desc

    assert base_uri_params.default == "fooBar"

def test_resource_type_properties(resource_types):
    another_example = resource_types[6]
    assert another_example.name == "anotherExample"

    desc = "Another Resource Type example"
    assert another_example.description.raw == desc

    usage = "Some sort of usage description"
    assert another_example.usage == usage

    assert another_example.optional is False
    assert another_example.media_type == "text/xml"

def test_resource_type_inherited(resource_types):
    inherited = resource_types[9]
    assert inherited.type == "base"
    assert inherited.usage == "Some sort of usage text"
    assert inherited.display_name == "inherited example"

    inherited_response = inherited.responses[1]
    assert inherited_response.code == 403

    new_response = inherited.responses[2]
    assert new_response.code == 500

def test_resource_type_with_trait(resource_types):
    another_example = resource_types[6]
    assert another_example.is_ == ["filterable"]

    trait = another_example.traits[0]
    assert trait.name == "filterable"

    query_param = trait.query_params[0]
    assert query_param.name == "fields"
    assert query_param.display_name == "Fields"
    assert query_param.type == "string"

    desc = "A comma-separated list of fields to filter query"
    assert query_param.description.raw == desc

    example = "gizmos.items(added_by.id,gizmo(name,href,widget(name,href)))"
    assert query_param.example == example

def test_resource_type_secured_by(resource_types):
    another_example = resource_types[6]
    assert another_example.secured_by == ["oauth_2_0"]

    scheme = another_example.security_schemes[0]
    assert scheme.name == "oauth_2_0"
    assert scheme.type == "OAuth 2.0"

    desc = ("Example API supports OAuth 2.0 for authenticating all API "
            "requests.\n")
    assert scheme.description.raw == desc

    desc_by = {
        "headers": {
            "Authorization": {
                "description": "Used to send a valid OAuth 2 access token.\n",
                "type": "string"
            },
            "X-Foo-Header": {
                "description": "a foo header",
                "type": "string"
            }
        },
        "responses": {
            401: {
                "description": ("Bad or expired token. This can happen if the "
                                "user revoked a token or\nthe access token "
                                "has expired. You should re-authenticate the "
                                "user.\n")
            },
            403: {
                "description": ("Bad OAuth request (wrong consumer key, bad "
                                "nonce, expired\ntimestamp...). Unfortunately,"
                                " re-authenticating the user won't help "
                                "here.\n")
            }
        }
    }
    assert scheme.described_by == desc_by

    settings = {
        "authorizationUri": "https://accounts.example.com/authorize",
        "accessTokenUri": "https://accounts.example.com/api/token",
        "authorizationGrants": ["code", "token"],
        "scopes": [
            "user-public-profile",
            "user-email",
            "user-activity",
            "nsa-level-privacy"
        ]
    }
    assert scheme.settings == settings

def test_resource_type_empty_mapping():
    raml_file = os.path.join(EXAMPLES + "empty-mapping-resource-type.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    assert len(api.resource_types) == 1

    res = api.resource_types[0]

    assert res.name == "emptyType"
    assert res.raw == {}

def test_resource_type_empty_mapping_headers():
    raml_file = os.path.join(EXAMPLES + "empty-mapping.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    base_res_type = api.resource_types[0]

    assert len(base_res_type.headers) == 3
    assert base_res_type.headers[-1].description is None

#####
# Test Resources
#####
@pytest.fixture(scope="session")
def resources():
    raml_file = os.path.join(EXAMPLES + "complete-valid-example.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    api = pw.parse_raml(loaded_raml_file, config)
    return api.resources

def test_resource_properties(resources):
    assert resources[0].name == "/widgets"
    assert resources[0].display_name == "several-widgets"
    assert resources[0].method == "get"
    assert resources[0].protocols == ["HTTPS"]
    assert resources[0].media_type == "application/xml"

    assert resources[1].parent.name == "/widgets"
    assert resources[1].path == "/widgets/{id}"

    abs_uri = "http://{subdomain}.example.com/v1/{communityPath}/widgets/{id}"
    assert resources[1].absolute_uri == abs_uri
    assert resources[1].media_type == "application/xml"
    assert resources[1].protocols == ["HTTP"]

    assert resources[2].is_ == ["paged"]
    # assert resources[2].media_type == "application/xml"
    assert resources[12].type == "collection"

    assert resources[3].media_type == "text/xml"

def test_resource_no_method_properties(resources):
    assert resources[-2].method is None
    assert resources[-2].name == "/no_method_properties"

    assert resources[-1].parent.name == resources[-2].name
    assert resources[-1].method == "get"

def test_resource_headers(resources):
    assert resources[0].headers[0].name == "X-bogus-header"
    desc = "just an extra header for funsies"
    assert resources[0].headers[0].description.raw == desc

def test_resource_inherited_properties(resources):
    res = resources[9]
    # actual object data will not match, just names
    res_uri = res.base_uri_params[0].name
    restype_uri = res.resource_type.base_uri_params[0].name
    assert res_uri  == restype_uri

    res = resources[-6]
    assert res.form_params[0] == res.resource_type.form_params[0]

    res = resources[11]
    assert res.is_ == ["protocolTrait"]
    assert res.traits[0].description.raw == "A trait to assign a protocol"
    assert res.traits[0].protocols == ["HTTP"]

def test_resource_assigned_type(resources):
    res = resources[19]

    assert res.display_name == "thingy"
    assert res.method == "get"
    assert res.type == "item"

    res_type_uri = [r.name for r in res.resource_type.uri_params]
    res_uri = [r.name for r in res.uri_params]

    exp_res_type_uri = ["mediaTypeExtension"]
    exp_res_uri = ["communityPath", "user_id", "thingy_id"]

    assert res_type_uri == exp_res_type_uri
    assert res_uri == exp_res_uri

    assert res.headers[0] == res.resource_type.headers[0]
    assert res.body[0] == res.resource_type.body[0]
    assert res.responses[0] == res.resource_type.responses[0]
    assert set([h.name for h in res.headers]) == set([
        "X-another-header",
        "Accept",
        "X-example-header",
    ])

    res = resources[18]
    assert res.type == "collection"
    assert res.method == "post"
    assert res.form_params[0] == res.resource_type.form_params[0]

    res = resources[11]
    assert res.type == "queryParamType"
    assert res.method == "get"
    assert res.resource_type.query_params[0] == res.query_params[0]

    res = resources[9]
    assert res.type == "baseUriType"
    assert res.method == "get"
    # actual object data will not match, just name
    res_uri = res.base_uri_params[0].name
    restype_uri = res.resource_type.base_uri_params[0].name
    assert res_uri == restype_uri

    res = resources[1]
    assert res.type == "protocolExampleType"
    assert res.resource_type.name == "protocolExampleType"
    assert res.protocols == res.resource_type.protocols

def test_resource_assigned_trait(resources):
    res = resources[10]

    assert res.name == "/search"
    assert res.is_ == ["paged"]
    assert res.traits[0].description.raw == "A description of the paged trait"
    assert res.traits[0].media_type == "application/xml"

    params = [p.name for p in res.query_params]
    t_params = [p.name for p in res.traits[0].query_params]

    for t in t_params:
        assert t in params

def test_resource_protocols(resources):
    res = resources[13]

    assert res.method == "put"
    assert res.name == "/widgets"

    assert res.protocols == ["HTTP"]

    res = resources[16]

    assert res.method == "get"
    assert res.name == "/users/{user_id}"
    assert res.protocols == ["HTTP"]

def test_resource_responses(resources):
    res = resources[17]

    assert res.responses[0].code == 200
    assert res.responses[0].body[0].mime_type == "application/json"
    assert res.responses[0].body[1].mime_type == "text/xml"
    assert len(res.responses[0].body) == 2

    json_schema = {
        "$schema": "http://json-schema.org/draft-03/schema",
        "type": "array",
        "items": {
            "$ref": "schemas/thingy.json"
        }
    }
    assert res.responses[0].body[0].schema == json_schema
    assert res.responses[0].body[1].schema == 'ThingyListXsd'

    res = resources[10]
    headers = [h.name for h in res.responses[0].headers]
    assert sorted(["X-search-header", "X-another-header"]) == sorted(headers)

    schema = res.responses[0].body[0].schema
    assert schema == {"name": "the search body"}

    schema = res.responses[0].body[1].schema
    assert schema == {}
    example = res.responses[0].body[1].example
    assert example == {}

    res = resources[19]
    headers = [h.name for h in res.responses[0].headers]
    assert "X-waiting-period" in headers
    body = res.responses[0].body[0].schema
    assert body == {"name": "string"}
    codes = [r.code for r in res.responses]
    assert [200, 403] == sorted(codes)

    res = resources[-9]

    assert res.path == "/users/{user_id}/thingys/{thingy_id}"
    assert res.type == "item"
    assert res.responses[0] == res.resource_type.responses[0]
    assert len(res.responses[0].headers) == 1
    assert res.responses[0].headers[0].name == "X-waiting-period"
    assert res.responses[0].headers[0].type == "integer"
    assert res.responses[0].headers[0].minimum == 1
    assert res.responses[0].headers[0].maximum == 3600
    assert res.responses[0].headers[0].example == 34

    desc = ("The number of seconds to wait before you can attempt to make "
            "a request again.\n")
    assert res.responses[0].headers[0].description.raw == desc

    res_response = res.responses[0].headers[0]
    res_type_resp = res.resource_type.responses[0].headers[0]
    assert res_response == res_type_resp

    res = resources[-10]

    assert res.display_name == "thingys"
    assert res.responses[0].code == 201
    assert res.responses[0].headers[0].name == "X-another-bogus-header"
    assert res.responses[0].headers[0].description.raw == "A bogus header"
    assert res.responses[0].body[0].mime_type == "application/json"
    assert res.responses[0].body[0].schema == "Thingy"

def test_resource_base_uri_params(resources):
    res = resources[2]

    assert res.display_name == "widget-gizmos"
    assert res.base_uri_params[0].name == "subdomain"

    # TODO: figure out what this issue is
    # desc = "subdomain for the baseUriType resource type"
    # assert res.base_uri_params[0].description.raw == desc
    # assert res.base_uri_params[0].default == "fooBar"

    res = resources[-12]
    assert len(res.base_uri_params) == 1
    assert res.display_name == "users-profile"
    assert res.base_uri_params[0].name == "subdomain"
    assert res.base_uri_params[0].default == "barFoo"

    desc = "a test base URI parameter for resource-level"
    assert res.base_uri_params[0].description.raw == desc

def test_resource_form_params(resources):
    res = resources[-3]

    assert res.display_name == "formParamResource"
    assert res.description.raw == "A example resource with form parameters"
    assert res.form_params[0].name == "foo"
    assert res.form_params[0].description.raw == "Post some foo"
    assert res.form_params[0].type == "string"
    assert res.form_params[0].required
    assert res.form_params[0].min_length == 10
    assert res.form_params[0].max_length == 100

    assert res.form_params[1].name == "bar"
    assert res.form_params[1].description.raw == "Post some bar"
    assert res.form_params[1].type == "string"
    assert res.form_params[1].required is False
    assert res.form_params[1].min_length == 15
    assert res.form_params[1].max_length == 150
    assert res.form_params[1].default == "aPostedBarExample"

def test_resource_security_scheme(resources):
    res = resources[17]
    assert res.method == "get"
    assert res.name == "/users/{user_id}/thingys"
    assert res.secured_by == [
        {"oauth_2_0": {"scopes": ["thingy-read-private"]}}
    ]
    assert res.security_schemes[0].name == "oauth_2_0"

def test_resource_inherit_parent(resources):
    res = resources[2]
    assert len(res.uri_params) == 2

def test_resource_response_no_desc():
    raml_file = os.path.join(EXAMPLES + "empty-mapping.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    api = pw.parse_raml(loaded_raml_file, config)

    res = api.resources[-1]
    response = res.responses[-1]

    assert response.code == 204
    assert response.description is None

@pytest.fixture(scope="session")
def inherited_resources():
    raml_file = os.path.join(EXAMPLES, "resource-type-inherited.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config["validate"] = False
    return pw.parse_raml(loaded_raml, config)

def test_resource_inherits_type(inherited_resources):
    assert len(inherited_resources.resources) == 7
    res = inherited_resources.resources[0]
    assert res.type == "inheritgetmethod"
    assert res.method == "get"
    assert len(res.headers) == 1
    assert len(res.body) == 1
    assert len(res.responses) == 2
    assert len(res.query_params) == 1

    exp_desc = ("This description should be inherited when applied to "
                "resources")
    assert res.description.raw == exp_desc

    h = res.headers[0]
    assert h.name == "X-Inherited-Header"
    assert h.description.raw == "This header should be inherited"

    b = res.body[0]
    assert b.mime_type == "application/json"
    # lazy checking
    assert b.schema is not None
    assert b.example is not None

    q = res.query_params[0]
    assert q.name == "inherited_param"
    assert q.display_name == "inherited query parameter for a get method"
    assert q.type == "string"
    assert q.description.raw == "description for inherited query param"
    assert q.example == "fooBar"
    assert q.min_length == 1
    assert q.max_length == 50
    assert q.required is True

def test_res_type_inheritance(inherited_resources):
    res = inherited_resources.resource_types[0]
    assert res.name == "basetype"
    assert len(res.query_params) == 1
    assert len(res.form_params) == 1
    assert len(res.uri_params) == 1
    assert len(res.base_uri_params) == 1

    res = inherited_resources.resource_types[-1]
    assert res.name == "inheritbase"
    assert len(res.query_params) == 2
    assert len(res.form_params) == 2
    assert len(res.uri_params) == 2
    assert len(res.base_uri_params) == 2

def test_resource_inherits_type_optional_post(inherited_resources):
    assert len(inherited_resources.resources) == 7
    res = inherited_resources.resources[1]
    assert res.type == "inheritgetoptionalmethod"
    assert res.method == "post"
    assert res.headers is None
    assert res.query_params is None
    assert res.description.raw == "post some foobar"

def test_resource_inherits_type_optional_get(inherited_resources):
    # make sure that optional resource type methods are not inherited if not
    # explicitly included in resource (unless no methods defined)
    assert len(inherited_resources.resources) == 7
    res = inherited_resources.resources[2]
    assert res.type == "inheritgetoptionalmethod"
    assert res.method == "get"
    assert len(res.headers) == 2
    assert len(res.query_params) == 1

    desc = ("This description should be inherited when applied to resources "
            "with get methods")
    assert res.description.raw == desc

def test_resource_inherits_get(inherited_resources):
    assert len(inherited_resources.resources) == 7

    rs = [r for r in inherited_resources.resources
          if r.path == '/another-post-resource']
    assert len(rs) == 2
    [post_res] = [r for r in rs if r.method == 'post']
    [get_res] = [r for r in rs if r.method == 'get']

    assert len(get_res.headers) == 1
    assert len(get_res.body) == 1
    assert len(get_res.responses) == 2
    assert len(get_res.query_params) == 1

    h = get_res.headers[0]
    assert h.name == "X-Inherited-Header"
    assert h.description.raw == "This header should be inherited"

    b = get_res.body[0]
    assert b.mime_type == "application/json"
    # lazy checking
    assert b.schema is not None
    assert b.example is not None

    q = get_res.query_params[0]
    assert q.name == "inherited_param"
    assert q.display_name == "inherited query parameter for a get method"
    assert q.type == "string"
    assert q.description.raw == "description for inherited query param"
    assert q.example == "fooBar"
    assert q.min_length == 1
    assert q.max_length == 50
    assert q.required is True

    assert post_res.description.raw == "post some more foobar"

def test_resource_inherited_no_overwrite(inherited_resources):
    # make sure that if resource inherits a resource type, and explicitly
    # defines properties that are defined in the resource type, the
    # properties in the resource take preference
    assert len(inherited_resources.resources) == 7
    res = inherited_resources.resources[5]

    assert res.method == "get"
    assert len(res.query_params) == 2

    desc = "This method-level description should be used"
    assert res.description.raw == desc

    # test query params
    first_param = res.query_params[0]
    second_param = res.query_params[1]

    assert second_param.name == "inherited"
    assert second_param.description.raw == "An inherited parameter"

    assert first_param.name == "overwritten"
    desc = "This query param description should be used"
    assert first_param.description.raw == desc

    # test form params
    first_param = res.form_params[0]

    desc = "This description should be inherited"
    assert first_param.description.raw == desc

    example = "This example for the overwritten form param should be used"
    assert first_param.example == example

    assert first_param.type == "string"
    assert first_param.min_length == 1
    assert first_param.max_length == 5

    # test headers
    first_header = res.headers[0]
    second_header = res.headers[1]

    assert first_header.name == "X-Inherited-Header"
    assert first_header.description.raw == "this header is inherited"

    assert second_header.name == "X-Overwritten-Header"
    desc = "This header description should be used"
    assert second_header.description.raw == desc
    assert second_header.required

    # test body
    first_body = res.body[0]
    second_body = res.body[1]

    assert first_body.mime_type == "application/json"

    schema = {
        "$schema": "http://json-schema.org/draft-03/schema",
        "type": "object",
        "properties": {
            "inherited": {
                "description": "this schema should be inherited"
            }
        }
    }
    example = {"inherited": "yes please!"}
    assert first_body.schema == schema
    assert first_body.example == example

    assert second_body.mime_type == "text/xml"

    schema = ("<xs:schema attributeFormDefault='unqualified' "
              "elementFormDefault='qualified' "
              "xmlns:xs='http://www.w3.org/2001/XMLSchema'>"
              "<xs:include schemaLocation='./thingy.xsd'/>"
              "<xs:element name='thingies'><xs:complexType>"
              "<xs:sequence minOccurs='0' maxOccurs='unbounded'>"
              "<xs:element type='thingyType' name='thingy'/>"
              "</xs:sequence></xs:complexType></xs:element></xs:schema>")
    schema = xmltodict.parse(schema)

    example = ("<thingies><thingy><name>Successfully overwrote body XML "
               "example</name></thingy></thingies>")
    example = xmltodict.parse(example)
    assert second_body.schema == schema
    assert second_body.example == example

    # test responses
    first_resp = res.responses[0]
    second_resp = res.responses[1]

    assert first_resp.code == 200

    desc = "overwriting the 200 response description"
    assert first_resp.description.raw == desc
    assert len(first_resp.headers) == 2

    first_header = first_resp.headers[0]
    second_header = first_resp.headers[1]

    assert first_header.name == "X-Inherited-Success"
    desc = "inherited success response header"
    assert first_header.description.raw == desc

    assert second_header.name == "X-Overwritten-Success"
    desc = "overwritten success response header"
    assert second_header.description.raw == desc

    assert second_resp.code == 201
    assert second_resp.body[0].mime_type == "application/json"
    example = {"description": "overwritten description of 201 body example"}
    assert second_resp.body[0].example == example

@pytest.fixture(scope="session")
def resource_protocol():
    raml_file = os.path.join(EXAMPLES, "protocols.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)

def test_overwrite_protocol(resource_protocol):
    # if a resource explicitly defines a protocol, *that*
    # should be reflected in the absolute URI
    api = resource_protocol
    assert api.protocols == ["HTTPS"]
    assert api.base_uri == "https://api.spotify.com/v1"

    res = api.resources
    assert len(res) == 2

    first = res[0]
    second = res[1]

    assert first.display_name == "several-tracks"
    assert first.protocols == ["HTTP"]
    assert second.display_name == "track"
    assert second.protocols == ["HTTP"]

@pytest.fixture(scope="session")
def uri_param_resources():
    raml_file = os.path.join(EXAMPLES, "preserve-uri-order.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)

def test_uri_params_order(uri_param_resources):
    res = uri_param_resources.resources[1]
    expected_uri = ["lang", "user_id", "playlist_id"]
    expected_base = ["subHostName", "bucketName"]

    uri = [u.name for u in res.uri_params]
    base = [b.name for b in res.base_uri_params]

    assert uri == expected_uri
    assert base == expected_base

@pytest.fixture(scope="session")
def undef_uri_params_resources():
    raml_file = os.path.join(EXAMPLES, "undefined-uri-params.raml")
    loaded_raml = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    config['validate'] = False
    return pw.parse_raml(loaded_raml, config)

def test_undefined_uri_params(undef_uri_params_resources):
    res = undef_uri_params_resources.resources[1]

    assert len(res.uri_params) == 1
    assert res.uri_params[0].name == "id"

#####
# Test Includes parsing
#####
@pytest.fixture(scope="session")
def xml_includes():
    raml_file = os.path.join(EXAMPLES + "xsd_includes.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)

def test_includes_xml(xml_includes):
    api = xml_includes
    assert api.title == "Sample API Demo - XSD Includes"
    assert api.version == "v1"
    assert api.schemas == [{
        "xml": {
            "root": {
                "false": "true",
                "name": "foo",
            }
        },
    }]

@pytest.fixture(scope="session")
def json_includes():
    raml_file = os.path.join(EXAMPLES + "json_includes.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)

def test_includes_json(json_includes):
    api = json_includes
    assert api.title == "Sample API Demo - JSON Includes"
    assert api.version == "v1"
    assert api.schemas == [{
        "json": {
            "false": True,
            "name": "foo",
        },
    }]

@pytest.fixture(scope="session")
def md_includes():
    raml_file = os.path.join(EXAMPLES + "md_includes.raml")
    loaded_raml_file = load_file(raml_file)
    config = setup_config(EXAMPLES + "test-config.ini")
    return pw.parse_raml(loaded_raml_file, config)

def test_includes_md(md_includes):
    api = md_includes
    assert api.title == "Sample API Demo - Markdown Includes"
    assert api.version == "v1"
    markdown_raw = """## Foo

*Bacon ipsum dolor* amet pork belly _doner_ rump brisket. [Cupim jerky \
shoulder][0] ball tip, jowl bacon meatloaf shank kielbasa turducken corned \
beef beef turkey porchetta.

### Doner meatball pork belly andouille drumstick sirloin

Porchetta picanha tail sirloin kielbasa, pig meatball short ribs drumstick \
jowl. Brisket swine spare ribs picanha t-bone. Ball tip beef tenderloin jowl \
doner andouille cupim meatball. Porchetta hamburger filet mignon jerky flank, \
meatball salami beef cow venison tail ball tip pork belly.

[0]: https://baconipsum.com/?paras=1&type=all-meat&start-with-lorem=1
"""
    assert api.documentation[0].content.raw == markdown_raw

    markdown_html = """
Foo

Bacon ipsum dolor amet pork belly doner rump brisket. \
Cupim jerky shoulder ball tip, jowl bacon meatloaf shank \
kielbasa turducken corned beef beef turkey porchetta.

Doner meatball pork belly andouille drumstick sirloin

Porchetta picanha tail sirloin kielbasa, pig meatball short ribs drumstick \
jowl. Brisket swine spare ribs picanha t-bone. Ball tip beef tenderloin jowl \
doner andouille cupim meatball. Porchetta hamburger filet mignon jerky flank, \
meatball salami beef cow venison tail ball tip pork belly.

"""
    assert api.documentation[0].content.html == markdown_html


text:
void QuadTree::init(const char * quadtreePath, List<GObject*>* allObject, int mapHeight)
{
	fstream fs(quadtreePath);
	rootNode = new QuadTreeNode(fs, allObject,mapHeight);
}

void QuadTree::update()
{
	//lay doi tuong cu ra khoi camera
	CAMERA->remove();

	//fill nhung object nam trong node cat camera
	rootNode->findObjectToFillToCamera();
}

QuadTree::QuadTree()
{
}

QuadTree::~QuadTree()
{
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>org.openqa.selenium.security Class Hierarchy</title>
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes

Hierarchy For Package org.openqa.selenium.security

Package Hierarchies:

All Packages

Class Hierarchy

java.lang.Object

org.openqa.selenium.security.UserAndPassword (implements org.openqa.selenium.security.Credentials)

Interface Hierarchy

org.openqa.selenium.security.Credentials

Skip navigation links

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev

Next

Frames

No Frames

All Classes