<commit_before>#  -*- Mode: python; coding:utf-8; indent-tabs-mode: nil -*- */
#
#  This file is part of systemd.
#
#  Copyright 2012 <NAME> <<EMAIL>>
#  Copyright 2012 <NAME> <<EMAIL>>
#  Copyright 2012 <NAME> <<EMAIL>>
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
#  systemd is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with systemd; If not, see <http://www.gnu.org/licenses/>.

import sys as _sys
import datetime as _datetime
import functools as _functools
import uuid as _uuid
import traceback as _traceback
import os as _os
from os import SEEK_SET, SEEK_CUR, SEEK_END
import logging as _logging
if _sys.version_info >= (3,):
    from collections import ChainMap
from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
                    LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
from ._journal import sendv, stream_fd
from ._reader import (_Journal, NOP, APPEND, INVALIDATE,
                      LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY)
from . import id128 as _id128

_MONOTONIC_CONVERTER = lambda x: _datetime.timedelta(microseconds=float(x))
_REALTIME_CONVERTER = lambda x: _datetime.datetime.fromtimestamp(float(x)/1E6)
DEFAULT_CONVERTERS = {
    'MESSAGE_ID': _uuid.UUID,
    '_MACHINE_ID': _uuid.UUID,
    '_BOOT_ID': _uuid.UUID,
    'PRIORITY': int,
    'LEADER': int,
    'SESSION_ID': int,
    'USERSPACE_USEC': int,
    'INITRD_USEC': int,
    'KERNEL_USEC': int,
    '_UID': int,
    '_GID': int,
    '_PID': int,
    'SYSLOG_FACILITY': int,
    'SYSLOG_PID': int,
    '_AUDIT_SESSION': int,
    '_AUDIT_LOGINUID': int,
    '_SYSTEMD_SESSION': int,
    '_SYSTEMD_OWNER_UID': int,
    'CODE_LINE': int,
    'ERRNO': int,
    'EXIT_STATUS': int,
    '_SOURCE_REALTIME_TIMESTAMP': _REALTIME_CONVERTER,
    '__REALTIME_TIMESTAMP': _REALTIME_CONVERTER,
    '_SOURCE_MONOTONIC_TIMESTAMP': _MONOTONIC_CONVERTER,
    '__MONOTONIC_TIMESTAMP': _MONOTONIC_CONVERTER,
    'COREDUMP': bytes,
    'COREDUMP_PID': int,
    'COREDUMP_UID': int,
    'COREDUMP_GID': int,
    'COREDUMP_SESSION': int,
    'COREDUMP_SIGNAL': int,
    'COREDUMP_TIMESTAMP': _REALTIME_CONVERTER,
}

if _sys.version_info >= (3,):
    _convert_unicode = _functools.partial(str, encoding='utf-8')
else:
    _convert_unicode = _functools.partial(unicode, encoding='utf-8')

class Journal(_Journal):
    def __init__(self, converters=None, flags=LOCAL_ONLY, path=None):
        """Creates instance of Journal, which allows filtering and
        return of journal entries.
        Argument `converters` is a dictionary which updates the
        DEFAULT_CONVERTERS to convert journal field values.
        Argument `flags` sets open flags of the journal, which can be one
        of, or ORed combination of constants: LOCAL_ONLY (default) opens
        journal on local machine only; RUNTIME_ONLY opens only
        volatile journal files; and SYSTEM_ONLY opens only
        journal files of system services and the kernel.
        Argument `path` is the directory of journal files. Note that
        currently flags are ignored when `path` is present as they are
        currently not relevant.
        """
        super(Journal, self).__init__(flags, path)
        if _sys.version_info >= (3,3):
            self.converters = ChainMap()
            if converters is not None:
                self.converters.maps.append(converters)<commit_msg>systemd-python: Added doc string for Journal<commit_after>#  -*- Mode: python; coding:utf-8; indent-tabs-mode: nil -*- */
#
#  This file is part of systemd.
#
#  Copyright 2012 <NAME> <<EMAIL>>
#  Copyright 2012 <NAME> <<EMAIL>>
#  Copyright 2012 <NAME> <<EMAIL>>
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
#  systemd is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with systemd; If not, see <http://www.gnu.org/licenses/>.

import sys as _sys
import datetime as _datetime
import functools as _functools
import uuid as _uuid
import traceback as _traceback
import os as _os
from os import SEEK_SET, SEEK_CUR, SEEK_END
import logging as _logging
if _sys.version_info >= (3,):
    from collections import ChainMap
from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
                    LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
from ._journal import sendv, stream_fd
from ._reader import (_Journal, NOP, APPEND, INVALIDATE,
                      LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY)
from . import id128 as _id128

_MONOTONIC_CONVERTER = lambda x: _datetime.timedelta(microseconds=float(x))
_REALTIME_CONVERTER = lambda x: _datetime.datetime.fromtimestamp(float(x)/1E6)
DEFAULT_CONVERTERS = {
    'MESSAGE_ID': _uuid.UUID,
    '_MACHINE_ID': _uuid.UUID,
    '_BOOT_ID': _uuid.UUID,
    'PRIORITY': int,
    'LEADER': int,
    'SESSION_ID': int,
    'USERSPACE_USEC': int,
    'INITRD_USEC': int,
    'KERNEL_USEC': int,
    '_UID': int,
    '_GID': int,
    '_PID': int,
    'SYSLOG_FACILITY': int,
    'SYSLOG_PID': int,
    '_AUDIT_SESSION': int,
    '_AUDIT_LOGINUID': int,
    '_SYSTEMD_SESSION': int,
    '_SYSTEMD_OWNER_UID': int,
    'CODE_LINE': int,
    'ERRNO': int,
    'EXIT_STATUS': int,
    '_SOURCE_REALTIME_TIMESTAMP': _REALTIME_CONVERTER,
    '__REALTIME_TIMESTAMP': _REALTIME_CONVERTER,
    '_SOURCE_MONOTONIC_TIMESTAMP': _MONOTONIC_CONVERTER,
    '__MONOTONIC_TIMESTAMP': _MONOTONIC_CONVERTER,
    'COREDUMP': bytes,
    'COREDUMP_PID': int,
    'COREDUMP_UID': int,
    'COREDUMP_GID': int,
    'COREDUMP_SESSION': int,
    'COREDUMP_SIGNAL': int,
    'COREDUMP_TIMESTAMP': _REALTIME_CONVERTER,
}

if _sys.version_info >= (3,):
    _convert_unicode = _functools.partial(str, encoding='utf-8')
else:
    _convert_unicode = _functools.partial(unicode, encoding='utf-8')

class Journal(_Journal):
    """Journal allows the access and filtering of systemd journal
    entries. Note that in order to access the system journal, a
    non-root user must be in the `adm` group.

    Example usage to print out all error or higher level messages
    for systemd-udevd for the boot:

    >>> myjournal = journal.Journal()
    >>> myjournal.add_boot_match(journal.CURRENT_BOOT)
    >>> myjournal.add_loglevel_matches(journal.LOG_ERR)
    >>> myjournal.add_match(_SYSTEMD_UNIT="systemd-udevd.service")
    >>> from __future__ import print_function
    >>> for entry in myjournal:
    ...    print(entry['MESSAGE'])

    See man page "systemd.journal-fields" for more info on
    typical fields found in the journal.
    """
    def __init__(self, converters=None, flags=LOCAL_ONLY, path=None):
        """Creates instance of Journal, which allows filtering and
        return of journal entries.
        Argument `converters` is a dictionary which updates the
        DEFAULT_CONVERTERS to convert journal field values.
        Argument `flags` sets open flags of the journal, which can be one
        of, or ORed combination of constants: LOCAL_ONLY (default) opens
        journal on local machine only; RUNTIME_ONLY opens only
        volatile journal files; and SYSTEM_ONLY opens only
        journal files of system services and the kernel.
        Argument `path` is the directory of journal files. Note that
        currently flags are ignored when `path` is present as they are
        currently not relevant.
        """
        super(Journal, self).__init__(flags, path)
        if _sys.version_info >= (3,3):
            self.converters = ChainMap()
            if converters is not None:
                self.converters.maps.append(converters)
{'fraction_non_alphanumeric': 0.0922104258618633, 'fraction_numerical': 0.006918764165573184, 'mean_word_length': 3.526997840172786, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '188924', 'n_tokens_mistral': 2720, 'n_tokens_neox': 2645, 'n_words': 862}