Source code for scrubadub.detectors.base

import re

from .. import exceptions
from ..filth import Filth, RegexFilth


[docs]class Detector(object): filth_cls = None
[docs] def iter_filth(self, text): raise NotImplementedError('must be overridden by base classes')
[docs]class RegexDetector(Detector):
[docs] def iter_filth(self, text): if not issubclass(self.filth_cls, RegexFilth): raise exceptions.UnexpectedFilth( 'RegexFilth required for RegexDetector' ) if self.filth_cls.regex is None: raise StopIteration for match in self.filth_cls.regex.finditer(text): yield self.filth_cls(match)