<commit_before>// Copyright 2018 ETH Zurich
// Copyright 2019 ETH Zurich, Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package pathpol implements path policies, documentation in doc/PathPolicy.md
// Currently implemented: ACL, Sequence, Extends and Options.
//
// A policy has an Act() method that takes an AppPathSet and returns a filtered AppPathSet
package pathpol

import (
	"fmt"
	"sort"

	"github.com/scionproto/scion/go/lib/common"
)

// ExtPolicy is an extending policy, it may have a list of policies it extends
type ExtPolicy struct {
	Extends []string `json:",omitempty"`
	*Policy
}

// PolicyMap is a container for Policies, keyed by their unique name. PolicyMap
// can be used to marshal Policies to JSON. Unmarshaling back to PolicyMap is
// guaranteed to yield an object that is identical to the initial one.
type PolicyMap map[string]*ExtPolicy

// Policy is a compiled path policy object, all extended policies have been merged.
type Policy struct {
	Name     string    `json:"-"`
	ACL      *ACL      `json:",omitempty"`
	Sequence *Sequence `json:",omitempty"`
	Options  []Option  `json:",omitempty"`
}

// NewPolicy creates a Policy and sorts its Options
func NewPolicy(name string, acl *ACL, sequence *Sequence, options []Option) *Policy {<commit_msg>Pathpol: JSON keys should be snake_case (#2917)<commit_after>// Copyright 2018 ETH Zurich
// Copyright 2019 ETH Zurich, Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package pathpol implements path policies, documentation in doc/PathPolicy.md
// Currently implemented: ACL, Sequence, Extends and Options.
//
// A policy has an Act() method that takes an AppPathSet and returns a filtered AppPathSet
package pathpol

import (
	"fmt"
	"sort"

	"github.com/scionproto/scion/go/lib/common"
)

// ExtPolicy is an extending policy, it may have a list of policies it extends
type ExtPolicy struct {
	Extends []string `json:"extends,omitempty"`
	*Policy
}

// PolicyMap is a container for Policies, keyed by their unique name. PolicyMap
// can be used to marshal Policies to JSON. Unmarshaling back to PolicyMap is
// guaranteed to yield an object that is identical to the initial one.
type PolicyMap map[string]*ExtPolicy

// Policy is a compiled path policy object, all extended policies have been merged.
type Policy struct {
	Name     string    `json:"-"`
	ACL      *ACL      `json:"acl,omitempty"`
	Sequence *Sequence `json:"sequence,omitempty"`
	Options  []Option  `json:"options,omitempty"`
}

// NewPolicy creates a Policy and sorts its Options
func NewPolicy(name string, acl *ACL, sequence *Sequence, options []Option) *Policy {
{'fraction_non_alphanumeric': 0.08904670854957662, 'fraction_numerical': 0.0076481835564053535, 'mean_word_length': 3.8761651131824233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4519359', 'n_tokens_mistral': 998, 'n_tokens_neox': 965, 'n_words': 470}