openrvdas.logger.readers.reader
Abstract base class for data Readers.
1#!/usr/bin/env python3 2""" 3Abstract base class for data Readers. 4""" 5 6 7from logger.utils.base_module import BaseModule # noqa: E402 8 9 10################################################################################ 11class Reader(BaseModule): 12 """ 13 Base class Reader about which we know nothing else. 14 15 Passes arguments quiet, encoding and encoding_errors up to BaseModule 16 """ 17 ############################ 18 def __init__(self, **kwargs): 19 super().__init__(**kwargs) 20 21 ############################ 22 def read(self): 23 """ 24 read() should return None when there are no more records. 25 """ 26 raise NotImplementedError('Class %s (subclass of Reader) is missing ' 27 'implementation of read() method.' 28 % self.__class__.__name__) 29 30################################################################################ 31 32 33class StorageReader(Reader): 34 """ 35 A StorageReader is something like a file, where we can, in theory, 36 seek and rewind, or retrieve a range of records. 37 """ 38 39 ############################ 40 def __init__(self, **kwargs): 41 super().__init__(**kwargs) 42 43 ############################ 44 # Behavior is intended to mimic file seek() behavior but with 45 # respect to records: 'offset' means number of records, and origin 46 # is either 'start', 'current' or 'end'. 47 def seek(self, offset=0, origin='current'): 48 raise NotImplementedError('Class %s (subclass of StorageReader) is missing ' 49 'implementation of seek() method.' 50 % self.__class__.__name__) 51 52 ############################ 53 def read_range(self, start=None, stop=None): 54 """ 55 Read a range of records beginning with record number start, and ending 56 *before* record number stop. 57 """ 58 raise NotImplementedError('Class %s (subclass of StorageReader) is missing ' 59 'implementation of read_range() method.' 60 % self.__class__.__name__) 61 62 63################################################################################ 64class TimestampedReader(StorageReader): 65 """ 66 A TimestampedReader is a special case of a StorageReader where we 67 can seek and retrieve a range specified by timestamps. 68 """ 69 70 ############################ 71 def __init__(self, **kwargs): 72 super().__init__(**kwargs) 73 74 ############################ 75 # Behavior is intended to mimic file seek() behavior but with 76 # respect to timestamps: 'offset' means number of milliseconds, and 77 # origin is either 'start', 'current' or 'end'. 78 def seek_time(self, offset=0, origin='current'): 79 raise NotImplementedError('Class %s (subclass of TimestampedReader) is missing ' 80 'implementation of seek_time() method.' 81 % self.__class__.__name__) 82 83 ############################ 84 # Read a range of records beginning with timestamp start 85 # milliseconds, and ending *before* timestamp stop milliseconds. 86 def read_time_range(self, start=None, stop=None): 87 raise NotImplementedError('Class %s (subclass of TimestampedReader) is missing ' 88 'implementation of read_range() method.' 89 % self.__class__.__name__)
class
Reader(logger.utils.base_module.BaseModule):
12class Reader(BaseModule): 13 """ 14 Base class Reader about which we know nothing else. 15 16 Passes arguments quiet, encoding and encoding_errors up to BaseModule 17 """ 18 ############################ 19 def __init__(self, **kwargs): 20 super().__init__(**kwargs) 21 22 ############################ 23 def read(self): 24 """ 25 read() should return None when there are no more records. 26 """ 27 raise NotImplementedError('Class %s (subclass of Reader) is missing ' 28 'implementation of read() method.' 29 % self.__class__.__name__)
Base class Reader about which we know nothing else.
Passes arguments quiet, encoding and encoding_errors up to BaseModule
Reader(**kwargs)
quiet - if type checking should log type errors or operate silently.
Two additional arguments govern how records will be encoded/decoded
from bytes, if desired by the Writer subclass when it calls
_encode_str() or _decode_bytes:
encoding - 'utf-8' by default. If empty or None, do not attempt any
decoding and return raw bytes. Other possible encodings are
listed in online documentation here:
https://docs.python.org/3/library/codecs.html#standard-encodings
encoding_errors - 'ignore' by default. Other error strategies are
'strict', 'replace', and 'backslashreplace', described here:
https://docs.python.org/3/howto/unicode.html#encodings
mirror_to - Optional Writer to which all records read or transformed
by this module (if it is a Reader or Transform) will be
"mirrored" (copied). Mirroring happens asynchronously via
a queue and background thread to minimize impact on the
primary data flow. Writers cannot be mirrored.
def
read(self):
23 def read(self): 24 """ 25 read() should return None when there are no more records. 26 """ 27 raise NotImplementedError('Class %s (subclass of Reader) is missing ' 28 'implementation of read() method.' 29 % self.__class__.__name__)
read() should return None when there are no more records.
34class StorageReader(Reader): 35 """ 36 A StorageReader is something like a file, where we can, in theory, 37 seek and rewind, or retrieve a range of records. 38 """ 39 40 ############################ 41 def __init__(self, **kwargs): 42 super().__init__(**kwargs) 43 44 ############################ 45 # Behavior is intended to mimic file seek() behavior but with 46 # respect to records: 'offset' means number of records, and origin 47 # is either 'start', 'current' or 'end'. 48 def seek(self, offset=0, origin='current'): 49 raise NotImplementedError('Class %s (subclass of StorageReader) is missing ' 50 'implementation of seek() method.' 51 % self.__class__.__name__) 52 53 ############################ 54 def read_range(self, start=None, stop=None): 55 """ 56 Read a range of records beginning with record number start, and ending 57 *before* record number stop. 58 """ 59 raise NotImplementedError('Class %s (subclass of StorageReader) is missing ' 60 'implementation of read_range() method.' 61 % self.__class__.__name__)
A StorageReader is something like a file, where we can, in theory, seek and rewind, or retrieve a range of records.
StorageReader(**kwargs)
quiet - if type checking should log type errors or operate silently.
Two additional arguments govern how records will be encoded/decoded
from bytes, if desired by the Writer subclass when it calls
_encode_str() or _decode_bytes:
encoding - 'utf-8' by default. If empty or None, do not attempt any
decoding and return raw bytes. Other possible encodings are
listed in online documentation here:
https://docs.python.org/3/library/codecs.html#standard-encodings
encoding_errors - 'ignore' by default. Other error strategies are
'strict', 'replace', and 'backslashreplace', described here:
https://docs.python.org/3/howto/unicode.html#encodings
mirror_to - Optional Writer to which all records read or transformed
by this module (if it is a Reader or Transform) will be
"mirrored" (copied). Mirroring happens asynchronously via
a queue and background thread to minimize impact on the
primary data flow. Writers cannot be mirrored.
def
read_range(self, start=None, stop=None):
54 def read_range(self, start=None, stop=None): 55 """ 56 Read a range of records beginning with record number start, and ending 57 *before* record number stop. 58 """ 59 raise NotImplementedError('Class %s (subclass of StorageReader) is missing ' 60 'implementation of read_range() method.' 61 % self.__class__.__name__)
Read a range of records beginning with record number start, and ending before record number stop.
65class TimestampedReader(StorageReader): 66 """ 67 A TimestampedReader is a special case of a StorageReader where we 68 can seek and retrieve a range specified by timestamps. 69 """ 70 71 ############################ 72 def __init__(self, **kwargs): 73 super().__init__(**kwargs) 74 75 ############################ 76 # Behavior is intended to mimic file seek() behavior but with 77 # respect to timestamps: 'offset' means number of milliseconds, and 78 # origin is either 'start', 'current' or 'end'. 79 def seek_time(self, offset=0, origin='current'): 80 raise NotImplementedError('Class %s (subclass of TimestampedReader) is missing ' 81 'implementation of seek_time() method.' 82 % self.__class__.__name__) 83 84 ############################ 85 # Read a range of records beginning with timestamp start 86 # milliseconds, and ending *before* timestamp stop milliseconds. 87 def read_time_range(self, start=None, stop=None): 88 raise NotImplementedError('Class %s (subclass of TimestampedReader) is missing ' 89 'implementation of read_range() method.' 90 % self.__class__.__name__)
A TimestampedReader is a special case of a StorageReader where we can seek and retrieve a range specified by timestamps.
TimestampedReader(**kwargs)
quiet - if type checking should log type errors or operate silently.
Two additional arguments govern how records will be encoded/decoded
from bytes, if desired by the Writer subclass when it calls
_encode_str() or _decode_bytes:
encoding - 'utf-8' by default. If empty or None, do not attempt any
decoding and return raw bytes. Other possible encodings are
listed in online documentation here:
https://docs.python.org/3/library/codecs.html#standard-encodings
encoding_errors - 'ignore' by default. Other error strategies are
'strict', 'replace', and 'backslashreplace', described here:
https://docs.python.org/3/howto/unicode.html#encodings
mirror_to - Optional Writer to which all records read or transformed
by this module (if it is a Reader or Transform) will be
"mirrored" (copied). Mirroring happens asynchronously via
a queue and background thread to minimize impact on the
primary data flow. Writers cannot be mirrored.