Descriptor to allow lazy compilation of regex
| 2 | |
| 3 | |
| 4 | class LazyRegexCompiler: |
| 5 | """Descriptor to allow lazy compilation of regex""" |
| 6 | |
| 7 | def __init__(self, pattern, flags=0): |
| 8 | self._pattern = pattern |
| 9 | self._flags = flags |
| 10 | self._compiled_regex = None |
| 11 | |
| 12 | @property |
| 13 | def compiled_regex(self): |
| 14 | if self._compiled_regex is None: |
| 15 | self._compiled_regex = re.compile(self._pattern, self._flags) |
| 16 | return self._compiled_regex |
| 17 | |
| 18 | def __get__(self, instance, owner): |
| 19 | return self.compiled_regex |
| 20 | |
| 21 | def __set__(self, instance, value): |
| 22 | raise AttributeError("Can not set attribute LazyRegexCompiler") |
no outgoing calls
no test coverage detected
searching dependent graphs…