Store the rules.

        Policy is maintained as a dictionary of Rule ID.
486246
def store_rule(self, rule_id, rule):
        
        if rule_id not in self.rules:
            self.rules[rule_id] = rule
            self.rule_cnt += 1
136702
def _apply_policy_config(policy_spec, policy_dict):
    ''''''
    log.trace('policy_dict = %s', policy_dict)
    if policy_dict.get('name'):
        policy_spec.name = policy_dict['name']
    if policy_dict.get('description'):
        policy_spec.description = policy_dict['description']
    if policy_dict.get('subprofiles'):
        # Incremental changes to subprofiles and capabilities are not
        # supported because they would complicate updates too much
        # The whole configuration of all sub-profiles is expected and applied
        policy_spec.constraints = pbm.profile.SubProfileCapabilityConstraints()
        subprofiles = []
        for subprofile_dict in policy_dict['subprofiles']:
            subprofile_spec = \
                    pbm.profile.SubProfileCapabilityConstraints.SubProfile(
                        name=subprofile_dict['name'])
            cap_specs = []
            if subprofile_dict.get('force_provision'):
                subprofile_spec.forceProvision = \
                        subprofile_dict['force_provision']
            for cap_dict in subprofile_dict['capabilities']:
                prop_inst_spec = pbm.capability.PropertyInstance(
                    id=cap_dict['id']
                )
                setting_type = cap_dict['setting']['type']
                if setting_type == 'set':
                    prop_inst_spec.value = pbm.capability.types.DiscreteSet()
                    prop_inst_spec.value.values = cap_dict['setting']['values']
                elif setting_type == 'range':
                    prop_inst_spec.value = pbm.capability.types.Range()
                    prop_inst_spec.value.max = cap_dict['setting']['max']
                    prop_inst_spec.value.min = cap_dict['setting']['min']
                elif setting_type == 'scalar':
                    prop_inst_spec.value = cap_dict['setting']['value']
                cap_spec = pbm.capability.CapabilityInstance(
                    id=pbm.capability.CapabilityMetadata.UniqueId(
                        id=cap_dict['id'],
                        namespace=cap_dict['namespace']),
                    constraint=[pbm.capability.ConstraintInstance(
                        propertyInstance=[prop_inst_spec])])
                cap_specs.append(cap_spec)
            subprofile_spec.capability = cap_specs
            subprofiles.append(subprofile_spec)
        policy_spec.constraints.subProfiles = subprofiles
    log.trace('updated policy_spec = %s', policy_spec)
    return policy_spec
69947
def save_rule!(objectID, rule, forward_to_replicas = false, request_options = {})
      res = save_rule(objectID, rule, forward_to_replicas, request_options)
      wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
      return res
    end
893331
public boolean addPolicy(String sec, String ptype, List<String> rule) {
        if (!hasPolicy(sec, ptype, rule)) {
            model.get(sec).get(ptype).policy.add(rule);
            return true;
        }
        return false;
    }
900707
def policy(self, observations):
        
        input_data = self.input_block(observations)
        policy_base_output = self.policy_backbone(input_data)
        policy_params = self.action_head(policy_base_output)
        return policy_params
1024039
public function initializeObject()
    {
        if ($this->cache->has('rulesets') && $this->cache->has('rulesetsIndices')) {
            $this->rulesets = $this->cache->get('rulesets');
            $this->rulesetsIndices = $this->cache->get('rulesetsIndices');
        } else {
            $this->generateRulesets();
            $this->cache->set('rulesets', $this->rulesets);
            $this->cache->set('rulesetsIndices', $this->rulesetsIndices);
        }
    }
994109
def from_raw(self, rule_ids, outputs, raw_rules):
        
        self._rule_pool = [([], [])] + raw_rules
        self._rule_list = []
        for i, idx in enumerate(rule_ids):
            rule = Rule([Clause(f, c) for f, c in zip(*self._rule_pool[idx])], outputs[i])
            self._rule_list.append(rule)
            # self._rule_list.append(rule_str2rule(_rule_name, outputs[i]))
        self._rule_ids = rule_ids
        self._rule_outputs = outputs
804547
def load_rules(self, force_reload=False, overwrite=True):
        """"""

        # double-checked locking
        if self.load_once and self._policy_loaded:
            return
        with self._load_lock:
            if self.load_once and self._policy_loaded:
                return

            reloaded, data = _cache.read_file(
                self.policy_file, force_reload=force_reload)
            self._policy_loaded = True
            if reloaded or not self.rules:
                rules = Rules.load_json(data, self.default_rule, self.raise_error)
                self._set_rules(rules, overwrite=overwrite)
                LOG.debug('Reload policy file: %s', self.policy_file)
546180
def process_rules(self, path: Path, system: System):
        """"""
        self.context.update({
            'system': system,
        })
        document = FileSystem.load_yaml(path, required=True)
        for module, rules in document.items():
            click.secho('process: {0}'.format(module), fg='green')
            self._process_rules(rules, system)
1101211
function addRules(rules) {
        _.each(rules, function (rule) {
            _global.rules[rule.id] = rule;
        });
    }
469904
def _store(self, con):
        """"""
        self._con = con
        self._transaction = False
        self._closed = False
        self._usage = 0
1122438
def store_model(constrs, vars)
      # Store all constraints
      constrs.each do |constr|
        store_constraint constr
        @constraints << constr
      end

      # We store variables now since they didn't exist earlier
      vars.each_with_index do |var, i|
        var.index = i
        var.model = self
        store_variable var
      end
    end
253727
def _process_rule(self, rule: dict, context: dict):
        
        if not rule or not self._shall_proceed(rule):
            return
        self.context.update(context)
        self.context.update(rule.get('context', {}))
        self.path = rule.get('path', None)
        self.source = rule.get('source', None)
        for entry in rule.get('documents', []):
            target, source = self._resolve_rule_document(entry)
            self.write(target, source)
        for entry in rule.get('preserve', []):
            target, source = self._resolve_rule_document(entry)
            self.write(target, source, preserve=True)
551620
def as_dict(self):
        
        dict_fw = {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'rules_direction': self.rules_direction,
            'rules_ip_protocol': self.rules_ip_protocol,
            'rules_from_port': self.rules_from_port,
            'rules_to_port': self.rules_to_port,
            'rules_grants_group_id': self.rules_grants_group_id,
            'rules_grants_name': self.rules_grants_name,
            'rules_grants_cidr_ip': self.rules_grants_cidr_ip,
            'rules_description': self.rules_description
        }

        return dict_fw
609350
def policy_net(rng_key,
               batch_observations_shape,
               num_actions,
               bottom_layers=None):
  """"""
  # Use the bottom_layers as the bottom part of the network and just add the
  # required layers on top of it.
  if bottom_layers is None:
    bottom_layers = []

  # NOTE: The LogSoftmax instead of the Softmax.
  bottom_layers.extend([layers.Dense(num_actions), layers.LogSoftmax()])
  net = layers.Serial(*bottom_layers)

  return net.initialize(batch_observations_shape, rng_key), net
964886
def store(self, key, pk, value):
        

        self.connection.zadd(key, value, pk)
1335640
def policies(options = {})
      batches = Enumerator.new do |y|
        options = options.merge(role_name: @name)
        resp = @client.list_role_policies(options)
        resp.each_page do |page|
          batch = []
          page.data.policy_names.each do |p|
            batch << RolePolicy.new(
              role_name: @name,
              name: p,
              client: @client
            )
          end
          y.yield(batch)
        end
      end
      RolePolicy::Collection.new(batches)
    end