<commit_before>from ..base import ParametrizedValue
from ..utils import make_key_val_string, filter_locals


class RouteAction(ParametrizedValue):

    pass


class ActionFlush(RouteAction):
    """Send the current contents of the transformation buffer
    to the client (without clearing the buffer).

    * http://uwsgi.readthedocs.io/en/latest/Transformations.html#flushing-magic

    """
    name = 'flush'

    def __init__(self):
        super(ActionFlush, self).__init__()


class ActionGzip(RouteAction):
    """Encodes the response buffer to gzip."""

    name = 'gzip'
    plugin = 'transformation_gzip'

    def __init__(self):
        super(ActionGzip, self).__init__()


class ActionToFile(RouteAction):
    """Used for caching a response buffer into a static file."""

    name = 'tofile'
    plugin = 'transformation_tofile'

    def __init__(self, filename, mode=None):
        arg = make_key_val_string(locals())
        super(ActionToFile, self).__init__(arg)


class ActionUpper(RouteAction):
    """Transforms each character in uppercase.

    Mainly as an example of transformation plugin.

    """
    name = 'toupper'
    plugin = 'transformation_toupper'

    def __init__(self):
        super(ActionUpper, self).__init__()


class ActionChunked(RouteAction):
    """Encodes the output in HTTP chunked."""

    name = 'chunked'

    def __init__(self):
        super(ActionChunked, self).__init__()


class ActionTemplate(RouteAction):
    """Allows using a template file to expose everything
    from internal routing system into it.

    * http://uwsgi.readthedocs.io/en/latest/Changelog-1.9.19.html#the-template-transformation

    """
    name = 'template'

    def __init__(self):
        super(ActionTemplate, self).__init__()


class ActionFixContentLen(RouteAction):
    """Fixes Content-length header."""

    name = 'fixcl'

    def __init__(self, add_header=False):
        """
        :param bool add_header: Force header add instead of plain fix of existing header.
        """
        if add_header:
            self.name = 'forcexcl'

        super(ActionFixContentLen, self).__init__()


class ActionDoContinue(RouteAction):
    """Stop scanning the internal routing table
    and continue to the selected request handler.

    """
    name = 'continue'

    def __init__(self):
        super(ActionDoContinue, self).__init__()


class ActionDoBreak(RouteAction):
    """Stop scanning the internal routing table and close the request."""

    name = 'break'

    def __init__(self, code, return_body=False):
        """
        :param int code: HTTP code

        :param return_body: Uses uWSGI's built-in status code and returns
            both status code and message body.

        """
        if return_body:
            self.name = 'return'

        super(ActionDoBreak, self).__init__(code)


class ActionLog(RouteAction):
    """Print the specified message in the logs or
    do not log a request is ``message`` is ``None``.

    """
    name = 'log'

    def __init__(self, message):
        """

        :param str|unicode|None message: Message to add into log.
            If ``None`` logging will be disabled for this request.

        """
        if message is None:
            self.name = 'donotlog'

        super(ActionLog, self).__init__(message)


class ActionOffloadOff(RouteAction):
    """Do not use offloading."""

    name = 'donotoffload'

    def __init__(self):
        super(ActionOffloadOff, self).__init__()


class ActionAddVarLog(RouteAction):
    """Add the specified logvar."""

    name = 'logvar'

    def __init__(self, name, val):
        """
        :param str|unicode name: Variable name.

        :param val: Variable value.
        """
        super(ActionAddVarLog, self).__init__(name, val)


class ActionDoGoto(RouteAction):
    """Make a forward jump to the specified label or rule position."""

    name = 'goto'

    def __init__(self, where):
        """
        :param str|unicode|int where: Rule number of label to go to.
        """
        super(ActionDoGoto, self).__init__(where)


class ActionAddVarCgi(RouteAction):
    """Add the specified CGI (environment) variable to the request."""

    name = 'addvar'

    def __init__(self, name, val):
        """
        :param str|unicode name: Variable name.

        :param val: Variable value.
        """
        super(ActionAddVarCgi, self).__init__(name, val)


class ActionHeaderAdd(RouteAction):
    """Add the specified HTTP header to the response."""

    name = 'addheader'

    def __init__(self, name, val):
        """
        :param str|unicode name: Header name.

        :param val: Header value.
        """
        name += ':'

        super(ActionHeaderAdd, self).__init__(name, val)


class ActionHeaderRemove(RouteAction):
    """Remove the specified HTTP header from the response."""

    name = 'delheader'

    def __init__(self, name):
        """
        :param str|unicode name: Header name.
        """
        super(ActionHeaderRemove, self).__init__(name)


class ActionHeadersOff(RouteAction):
    """Disable headers."""

    name = 'disableheaders'

    def __init__(self):
        super(ActionHeadersOff, self).__init__()


class ActionHeadersReset(RouteAction):
    """Clear the response headers, setting a new HTTP status code,
    useful for resetting a response.

    """
    name = 'clearheaders'

    def __init__(self, code):
        """
        :param int code: HTTP code.
        """
        super(ActionHeadersReset, self).__init__(code)


class ActionSignal(RouteAction):
    """Raise the specified uwsgi signal."""

    name = 'signal'

    def __init__(self, num):
        """
        :param int num: Signal number.
        """
        super(ActionSignal, self).__init__(num)


class ActionSend(RouteAction):
    """Extremely advanced (and dangerous) function allowing you
    to add raw data to the response.

    """
    name = 'send'

    def __init__(self, data, crnl=False):
        """
        :param data: Data to add to response.
        :param bool crnl: Add carriage return and new line.
        """
        if crnl:
            self.name = 'send-crnl'
        super(ActionSend, self).__init__(data)


class ActionRedirect(RouteAction):
    """Return a HTTP 301/302 Redirect to the specified URL."""

    name = 'redirect-302'
    plugin = 'router_redirect'

    def __init__(self, url, permanent=False):
        """
        :param str| unicode url: URL to redirect to.
        :param bool permanent: If ``True`` use 301, otherwise 302.
        """
        if permanent:
            self.name = 'redirect-301'

        super(ActionRedirect, self).__init__(url)


class ActionRewrite(RouteAction):
    """A rewriting engine inspired by Apache mod_rewrite.

    Rebuild PATH_INFO and QUERY_STRING according to the specified rules
    before the request is dispatched to the request handler.

    """
    name = 'rewrite'
    plugin = 'router_rewrite'

    def __init__(self, rule, do_continue=False):
        """
        :param str|unicode rule: A rewrite rule.

        :param bool do_continue: Stop request processing
            and continue to the selected request handler.

        """
        if do_continue:
            self.name = 'rewrite-last'

        super(ActionRewrite, self).__init__(rule)


class ActionRouteUwsgi(RouteAction):
    """Rewrite the modifier1, modifier2 and optionally UWSGI_APPID values of a request
    or route the request to an external uwsgi server.

    """
    name = 'uwsgi'
    plugin = 'router_uwsgi'
    args_joiner = ','

    def __init__(self, external_address='', modifier='', mod2='', app=''):
        """
        :param str|unicode external_address: External uWSGI server address (host:port).
        :param Modifier modifier: Set request modifier.
        :param str|unicode app: Set ``UWSGI_APPID``.
        """
        super(ActionRouteUwsgi, self).__init__(external_address, modifier, modifier.submod, app)


class ActionRouteExternal(RouteAction):
    """Route the request to an external HTTP server."""

    name = 'http'
    plugin = 'router_http'
    args_joiner = ','

    def __init__(self, address, host_header=None):
        """
        :param str|unicode address: External HTTP address (host:port)

        :param str|unicode host_header: HOST header value.
        """
        super(ActionRouteExternal, self).__init__(address, host_header)


class ActionAlarm(RouteAction):<commit_msg>Removed unused arg.<commit_after>from ..base import ParametrizedValue
from ..utils import make_key_val_string, filter_locals


class RouteAction(ParametrizedValue):

    pass


class ActionFlush(RouteAction):
    """Send the current contents of the transformation buffer
    to the client (without clearing the buffer).

    * http://uwsgi.readthedocs.io/en/latest/Transformations.html#flushing-magic

    """
    name = 'flush'

    def __init__(self):
        super(ActionFlush, self).__init__()


class ActionGzip(RouteAction):
    """Encodes the response buffer to gzip."""

    name = 'gzip'
    plugin = 'transformation_gzip'

    def __init__(self):
        super(ActionGzip, self).__init__()


class ActionToFile(RouteAction):
    """Used for caching a response buffer into a static file."""

    name = 'tofile'
    plugin = 'transformation_tofile'

    def __init__(self, filename, mode=None):
        arg = make_key_val_string(locals())
        super(ActionToFile, self).__init__(arg)


class ActionUpper(RouteAction):
    """Transforms each character in uppercase.

    Mainly as an example of transformation plugin.

    """
    name = 'toupper'
    plugin = 'transformation_toupper'

    def __init__(self):
        super(ActionUpper, self).__init__()


class ActionChunked(RouteAction):
    """Encodes the output in HTTP chunked."""

    name = 'chunked'

    def __init__(self):
        super(ActionChunked, self).__init__()


class ActionTemplate(RouteAction):
    """Allows using a template file to expose everything
    from internal routing system into it.

    * http://uwsgi.readthedocs.io/en/latest/Changelog-1.9.19.html#the-template-transformation

    """
    name = 'template'

    def __init__(self):
        super(ActionTemplate, self).__init__()


class ActionFixContentLen(RouteAction):
    """Fixes Content-length header."""

    name = 'fixcl'

    def __init__(self, add_header=False):
        """
        :param bool add_header: Force header add instead of plain fix of existing header.
        """
        if add_header:
            self.name = 'forcexcl'

        super(ActionFixContentLen, self).__init__()


class ActionDoContinue(RouteAction):
    """Stop scanning the internal routing table
    and continue to the selected request handler.

    """
    name = 'continue'

    def __init__(self):
        super(ActionDoContinue, self).__init__()


class ActionDoBreak(RouteAction):
    """Stop scanning the internal routing table and close the request."""

    name = 'break'

    def __init__(self, code, return_body=False):
        """
        :param int code: HTTP code

        :param return_body: Uses uWSGI's built-in status code and returns
            both status code and message body.

        """
        if return_body:
            self.name = 'return'

        super(ActionDoBreak, self).__init__(code)


class ActionLog(RouteAction):
    """Print the specified message in the logs or
    do not log a request is ``message`` is ``None``.

    """
    name = 'log'

    def __init__(self, message):
        """

        :param str|unicode|None message: Message to add into log.
            If ``None`` logging will be disabled for this request.

        """
        if message is None:
            self.name = 'donotlog'

        super(ActionLog, self).__init__(message)


class ActionOffloadOff(RouteAction):
    """Do not use offloading."""

    name = 'donotoffload'

    def __init__(self):
        super(ActionOffloadOff, self).__init__()


class ActionAddVarLog(RouteAction):
    """Add the specified logvar."""

    name = 'logvar'

    def __init__(self, name, val):
        """
        :param str|unicode name: Variable name.

        :param val: Variable value.
        """
        super(ActionAddVarLog, self).__init__(name, val)


class ActionDoGoto(RouteAction):
    """Make a forward jump to the specified label or rule position."""

    name = 'goto'

    def __init__(self, where):
        """
        :param str|unicode|int where: Rule number of label to go to.
        """
        super(ActionDoGoto, self).__init__(where)


class ActionAddVarCgi(RouteAction):
    """Add the specified CGI (environment) variable to the request."""

    name = 'addvar'

    def __init__(self, name, val):
        """
        :param str|unicode name: Variable name.

        :param val: Variable value.
        """
        super(ActionAddVarCgi, self).__init__(name, val)


class ActionHeaderAdd(RouteAction):
    """Add the specified HTTP header to the response."""

    name = 'addheader'

    def __init__(self, name, val):
        """
        :param str|unicode name: Header name.

        :param val: Header value.
        """
        name += ':'

        super(ActionHeaderAdd, self).__init__(name, val)


class ActionHeaderRemove(RouteAction):
    """Remove the specified HTTP header from the response."""

    name = 'delheader'

    def __init__(self, name):
        """
        :param str|unicode name: Header name.
        """
        super(ActionHeaderRemove, self).__init__(name)


class ActionHeadersOff(RouteAction):
    """Disable headers."""

    name = 'disableheaders'

    def __init__(self):
        super(ActionHeadersOff, self).__init__()


class ActionHeadersReset(RouteAction):
    """Clear the response headers, setting a new HTTP status code,
    useful for resetting a response.

    """
    name = 'clearheaders'

    def __init__(self, code):
        """
        :param int code: HTTP code.
        """
        super(ActionHeadersReset, self).__init__(code)


class ActionSignal(RouteAction):
    """Raise the specified uwsgi signal."""

    name = 'signal'

    def __init__(self, num):
        """
        :param int num: Signal number.
        """
        super(ActionSignal, self).__init__(num)


class ActionSend(RouteAction):
    """Extremely advanced (and dangerous) function allowing you
    to add raw data to the response.

    """
    name = 'send'

    def __init__(self, data, crnl=False):
        """
        :param data: Data to add to response.
        :param bool crnl: Add carriage return and new line.
        """
        if crnl:
            self.name = 'send-crnl'
        super(ActionSend, self).__init__(data)


class ActionRedirect(RouteAction):
    """Return a HTTP 301/302 Redirect to the specified URL."""

    name = 'redirect-302'
    plugin = 'router_redirect'

    def __init__(self, url, permanent=False):
        """
        :param str| unicode url: URL to redirect to.
        :param bool permanent: If ``True`` use 301, otherwise 302.
        """
        if permanent:
            self.name = 'redirect-301'

        super(ActionRedirect, self).__init__(url)


class ActionRewrite(RouteAction):
    """A rewriting engine inspired by Apache mod_rewrite.

    Rebuild PATH_INFO and QUERY_STRING according to the specified rules
    before the request is dispatched to the request handler.

    """
    name = 'rewrite'
    plugin = 'router_rewrite'

    def __init__(self, rule, do_continue=False):
        """
        :param str|unicode rule: A rewrite rule.

        :param bool do_continue: Stop request processing
            and continue to the selected request handler.

        """
        if do_continue:
            self.name = 'rewrite-last'

        super(ActionRewrite, self).__init__(rule)


class ActionRouteUwsgi(RouteAction):
    """Rewrite the modifier1, modifier2 and optionally UWSGI_APPID values of a request
    or route the request to an external uwsgi server.

    """
    name = 'uwsgi'
    plugin = 'router_uwsgi'
    args_joiner = ','

    def __init__(self, external_address='', modifier='', app=''):
        """
        :param str|unicode external_address: External uWSGI server address (host:port).
        :param Modifier modifier: Set request modifier.
        :param str|unicode app: Set ``UWSGI_APPID``.
        """
        super(ActionRouteUwsgi, self).__init__(external_address, modifier, modifier.submod, app)


class ActionRouteExternal(RouteAction):
    """Route the request to an external HTTP server."""

    name = 'http'
    plugin = 'router_http'
    args_joiner = ','

    def __init__(self, address, host_header=None):
        """
        :param str|unicode address: External HTTP address (host:port)

        :param str|unicode host_header: HOST header value.
        """
        super(ActionRouteExternal, self).__init__(address, host_header)


class ActionAlarm(RouteAction):
{'fraction_non_alphanumeric': 0.10858361471476809, 'fraction_numerical': 0.002902671642675197, 'mean_word_length': 2.7374363515607705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1196394', 'n_tokens_mistral': 5012, 'n_tokens_neox': 4683, 'n_words': 1444}