How to use the scrubadub.exceptions.UnexpectedFilth function in scrubadub

To help you get started, we’ve selected a few scrubadub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datascopeanalytics / scrubadub / tests / test_detector.py View on Github external
def test_regex_filth(self):
        """make sure RegexDetector only works with RegexFilth"""

        class MyFilth(Filth):
            pass

        class MyDetector(RegexDetector):
            filth_cls = MyFilth

        text = 'dirty dirty text'
        detector = MyDetector()
        with self.assertRaises(UnexpectedFilth):
            for filth in detector.iter_filth(text):
                pass
github datascopeanalytics / scrubadub / scrubadub / detectors / base.py View on Github external
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)