<commit_before># -*- coding: utf-8 -*-

import os
import re
import logging
import yaml
import cPickle as pickle
from time import time
from collections import OrderedDict

from moulinette import m18n, msignals
from moulinette.cache import open_cachefile
from moulinette.globals import init_moulinette_env
from moulinette.core import (MoulinetteError, MoulinetteLock)
from moulinette.interfaces import (
    BaseActionsMapParser, GLOBAL_SECTION, TO_RETURN_PROP
)
from moulinette.utils.log import start_action_logging

logger = logging.getLogger('moulinette.actionsmap')


# Extra parameters ----------------------------------------------------

# Extra parameters definition

class _ExtraParameter(object):

    """
    Argument parser for an extra parameter.

    It is a pure virtual class that each extra parameter classes must
    implement.

    """

    def __init__(self, iface):
        # TODO: Add conn argument which contains authentification object
        self.iface = iface

    # Required variables
    # Each extra parameters classes must overwrite these variables.

    """The extra parameter name"""
    name = None

    # Optional variables
    # Each extra parameters classes can overwrite these variables.

    """A list of interface for which the parameter doesn't apply"""
    skipped_iface = []

    # Virtual methods
    # Each extra parameters classes can implement these methods.

    def __call__(self, parameter, arg_name, arg_value):
        """
        Parse the argument

        Keyword arguments:
            - parameter -- The value of this parameter for the action
            - arg_name -- The argument name
            - arg_value -- The argument value

        Returns:
            The new argument value

        """
        return arg_value

    @staticmethod
    def validate(value, arg_name):
        """
        Validate the parameter value for an argument

        Keyword arguments:
            - value -- The parameter value
            - arg_name -- The argument name

        Returns:
            The validated parameter value

        """
        return value


class CommentParameter(_ExtraParameter):
    name = "comment"
    skipped_iface = ['api']

    def __call__(self, message, arg_name, arg_value):
        if arg_value:
            return
        
        return msignals.display(m18n.n(message))

    @classmethod
    def validate(klass, value, arg_name):
        # Deprecated boolean or empty string
        if isinstance(value, bool) or (isinstance(value, str) and not value):
            logger.warning("expecting a non-empty string for extra parameter '%s' of "
                           "argument '%s'", klass.name, arg_name)
            value = arg_name
        elif not isinstance(value, str):
            raise TypeError("parameter value must be a string, got %r"
                            % value)
        return value


class AskParameter(_ExtraParameter):

    """
    Ask for the argument value if possible and needed.

    The value of this parameter corresponds to the message to display
    when asking the argument value.<commit_msg>[fix] blank spaces for travis.<commit_after># -*- coding: utf-8 -*-

import os
import re
import logging
import yaml
import cPickle as pickle
from time import time
from collections import OrderedDict

from moulinette import m18n, msignals
from moulinette.cache import open_cachefile
from moulinette.globals import init_moulinette_env
from moulinette.core import (MoulinetteError, MoulinetteLock)
from moulinette.interfaces import (
    BaseActionsMapParser, GLOBAL_SECTION, TO_RETURN_PROP
)
from moulinette.utils.log import start_action_logging

logger = logging.getLogger('moulinette.actionsmap')


# Extra parameters ----------------------------------------------------

# Extra parameters definition

class _ExtraParameter(object):

    """
    Argument parser for an extra parameter.

    It is a pure virtual class that each extra parameter classes must
    implement.

    """

    def __init__(self, iface):
        # TODO: Add conn argument which contains authentification object
        self.iface = iface

    # Required variables
    # Each extra parameters classes must overwrite these variables.

    """The extra parameter name"""
    name = None

    # Optional variables
    # Each extra parameters classes can overwrite these variables.

    """A list of interface for which the parameter doesn't apply"""
    skipped_iface = []

    # Virtual methods
    # Each extra parameters classes can implement these methods.

    def __call__(self, parameter, arg_name, arg_value):
        """
        Parse the argument

        Keyword arguments:
            - parameter -- The value of this parameter for the action
            - arg_name -- The argument name
            - arg_value -- The argument value

        Returns:
            The new argument value

        """
        return arg_value

    @staticmethod
    def validate(value, arg_name):
        """
        Validate the parameter value for an argument

        Keyword arguments:
            - value -- The parameter value
            - arg_name -- The argument name

        Returns:
            The validated parameter value

        """
        return value


class CommentParameter(_ExtraParameter):
    name = "comment"
    skipped_iface = ['api']

    def __call__(self, message, arg_name, arg_value):
        if arg_value:
            return
        return msignals.display(m18n.n(message))

    @classmethod
    def validate(klass, value, arg_name):
        # Deprecated boolean or empty string
        if isinstance(value, bool) or (isinstance(value, str) and not value):
            logger.warning("expecting a non-empty string for extra parameter '%s' of "
                           "argument '%s'", klass.name, arg_name)
            value = arg_name
        elif not isinstance(value, str):
            raise TypeError("parameter value must be a string, got %r"
                            % value)
        return value


class AskParameter(_ExtraParameter):

    """
    Ask for the argument value if possible and needed.

    The value of this parameter corresponds to the message to display
    when asking the argument value.
{'fraction_non_alphanumeric': 0.08111146803726309, 'fraction_numerical': 0.0016061676839061998, 'mean_word_length': 2.3460505104782374, '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': '3186032', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1535, 'n_words': 591}