<commit_before>""" Internal utility clases for the serial.core package.

"""
from __future__ import absolute_import


class TimeFormat(object):
    """ Convert datetime-like objects to formatted strings. 
    
    This is a replacement for datetime.strftime that handles years before 1900.    
    Only the most basic fields are supported, and it is not locale-aware.
    
    """
    _escape = "%"
    _field_defs = {
        "d": ("02d", lambda time: time.day),
        "f": ("06d", lambda time: time.microsecond),
        "H": ("02d", lambda time: time.hour),
        "I": ("02d", lambda time: time.hour%12),
        "M": ("02d", lambda time: time.minute),
        "m": ("02d", lambda time: time.month),
        "p": ("s", lambda time: "AM" if time.hour < 12 else "PM"),  # no locale
        "S": ("02d", lambda time: time.second),
        "Y": ("04d", lambda time: time.year),
        "y": ("02d", lambda time: time.year%100)}

    def __init__(self, timefmt):
        """ Initialize this object.
        
        """
        def scan():
            """ Iterate over timefmt while unescaping characters. """
            esc = False
            for char in timefmt:
                if char == self._escape and not esc:
                    # An unescaped escape character.
                    esc = True
                else:
                    # A regular character.
                    yield char, esc
                    esc = False
            return

        # The presumed use case is multiple conversions using the same format
        # string, so scan the string once and build a template.
        self._template = []
        self._fields = []
        for char, esc in scan():
            if not esc:
                # A character literal
                self._template.append(char)
                continue
            # Add a new field.
            try:
                field = self._field_defs[char]
            except:
                raise ValueError("uknown field specifier: {0:s}".format(char))<commit_msg>fixed typo in _util.py module<commit_after>""" Internal utility clases for the serial.core package.

"""
from __future__ import absolute_import


class TimeFormat(object):
    """ Convert datetime-like objects to formatted strings. 
    
    This is a replacement for datetime.strftime that handles years before 1900.    
    Only the most basic fields are supported, and it is not locale-aware.
    
    """
    _escape = "%"
    _field_defs = {
        "d": ("02d", lambda time: time.day),
        "f": ("06d", lambda time: time.microsecond),
        "H": ("02d", lambda time: time.hour),
        "I": ("02d", lambda time: time.hour%12),
        "M": ("02d", lambda time: time.minute),
        "m": ("02d", lambda time: time.month),
        "p": ("s", lambda time: "AM" if time.hour < 12 else "PM"),  # no locale
        "S": ("02d", lambda time: time.second),
        "Y": ("04d", lambda time: time.year),
        "y": ("02d", lambda time: time.year%100)}

    def __init__(self, timefmt):
        """ Initialize this object.
        
        """
        def scan():
            """ Iterate over timefmt while unescaping characters. """
            esc = False
            for char in timefmt:
                if char == self._escape and not esc:
                    # An unescaped escape character.
                    esc = True
                else:
                    # A regular character.
                    yield char, esc
                    esc = False
            return

        # The presumed use case is multiple conversions using the same format
        # string, so scan the string once and build a template.
        self._template = []
        self._fields = []
        for char, esc in scan():
            if not esc:
                # A character literal
                self._template.append(char)
                continue
            # Add a new field.
            try:
                field = self._field_defs[char]
            except:
                raise ValueError("unknown field specifier: {0:s}".format(char))
{'fraction_non_alphanumeric': 0.11193111931119311, 'fraction_numerical': 0.014760147601476014, 'mean_word_length': 1.6609947643979057, 'pattern_counts': {'":': 20, '<': 5, '<?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': '6397213', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1056, 'n_words': 389}