This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SaferScanner is just like re.Scanner, but it neuters any grouping in the lexicon | |
# regular expressions and throws an error on group references, named groups, or | |
# regex in-pattern flags. Any of those can break correct operation of Scanner. | |
import re | |
from sre_constants import BRANCH, SUBPATTERN, GROUPREF, GROUPREF_IGNORE, GROUPREF_EXISTS | |
class SaferScanner(re.Scanner): | |
def __init__(self, lexicon, flags=0): | |
self.lexicon = lexicon |