avwx.parsing.sanitization.cleaners.cleaners

Cleaners for elements not found in other files.

 1"""Cleaners for elements not found in other files."""
 2
 3from textwrap import wrap
 4
 5from avwx.parsing.core import is_unknown
 6from avwx.parsing.sanitization.base import CleanItem, RemoveItem
 7from avwx.static.core import WX_TRANSLATIONS
 8
 9
10class OnlySlashes(RemoveItem):
11    """Remove elements containing only '/'."""
12
13    def can_handle(self, item: str) -> bool:
14        return is_unknown(item)
15
16
17class TrimWxCode(CleanItem):
18    """Remove RE from wx codes: REVCTS -> VCTS."""
19
20    def can_handle(self, item: str) -> bool:
21        if not item.startswith("RE") or item == "RE":
22            return False
23        return all(sub in WX_TRANSLATIONS for sub in wrap(item[2:], 2))
24
25    def clean(self, item: str) -> str:
26        return item[2:]
class OnlySlashes(avwx.parsing.sanitization.cleaners.base.RemoveItem):
11class OnlySlashes(RemoveItem):
12    """Remove elements containing only '/'."""
13
14    def can_handle(self, item: str) -> bool:
15        return is_unknown(item)

Remove elements containing only '/'.

def can_handle(self, item: str) -> bool:
14    def can_handle(self, item: str) -> bool:
15        return is_unknown(item)

Return True if the element can and needs to be cleaned.

class TrimWxCode(avwx.parsing.sanitization.cleaners.base.CleanItem):
18class TrimWxCode(CleanItem):
19    """Remove RE from wx codes: REVCTS -> VCTS."""
20
21    def can_handle(self, item: str) -> bool:
22        if not item.startswith("RE") or item == "RE":
23            return False
24        return all(sub in WX_TRANSLATIONS for sub in wrap(item[2:], 2))
25
26    def clean(self, item: str) -> str:
27        return item[2:]

Remove RE from wx codes: REVCTS -> VCTS.

def can_handle(self, item: str) -> bool:
21    def can_handle(self, item: str) -> bool:
22        if not item.startswith("RE") or item == "RE":
23            return False
24        return all(sub in WX_TRANSLATIONS for sub in wrap(item[2:], 2))

Return True if the element can and needs to be cleaned.

def clean(self, item: str) -> str:
26    def clean(self, item: str) -> str:
27        return item[2:]

Clean the raw string.