openrvdas.logger.transforms.split_transform

Split a single record at a delimiter string, into an array of records.

 1#!/usr/bin/env python3
 2"""Split a single record at a delimiter string, into an array of records."""
 3
 4import logging
 5
 6from logger.transforms.transform import Transform  # noqa: E402
 7
 8
 9################################################################################
10class SplitTransform(Transform):
11    def __init__(self, sep='\n', **kwargs):
12        """
13        ```
14        sep       Field separator string; if omitted, split along newlines.
15        ```
16        """
17        super().__init__(**kwargs)  # processes 'quiet' and type hints
18        self.sep = sep
19
20    ############################
21    def transform(self, record: str) -> list:
22        """Split record into array of records along separator."""
23
24        # See if it's something we can process, and if not, try digesting
25        if not self.can_process_record(record):  # inherited from BaseModule()
26            return self.digest_record(record)  # inherited from BaseModule()
27
28        if not type(record) is str:
29            logging.warning('SplitTransform received non-string input: %s', record)
30            results = None
31
32        # If here, we've got a simple string.
33        else:
34            results = record.split(self.sep)
35
36        return [record for record in results if record]
class SplitTransform(logger.transforms.transform.Transform):
11class SplitTransform(Transform):
12    def __init__(self, sep='\n', **kwargs):
13        """
14        ```
15        sep       Field separator string; if omitted, split along newlines.
16        ```
17        """
18        super().__init__(**kwargs)  # processes 'quiet' and type hints
19        self.sep = sep
20
21    ############################
22    def transform(self, record: str) -> list:
23        """Split record into array of records along separator."""
24
25        # See if it's something we can process, and if not, try digesting
26        if not self.can_process_record(record):  # inherited from BaseModule()
27            return self.digest_record(record)  # inherited from BaseModule()
28
29        if not type(record) is str:
30            logging.warning('SplitTransform received non-string input: %s', record)
31            results = None
32
33        # If here, we've got a simple string.
34        else:
35            results = record.split(self.sep)
36
37        return [record for record in results if record]

Base class Transform about which we know nothing else.

Passes arguments quiet, encoding and encoding_errors up to BaseModule

SplitTransform(sep='\n', **kwargs)
12    def __init__(self, sep='\n', **kwargs):
13        """
14        ```
15        sep       Field separator string; if omitted, split along newlines.
16        ```
17        """
18        super().__init__(**kwargs)  # processes 'quiet' and type hints
19        self.sep = sep
sep       Field separator string; if omitted, split along newlines.
sep
def transform(self, record: str) -> list:
22    def transform(self, record: str) -> list:
23        """Split record into array of records along separator."""
24
25        # See if it's something we can process, and if not, try digesting
26        if not self.can_process_record(record):  # inherited from BaseModule()
27            return self.digest_record(record)  # inherited from BaseModule()
28
29        if not type(record) is str:
30            logging.warning('SplitTransform received non-string input: %s', record)
31            results = None
32
33        # If here, we've got a simple string.
34        else:
35            results = record.split(self.sep)
36
37        return [record for record in results if record]

Split record into array of records along separator.