def _build_match_rule(action, target, pluralized):
 match_rule = policy.RuleCheck('rule', action)
 (resource, enforce_attr_based_check) = get_resource_and_action(action, pluralized)
 if enforce_attr_based_check:
  res_map = attributes.RESOURCE_ATTRIBUTE_MAP
  if (resource in res_map):
   for attribute_name in res_map[resource]:
    if _is_attribute_explicitly_set(attribute_name, res_map[resource], target, action):
     attribute = res_map[resource][attribute_name]
     if ('enforce_policy' in attribute):
      attr_rule = policy.RuleCheck('rule', ('%s:%s' % (action, attribute_name)))
      if _should_validate_sub_attributes(attribute, target[attribute_name]):
       attr_rule = policy.AndCheck([attr_rule, _build_subattr_match_rule(attribute_name, attribute, action, target)])
      match_rule = policy.AndCheck([match_rule, attr_rule])
 return match_rule

def _build_match_rule ( action , target , pluralized ) : match_rule = policy . RuleCheck ( 'rule' , action ) ( resource , enforce_attr_based_check ) = get_resource_and_action ( action , pluralized ) if enforce_attr_based_check : res_map = attributes . RESOURCE_ATTRIBUTE_MAP if ( resource in res_map ) : for attribute_name in res_map [ resource ] : if _is_attribute_explicitly_set ( attribute_name , res_map [ resource ] , target , action ) : attribute = res_map [ resource ] [ attribute_name ] if ( 'enforce_policy' in attribute ) : attr_rule = policy . RuleCheck ( 'rule' , ( '%s:%s' % ( action , attribute_name ) ) ) if _should_validate_sub_attributes ( attribute , target [ attribute_name ] ) : attr_rule = policy . AndCheck ( [ attr_rule , _build_subattr_match_rule ( attribute_name , attribute , action , target ) ] ) match_rule = policy . AndCheck ( [ match_rule , attr_rule ] ) return match_rule
create the rule to match for a given action .