<commit_before>#!/usr/bin/env python3

"""
Copyright (C), 2013, The Schilduil Team. All rights reserved.
"""
import logging
import inspect
from functools import wraps


def loguse(param = None):
    """When in debug it will log entering and exiting a function or object methods.

    WARNING: Some callables are broken when you use this (e.g. Thread.__init__)
    Upon entering the callable it will also log all arguments.

    You can specify arguments to this decorator: a string, an int or a list of 
    string and/or integers. A string causes not log that name argument, an int 
    causes not to log that positional argument.

    Example:
        @loguse             # will log all arguments.
        @loguse('arg0')     # will log all but not a named argument named 'arg0'.
        @loguse(0)          # will log all but the first positional argument.
        @loguse(['arg0',0]) # will log all but the first pos. and 'arg0'.
    """
    # Checking the param
    #   If it is a callable then just return what real_loguse(f) would return.
    #   If it is a parameter (even if None) return the real_loguse function.
    # Param:
    #   It could be None => empty list
    #   It could be a string => list with that string as element
    #   It could be an iterable => ok
    f = None
    ignore_parameters = []
    if param == None:
        ignore_parameters = []
    elif callable(param):
        f = param
    elif isinstance(param, str):
        ignore_parameters = [param]
    elif isinstance(param, int):
        ignore_parameters = [param]
    elif isinstance(param, iterable):
        ignore_parameters = param
    # Looking for the classname.
    classname = "?"
    try:
        # We don't want this weird stuff messing in the log decorator
        # halting our code. And that is a real possibility as this
        # stuff is in CPtython but does not have to present in other
        # python implementation. More info on inspect:
        # http://docs.python.org/3/library/inspect.html
        classname = inspect.getouterframes(inspect.currentframe())[1][3]
    except:
        pass

    def real_loguse(f):
        log = logging.getLogger(f.__module__)
        @wraps(f)
        def decorator(*args, **kwargs):
            l_args = list(args)
            l_kwargs = dict(kwargs)
            if log.isEnabledFor(logging.DEBUG):
                ignore_parameters.sort(key = str, reverse = True)<commit_msg>Fix on the check if param is an iterable.<commit_after>#!/usr/bin/env python3

"""
Copyright (C), 2013, The Schilduil Team. All rights reserved.
"""
import logging
import inspect
from functools import wraps


def loguse(param = None):
    """When in debug it will log entering and exiting a function or object methods.

    WARNING: Some callables are broken when you use this (e.g. Thread.__init__)
    Upon entering the callable it will also log all arguments.

    You can specify arguments to this decorator: a string, an int or a list of 
    string and/or integers. A string causes not log that name argument, an int 
    causes not to log that positional argument.

    Example:
        @loguse             # will log all arguments.
        @loguse('arg0')     # will log all but not a named argument named 'arg0'.
        @loguse(0)          # will log all but the first positional argument.
        @loguse(['arg0',0]) # will log all but the first pos. and 'arg0'.
    """
    # Checking the param
    #   If it is a callable then just return what real_loguse(f) would return.
    #   If it is a parameter (even if None) return the real_loguse function.
    # Param:
    #   It could be None => empty list
    #   It could be a string => list with that string as element
    #   It could be an iterable => ok
    f = None
    ignore_parameters = []
    if param == None:
        ignore_parameters = []
    elif callable(param):
        f = param
    elif isinstance(param, str):
        ignore_parameters = [param]
    elif isinstance(param, int):
        ignore_parameters = [param]
    elif hasattr(param, '__iter__'):
        ignore_parameters = param
    # Looking for the classname.
    classname = "?"
    try:
        # We don't want this weird stuff messing in the log decorator
        # halting our code. And that is a real possibility as this
        # stuff is in CPtython but does not have to present in other
        # python implementation. More info on inspect:
        # http://docs.python.org/3/library/inspect.html
        classname = inspect.getouterframes(inspect.currentframe())[1][3]
    except:
        pass

    def real_loguse(f):
        log = logging.getLogger(f.__module__)
        @wraps(f)
        def decorator(*args, **kwargs):
            l_args = list(args)
            l_kwargs = dict(kwargs)
            if log.isEnabledFor(logging.DEBUG):
                ignore_parameters.sort(key = str, reverse = True)
{'fraction_non_alphanumeric': 0.08266666666666667, 'fraction_numerical': 0.005743589743589744, 'mean_word_length': 2.414565826330532, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1647912', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1341, 'n_words': 555}