Skip to content

Hilfsprogramme

Referenz für Hilfsprogramme und interne Dienstprogramme.

Logging

text2speech.logging_utils.SensitiveDataFilter

Bases: Filter

Redact sensitive data from logs.

Source code in text2speech/logging_utils.py
class SensitiveDataFilter(logging.Filter):
    """Redact sensitive data from logs."""

    PATTERNS = [
        (r"sk_[a-zA-Z0-9]{20,}", "sk_***REDACTED***"),
        (r'"api_key":\s*"[^"]+', '"api_key": "***"'),
    ]

    def filter(self, record: logging.LogRecord) -> bool:
        """Filter log records to redact sensitive information.

        Args:
            record (logging.LogRecord): The log record to filter.

        Returns:
            bool: Always True, as it modifies the record in-place.
        """
        if not isinstance(record.msg, str):
            return True

        msg = record.msg
        for pattern, replacement in self.PATTERNS:
            msg = re.sub(pattern, replacement, msg)
        record.msg = msg
        return True

filter(record)

Filter log records to redact sensitive information.

Parameters:

Name Type Description Default
record LogRecord

The log record to filter.

required

Returns:

Name Type Description
bool bool

Always True, as it modifies the record in-place.

Source code in text2speech/logging_utils.py
def filter(self, record: logging.LogRecord) -> bool:
    """Filter log records to redact sensitive information.

    Args:
        record (logging.LogRecord): The log record to filter.

    Returns:
        bool: Always True, as it modifies the record in-place.
    """
    if not isinstance(record.msg, str):
        return True

    msg = record.msg
    for pattern, replacement in self.PATTERNS:
        msg = re.sub(pattern, replacement, msg)
    record.msg = msg
    return True

Ausnahmen

text2speech.exceptions.Text2SpeechError

Bases: Exception

Base exception for text2speech errors.

Source code in text2speech/exceptions.py
4
5
6
7
class Text2SpeechError(Exception):
    """Base exception for text2speech errors."""

    pass

text2speech.exceptions.TTSEngineNotAvailable

Bases: Text2SpeechError

Raised when no TTS engine is available.

Source code in text2speech/exceptions.py
class TTSEngineNotAvailable(Text2SpeechError):
    """Raised when no TTS engine is available."""

    pass

text2speech.exceptions.AudioDeviceError

Bases: Text2SpeechError

Raised when audio device configuration fails.

Source code in text2speech/exceptions.py
class AudioDeviceError(Text2SpeechError):
    """Raised when audio device configuration fails."""

    pass

text2speech.exceptions.InvalidConfigurationError

Bases: Text2SpeechError

Raised when configuration is invalid.

Source code in text2speech/exceptions.py
class InvalidConfigurationError(Text2SpeechError):
    """Raised when configuration is invalid."""

    pass

Konstanten

text2speech.constants

Configuration constants for text2speech.