<commit_before>""" Module to read and convert TAI64(n) hex strings as used by DJBDNS.

    decode_tai64n("hex_string")
        decodes a hex string representing a TAI64(n) external date and returns
        a datetime.datetime object at UTC.
    utc2tai(datetime.datetime.now())
        returns a datetime.datetime object representing TAI from a datetime.datetime
        object at UTC. 
"""


from datetime import datetime, timedelta
from operator import itemgetter


class TAI64DecodeError(Exception):
    """ TAI64 decode error.
    """
    pass


def __conversion_table():
    """ returns [datetime, value] ordered reverse by date
        where value == seconds between TAI and UTC
    
    Example:
    >>> __conversion_table()[-1]
    (datetime.datetime(1972, 1, 1, 0, 0), 10.0)
    """
    # update this table as new values become known
    # source: ftp://maia.usno.navy.mil/ser7/tai-utc.dat
    conversion_table = [(datetime(1972, 01,  1), 10.0),
                        (datetime(1972, 07,  1), 11.0),
                        (datetime(1973, 01,  1), 12.0),
                        (datetime(1974, 01,  1), 13.0),
                        (datetime(1975, 01,  1), 14.0),
                        (datetime(1976, 01,  1), 15.0),
                        (datetime(1977, 01,  1), 16.0),
                        (datetime(1978, 01,  1), 17.0),
                        (datetime(1979, 01,  1), 18.0),
                        (datetime(1980, 01,  1), 19.0),
                        (datetime(1981, 07,  1), 20.0),
                        (datetime(1982, 07,  1), 21.0),
                        (datetime(1983, 07,  1), 22.0),
                        (datetime(1985, 07,  1), 23.0),
                        (datetime(1988, 01,  1), 24.0),
                        (datetime(1990, 01,  1), 25.0),
                        (datetime(1991, 01,  1), 26.0),
                        (datetime(1992, 07,  1), 27.0),
                        (datetime(1993, 07,  1), 28.0),
                        (datetime(1994, 07,  1), 29.0),
                        (datetime(1996, 01,  1), 30.0),
                        (datetime(1997, 07,  1), 31.0),
                        (datetime(1999, 01,  1), 32.0),
                        (datetime(2006, 01,  1), 33.0),
                        (datetime(2009, 01,  1), 34.0),
                        # add new values here
                       ]
    conversion_table.sort(key=itemgetter(0), reverse=True)
    return conversion_table

def __tai_seconds(date, table=__conversion_table()):
    """ returns seconds of TAI-offset from UTC at date given.
        Works only on dates later than 01.01.1972.
    
    Example:
        >>> __tai_seconds(datetime(1992, 6, 2, 8, 7, 9))
        26.0
        >>> __tai_seconds(datetime(1971, 6, 2, 8, 7, 9))
        False
    """
    for x in table:
        if date > x[0]:
            return x[1]
    return False


def __tai2utc(date):
    """ converts datetime.datetime TAI to datetime.datetime UTC.
        Works only on dates later than 01.01.1972.
    
    Example
        >>> __tai2utc(datetime(1992, 6, 2, 8, 7, 9))
        datetime.datetime(1992, 6, 2, 8, 6, 43)
    """
    seconds = __tai_seconds(date)
    return seconds and (date - timedelta(0, seconds))

<commit_msg>Irrelevate Leerzeile.<commit_after>""" Module to read and convert TAI64(n) hex strings as used by DJBDNS.

    decode_tai64n("hex_string")
        decodes a hex string representing a TAI64(n) external date and returns
        a datetime.datetime object at UTC.
    utc2tai(datetime.datetime.now())
        returns a datetime.datetime object representing TAI from a datetime.datetime
        object at UTC. 
"""


from datetime import datetime, timedelta
from operator import itemgetter


class TAI64DecodeError(Exception):
    """ TAI64 decode error.
    """
    pass


def __conversion_table():
    """ returns [datetime, value] ordered reverse by date
        where value == seconds between TAI and UTC
    
    Example:
    >>> __conversion_table()[-1]
    (datetime.datetime(1972, 1, 1, 0, 0), 10.0)
    """
    # update this table as new values become known
    # source: ftp://maia.usno.navy.mil/ser7/tai-utc.dat
    conversion_table = [(datetime(1972, 01,  1), 10.0),
                        (datetime(1972, 07,  1), 11.0),
                        (datetime(1973, 01,  1), 12.0),
                        (datetime(1974, 01,  1), 13.0),
                        (datetime(1975, 01,  1), 14.0),
                        (datetime(1976, 01,  1), 15.0),
                        (datetime(1977, 01,  1), 16.0),
                        (datetime(1978, 01,  1), 17.0),
                        (datetime(1979, 01,  1), 18.0),
                        (datetime(1980, 01,  1), 19.0),
                        (datetime(1981, 07,  1), 20.0),
                        (datetime(1982, 07,  1), 21.0),
                        (datetime(1983, 07,  1), 22.0),
                        (datetime(1985, 07,  1), 23.0),
                        (datetime(1988, 01,  1), 24.0),
                        (datetime(1990, 01,  1), 25.0),
                        (datetime(1991, 01,  1), 26.0),
                        (datetime(1992, 07,  1), 27.0),
                        (datetime(1993, 07,  1), 28.0),
                        (datetime(1994, 07,  1), 29.0),
                        (datetime(1996, 01,  1), 30.0),
                        (datetime(1997, 07,  1), 31.0),
                        (datetime(1999, 01,  1), 32.0),
                        (datetime(2006, 01,  1), 33.0),
                        (datetime(2009, 01,  1), 34.0),
                        # add new values here
                       ]
    conversion_table.sort(key=itemgetter(0), reverse=True)
    return conversion_table


def __tai_seconds(date, table=__conversion_table()):
    """ returns seconds of TAI-offset from UTC at date given.
        Works only on dates later than 01.01.1972.
    
    Example:
        >>> __tai_seconds(datetime(1992, 6, 2, 8, 7, 9))
        26.0
        >>> __tai_seconds(datetime(1971, 6, 2, 8, 7, 9))
        False
    """
    for x in table:
        if date > x[0]:
            return x[1]
    return False


def __tai2utc(date):
    """ converts datetime.datetime TAI to datetime.datetime UTC.
        Works only on dates later than 01.01.1972.
    
    Example
        >>> __tai2utc(datetime(1992, 6, 2, 8, 7, 9))
        datetime.datetime(1992, 6, 2, 8, 6, 43)
    """
    seconds = __tai_seconds(date)
    return seconds and (date - timedelta(0, seconds))


{'fraction_non_alphanumeric': 0.12921607885415062, 'fraction_numerical': 0.1034960726936701, 'mean_word_length': 1.5647709320695102, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7086438', 'n_tokens_mistral': 2483, 'n_tokens_neox': 1933, 'n_words': 565}