From c5857893499e2a75d401a5c207d04dd0d4d66ec7 Mon Sep 17 00:00:00 2001 From: blissful Date: Mon, 6 May 2024 12:12:06 -0400 Subject: [PATCH] hmm --- rose/rule_parser.py | 20 ++++++++++---------- rose/rule_parser_test.py | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rose/rule_parser.py b/rose/rule_parser.py index fc1068e..a3e75c4 100644 --- a/rose/rule_parser.py +++ b/rose/rule_parser.py @@ -7,12 +7,12 @@ from __future__ import annotations +import dataclasses import io import logging import re import shlex from collections.abc import Sequence -from dataclasses import dataclass from typing import Literal import click @@ -223,7 +223,7 @@ def __str__(self) -> str: ] -@dataclass +@dataclasses.dataclass class ReplaceAction: """ Replaces the matched tag with `replacement`. For multi-valued tags, `;` is treated as a @@ -233,7 +233,7 @@ class ReplaceAction: replacement: str -@dataclass +@dataclasses.dataclass class SedAction: """ Executes a regex substitution on a tag value. @@ -243,7 +243,7 @@ class SedAction: dst: str -@dataclass +@dataclasses.dataclass class SplitAction: """ Splits a tag into multiple tags on the provided delimiter. This action is only allowed on @@ -253,7 +253,7 @@ class SplitAction: delimiter: str -@dataclass +@dataclasses.dataclass class AddAction: """ Adds a value to the tag. This action is only allowed on multi-value tags. If the value already @@ -263,14 +263,14 @@ class AddAction: value: str -@dataclass +@dataclasses.dataclass class DeleteAction: """ Deletes the tag value. """ -@dataclass +@dataclasses.dataclass(slots=True) class Pattern: # Substring match with support for `^$` strict start / strict end matching. needle: str @@ -314,7 +314,7 @@ def __str__(self) -> str: return r -@dataclass() +@dataclasses.dataclass(slots=True) class Matcher: # Tags to test against the pattern. If any tags match the pattern, the action will be ran # against the track. @@ -411,7 +411,7 @@ def parse(cls, raw: str, *, rule_name: str = "matcher") -> Matcher: return matcher -@dataclass +@dataclasses.dataclass(slots=True) class Action: # The tags to apply the action on. Defaults to the tag that the pattern matched. tags: list[Tag] @@ -727,7 +727,7 @@ def parse( return action -@dataclass +@dataclasses.dataclass class Rule: matcher: Matcher actions: list[Action] diff --git a/rose/rule_parser_test.py b/rose/rule_parser_test.py index 445a350..54f3868 100644 --- a/rose/rule_parser_test.py +++ b/rose/rule_parser_test.py @@ -58,8 +58,8 @@ def test_rule_parse_matcher() -> None: assert Matcher.parse("tracktitle:Track$") == Matcher( ["tracktitle"], Pattern("Track", strict_end=True) ) - assert Matcher.parse(r"tracktitle:\^Track") == Matcher(["tracktitle"], Pattern("^Track")) - assert Matcher.parse(r"tracktitle:Track\$") == Matcher(["tracktitle"], Pattern("Track$")) + assert Matcher.parse(r"tracktitle:\^Track") == Matcher(["tracktitle"], Pattern(r"\^Track")) + assert Matcher.parse(r"tracktitle:Track\$") == Matcher(["tracktitle"], Pattern(r"Track\$")) def test_err(rule: str, err: str) -> None: with pytest.raises(RuleSyntaxError) as exc: @@ -535,13 +535,13 @@ def test_rule_parsing_multi_value_validation() -> None: def test_rule_parsing_defaults() -> None: rule = Rule.parse("tracktitle:Track", ["replace:hi"]) assert rule.actions[0].pattern is not None - assert rule.actions[0].pattern.pattern == "Track" + assert rule.actions[0].pattern.needle == "Track" rule = Rule.parse("tracktitle:Track", ["tracktitle/replace:hi"]) assert rule.actions[0].pattern is not None - assert rule.actions[0].pattern.pattern == "Track" + assert rule.actions[0].pattern.needle == "Track" rule = Rule.parse("tracktitle:Track", ["tracktitle:Lack/replace:hi"]) assert rule.actions[0].pattern is not None - assert rule.actions[0].pattern.pattern == "Lack" + assert rule.actions[0].pattern.needle == "Lack" def test_parser_take() -> None: