~homeworkprod/syslogmp

56ce70ee81266625f55abf8c33d0469a47ce6bea — Jochen Kupperschmidt 3 years ago 15a489c
Turn namedtuples `Message`, `PriorityValue` into dataclasses
3 files changed, 19 insertions(+), 5 deletions(-)

M CHANGES.rst
M src/syslogmp/message.py
M src/syslogmp/parser.py
M CHANGES.rst => CHANGES.rst +2 -0
@@ 9,6 9,8 @@ Unreleased

- Removed support for Python versions 3.6.

- Turn namedtuples ``Message`` and ``PriorityValue`` into dataclasses.


Version 0.3
-----------

M src/syslogmp/message.py => src/syslogmp/message.py +12 -2
@@ 6,7 6,17 @@ syslogmp.message
:License: MIT, see LICENSE for details.
"""

from collections import namedtuple
from dataclasses import dataclass
from datetime import datetime

from .facility import Facility
from .severity import Severity

Message = namedtuple('Message', 'facility severity timestamp hostname message')

@dataclass(frozen=True)
class Message:
    facility: Facility
    severity: Severity
    timestamp: datetime
    hostname: str
    message: bytes

M src/syslogmp/parser.py => src/syslogmp/parser.py +5 -3
@@ 24,7 24,7 @@ latter.
:License: MIT, see LICENSE for details.
"""

from collections import namedtuple
from dataclasses import dataclass
from datetime import datetime

from .facility import Facility


@@ 114,8 114,10 @@ class _Parser:
        return self.stream.read_remainder()


class PriorityValue(namedtuple('PriorityValue', 'facility severity')):
    pass
@dataclass(frozen=True)
class PriorityValue:
    facility: Facility
    severity: Severity


def _create_priority_value_from_pri_part(pri_part):