From 56ce70ee81266625f55abf8c33d0469a47ce6bea Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sat, 3 Apr 2021 19:42:15 +0200 Subject: [PATCH] Turn namedtuples `Message`, `PriorityValue` into dataclasses --- CHANGES.rst | 2 ++ src/syslogmp/message.py | 14 ++++++++++++-- src/syslogmp/parser.py | 8 +++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 65d66ed..2257183 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -9,6 +9,8 @@ Unreleased - Removed support for Python versions 3.6. +- Turn namedtuples ``Message`` and ``PriorityValue`` into dataclasses. + Version 0.3 ----------- diff --git a/src/syslogmp/message.py b/src/syslogmp/message.py index 77ae3f0..5a9aed8 100644 --- a/src/syslogmp/message.py +++ b/src/syslogmp/message.py @@ -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 diff --git a/src/syslogmp/parser.py b/src/syslogmp/parser.py index 68f6a4f..114c8b4 100644 --- a/src/syslogmp/parser.py +++ b/src/syslogmp/parser.py @@ -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): -- 2.45.2