<commit_before>import re

import pyrox.http as http


ADD_HEADER = 1
REWRITE_HEADER = 2
CONSUME_EVENT = 3
PROXY_REQUEST = 4
REJECT_REQUEST = 5


class MessageControl(object):
    """
    This class is returned to the control plane to aggregrate actions.
    """

    def __init__(self):
        self.control = PROXY_REQUEST
        self.message_actions = list()

    def add_action(self, filter_action):
        self.message_actions.append(filter_action)

    def should_consume(self):
        return self.control == CONSUME_EVENT

    def should_reject(self):
        return self.control == REJECT_REQUEST


class FilterAction(object):

    def __init__(self, kind, *args):
        self.kind = kind
        self.args = args


class HttpFilterChain(object):

    def __init__(self):
        self.chain = list()

    def add_filter(self, http_filter):
        self.chain.append(http_filter)

    def on_header(self, field, value):
        message_control = MessageControl()
        for http_filter in self.chain:
            action_list = http_filter.on_header(field, value)
            if action_list and len(action_list) > 0:
                self._process_actions(message_control, action_list)
                if message_control.should_consume() or message_control.should_reject():
                        break
        return message_control

    def _perform_actions(self, message_control, actions):
        message_control = PROXY_REQUEST
        for action in actions:
            if action.kind == ADD_HEADER and len(action.args) == 2:
                """
                Adding a header requires the name and value
                """
                message_control.add_action(action)
            elif action.kind == REWRITE_HEADER and len(action.args) == 2:
                """
                Rewriting a header requires the name and value
                """
                message_control.add_action(action)
            elif action.kind == CONSUME_EVENT:
                message_control.control = CONSUME_EVENT
            elif action.kind == REJECT_REQUEST:
                message_control.control = REJECT_REQUEST
        return message_control


class HttpMessageSelector(object):

    def __init__(<commit_msg>corrections in _process_actions<commit_after>import re

import pyrox.http as http


ADD_HEADER = 1
REWRITE_HEADER = 2
CONSUME_EVENT = 3
PROXY_REQUEST = 4
REJECT_REQUEST = 5


class MessageControl(object):
    """
    This class is returned to the control plane to aggregrate actions.
    """

    def __init__(self):
        self.control = PROXY_REQUEST
        self.message_actions = list()

    def add_action(self, filter_action):
        self.message_actions.append(filter_action)

    def should_consume(self):
        return self.control == CONSUME_EVENT

    def should_reject(self):
        return self.control == REJECT_REQUEST


class FilterAction(object):

    def __init__(self, kind, *args):
        self.kind = kind
        self.args = args


class HttpFilterChain(object):

    def __init__(self):
        self.chain = list()

    def add_filter(self, http_filter):
        self.chain.append(http_filter)

    def on_header(self, field, value):
        message_control = MessageControl()
        for http_filter in self.chain:
            action_list = http_filter.on_header(field, value)
            if action_list and len(action_list) > 0:
                self._perform_actions(message_control, action_list)
                if message_control.should_consume() or message_control.should_reject():
                        break
        return message_control

    def _perform_actions(self, message_control, actions):
        for action in actions:
            if action.kind == ADD_HEADER and len(action.args) == 2:

                #Adding a header requires the name and value
                message_control.add_action(action)
            elif action.kind == REWRITE_HEADER and len(action.args) == 2:

                #Rewriting a header requires the name and value
                message_control.add_action(action)
            elif action.kind == CONSUME_EVENT:
                message_control.control = CONSUME_EVENT
            elif action.kind == REJECT_REQUEST:
                message_control.control = REJECT_REQUEST
        return message_control


class HttpMessageSelector(object):

    def __init__(
{'fraction_non_alphanumeric': 0.07460973370064279, 'fraction_numerical': 0.0036730945821854912, 'mean_word_length': 2.3361408882082695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6294490', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1159, 'n_words': 303}