| 38 | |
| 39 | |
| 40 | def premodule(self): |
| 41 | # make sure the user actually provided an expression to search for |
| 42 | if not self.expression: |
| 43 | self.error("Must define an expression to search for using --search_expression") |
| 44 | sys.exit(1) |
| 45 | |
| 46 | # define the regex flags, based on arguments |
| 47 | re_flags = 0 |
| 48 | if self.ignorecase: |
| 49 | re_flags = re_flags | re.IGNORECASE |
| 50 | |
| 51 | # Create the regular expression |
| 52 | try: |
| 53 | # convert expression to bytes so it can accurately compare to |
| 54 | # the connection data (which is also of type bytes) |
| 55 | byte_expression = bytes(self.expression, 'utf-8') |
| 56 | self.regex = re.compile(byte_expression, re_flags) |
| 57 | except Exception as e: |
| 58 | self.error("Could not compile regex ({0})".format(e)) |
| 59 | sys.exit(1) |
| 60 | |
| 61 | |
| 62 | |