<commit_before>import json
import platform
import uuid

from contextgenerator import ContextGenerator
if platform.system() != "Windows":
    from outputhandlers.shellcolors import OutputHandler
else: # pragma: no cover
    from outputhandlers.windowscolors import OutputHandler

class ErrorBundle(object):
    """This class does all sorts of cool things. It gets passed around
    from test to test and collects up all the errors like the candy man
    'separating the sorrow and collecting up all the cream.' It's
    borderline magical."""
    
    def __init__(self, pipe=None, no_color=False, determined=True,
                 listed=False):
        """Specifying pipe allows the output of the bundler to be
        written to a file rather than to the screen."""
        
        self.errors = []
        self.warnings = []
        self.notices = []
        self.message_tree = {}

        self.tier = 1
        
        self.metadata = {}
        self.determined = determined
        
        self.subpackages = []
        self.package_stack = []
        
        self.detected_type = 0
        self.resources = {}
        self.reject = False
        self.unfinished = False
        
        if listed:
            self.resources["listed"] = True

        self.handler = OutputHandler(pipe, no_color)
            
        
    def error(self, err_id, error,
              description='', filename='', line=0, column=0, context=None):
        "Stores an error message for the validation process"
        self._save_message(self.errors,
                           "errors",
                           {"id": err_id,
                            "message": error,
                            "description": description,
                            "file": filename,
                            "line": line,
                            "column": column},
                           context=context)
        return self
        
    def warning(self, err_id, warning,
                description='', filename='', line=0, column=0, context=None):
        "Stores a warning message for the validation process"
        self._save_message(self.warnings,
                           "warnings",
                           {"id": err_id,
                            "message": warning,
                            "description": description,
                            "file": filename,
                            "line": line,
                            "column": column},
                           context=context)
        return self

    # NOTE : This function WILL NOT support contexts since it's deprecated.
    def info(self, err_id, info, description="", filename="", line=0):
        "An alias for notice"
        self.notice(err_id, info, description, filename, line)

    def notice(self, err_id, notice,
               description="", filename="", line=0, column=0, context=None):
        "Stores an informational message about the validation"
        self._save_message(self.notices,
                           "notices",
                           {"id": err_id,
                            "message": notice,
                            "description": description,
                            "file": filename,
                            "line": line,
                            "column": column},
                           context=context)
        return self
        
    def _save_message(self, stack, type_, message, context=None):
        "Stores a message in the appropriate message stack."
        
        uid = uuid.uuid1().hex
        
        message["uid"] = uid

        # Get the context for the message (if there's a context available)<commit_msg>Updated uuid1 to uuid4 for bug 617979<commit_after>import json
import platform
import uuid

from contextgenerator import ContextGenerator
if platform.system() != "Windows":
    from outputhandlers.shellcolors import OutputHandler
else: # pragma: no cover
    from outputhandlers.windowscolors import OutputHandler

class ErrorBundle(object):
    """This class does all sorts of cool things. It gets passed around
    from test to test and collects up all the errors like the candy man
    'separating the sorrow and collecting up all the cream.' It's
    borderline magical."""
    
    def __init__(self, pipe=None, no_color=False, determined=True,
                 listed=False):
        """Specifying pipe allows the output of the bundler to be
        written to a file rather than to the screen."""
        
        self.errors = []
        self.warnings = []
        self.notices = []
        self.message_tree = {}

        self.tier = 1
        
        self.metadata = {}
        self.determined = determined
        
        self.subpackages = []
        self.package_stack = []
        
        self.detected_type = 0
        self.resources = {}
        self.reject = False
        self.unfinished = False
        
        if listed:
            self.resources["listed"] = True

        self.handler = OutputHandler(pipe, no_color)
            
        
    def error(self, err_id, error,
              description='', filename='', line=0, column=0, context=None):
        "Stores an error message for the validation process"
        self._save_message(self.errors,
                           "errors",
                           {"id": err_id,
                            "message": error,
                            "description": description,
                            "file": filename,
                            "line": line,
                            "column": column},
                           context=context)
        return self
        
    def warning(self, err_id, warning,
                description='', filename='', line=0, column=0, context=None):
        "Stores a warning message for the validation process"
        self._save_message(self.warnings,
                           "warnings",
                           {"id": err_id,
                            "message": warning,
                            "description": description,
                            "file": filename,
                            "line": line,
                            "column": column},
                           context=context)
        return self

    # NOTE : This function WILL NOT support contexts since it's deprecated.
    def info(self, err_id, info, description="", filename="", line=0):
        "An alias for notice"
        self.notice(err_id, info, description, filename, line)

    def notice(self, err_id, notice,
               description="", filename="", line=0, column=0, context=None):
        "Stores an informational message about the validation"
        self._save_message(self.notices,
                           "notices",
                           {"id": err_id,
                            "message": notice,
                            "description": description,
                            "file": filename,
                            "line": line,
                            "column": column},
                           context=context)
        return self
        
    def _save_message(self, stack, type_, message, context=None):
        "Stores a message in the appropriate message stack."
        
        uid = uuid.uuid4().hex
        
        message["uid"] = uid

        # Get the context for the message (if there's a context available)
{'fraction_non_alphanumeric': 0.08780487804878048, 'fraction_numerical': 0.003794037940379404, 'mean_word_length': 1.4660875375877047, 'pattern_counts': {'":': 38, '<': 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': '4195901', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1723, 'n_words': 547}