secret labs regular expression engine various symbols used by the regular expression engine run this script to update the sre include files c 19982001 by secret labs ab see the init py file for information on usage and redistribution internal support module for sre update when constants are added or removed magic 20230612 from sre import maxrepeat maxgroups sre standard exception access as sre error should this really be here class errorexception module re def initself msg patternnone posnone self msg msg self pattern pattern self pos pos if pattern is not none and pos is not none msg s at position d msg pos if isinstancepattern str newline n else newline b n self lineno pattern countnewline 0 pos 1 self colno pos pattern rfindnewline 0 pos if newline in pattern msg s line d column d msg self lineno self colno else self lineno self colno none super initmsg class namedintconstantint def newcls value name self supernamedintconstant cls newcls value self name name return self def reprself return self name reduce none maxrepeat namedintconstantmaxrepeat maxrepeat def makecodesnames items namedintconstanti name for i name in enumeratenames globals updateitem name item for item in items return items operators opcodes makecodes failure0 success1 just because it looks better that way failure success any anyall assert assertnot at branch category charset bigcharset groupref grouprefexists in info jump literal mark maxuntil minuntil notliteral negate range repeat repeatone subpattern minrepeatone atomicgroup possessiverepeat possessiverepeatone grouprefignore inignore literalignore notliteralignore groupreflocignore inlocignore literallocignore notliterallocignore grouprefuniignore inuniignore literaluniignore notliteraluniignore rangeuniignore the following opcodes are only occurred in the parser output but not in the compiled code minrepeat maxrepeat del opcodes2 remove minrepeat and maxrepeat positions atcodes makecodes atbeginning atbeginningline atbeginningstring atboundary atnonboundary atend atendline atendstring atlocboundary atlocnonboundary atuniboundary atuninonboundary categories chcodes makecodes categorydigit categorynotdigit categoryspace categorynotspace categoryword categorynotword categorylinebreak categorynotlinebreak categorylocword categorylocnotword categoryunidigit categoryuninotdigit categoryunispace categoryuninotspace categoryuniword categoryuninotword categoryunilinebreak categoryuninotlinebreak replacement operations for ignore case mode opignore literal literalignore notliteral notliteralignore oplocaleignore literal literallocignore notliteral notliterallocignore opunicodeignore literal literaluniignore notliteral notliteraluniignore atmultiline atbeginning atbeginningline atend atendline atlocale atboundary atlocboundary atnonboundary atlocnonboundary atunicode atboundary atuniboundary atnonboundary atuninonboundary chlocale categorydigit categorydigit categorynotdigit categorynotdigit categoryspace categoryspace categorynotspace categorynotspace categoryword categorylocword categorynotword categorylocnotword categorylinebreak categorylinebreak categorynotlinebreak categorynotlinebreak chunicode categorydigit categoryunidigit categorynotdigit categoryuninotdigit categoryspace categoryunispace categorynotspace categoryuninotspace categoryword categoryuniword categorynotword categoryuninotword categorylinebreak categoryunilinebreak categorynotlinebreak categoryuninotlinebreak flags sreflagignorecase 2 case insensitive sreflaglocale 4 honour system locale sreflagmultiline 8 treat target as multiline string sreflagdotall 16 treat target as a single string sreflagunicode 32 use unicode locale sreflagverbose 64 ignore whitespace and comments sreflagdebug 128 debugging sreflagascii 256 use ascii locale flags for info primitive sreinfoprefix 1 has prefix sreinfoliteral 2 entire pattern is literal given by prefix sreinfocharset 4 pattern starts with character from given set secret labs regular expression engine various symbols used by the regular expression engine run this script to update the _sre include files c 1998 2001 by secret labs ab see the __init__ py file for information on usage and redistribution internal support module for sre update when constants are added or removed sre standard exception access as sre error should this really be here exception raised for invalid regular expressions attributes msg the unformatted error message pattern the regular expression pattern pos the index in the pattern where compilation failed may be none lineno the line corresponding to pos may be none colno the column corresponding to pos may be none operators failure 0 success 1 just because it looks better that way the following opcodes are only occurred in the parser output but not in the compiled code remove min_repeat and max_repeat positions categories replacement operations for ignore case mode flags case insensitive honour system locale treat target as multiline string treat target as a single string use unicode locale ignore whitespace and comments debugging use ascii locale flags for info primitive has prefix entire pattern is literal given by prefix pattern starts with character from given set
MAGIC = 20230612

from _sre import MAXREPEAT, MAXGROUPS




class error(Exception):
    

    __module__ = 're'

    def __init__(self, msg, pattern=None, pos=None):
        self.msg = msg
        self.pattern = pattern
        self.pos = pos
        if pattern is not None and pos is not None:
            msg = '%s at position %d' % (msg, pos)
            if isinstance(pattern, str):
                newline = '\n'
            else:
                newline = b'\n'
            self.lineno = pattern.count(newline, 0, pos) + 1
            self.colno = pos - pattern.rfind(newline, 0, pos)
            if newline in pattern:
                msg = '%s (line %d, column %d)' % (msg, self.lineno, self.colno)
        else:
            self.lineno = self.colno = None
        super().__init__(msg)


class _NamedIntConstant(int):
    def __new__(cls, value, name):
        self = super(_NamedIntConstant, cls).__new__(cls, value)
        self.name = name
        return self

    def __repr__(self):
        return self.name

    __reduce__ = None

MAXREPEAT = _NamedIntConstant(MAXREPEAT, 'MAXREPEAT')

def _makecodes(*names):
    items = [_NamedIntConstant(i, name) for i, name in enumerate(names)]
    globals().update({item.name: item for item in items})
    return items


OPCODES = _makecodes(
    
    'FAILURE', 'SUCCESS',

    'ANY', 'ANY_ALL',
    'ASSERT', 'ASSERT_NOT',
    'AT',
    'BRANCH',
    'CATEGORY',
    'CHARSET', 'BIGCHARSET',
    'GROUPREF', 'GROUPREF_EXISTS',
    'IN',
    'INFO',
    'JUMP',
    'LITERAL',
    'MARK',
    'MAX_UNTIL',
    'MIN_UNTIL',
    'NOT_LITERAL',
    'NEGATE',
    'RANGE',
    'REPEAT',
    'REPEAT_ONE',
    'SUBPATTERN',
    'MIN_REPEAT_ONE',
    'ATOMIC_GROUP',
    'POSSESSIVE_REPEAT',
    'POSSESSIVE_REPEAT_ONE',

    'GROUPREF_IGNORE',
    'IN_IGNORE',
    'LITERAL_IGNORE',
    'NOT_LITERAL_IGNORE',

    'GROUPREF_LOC_IGNORE',
    'IN_LOC_IGNORE',
    'LITERAL_LOC_IGNORE',
    'NOT_LITERAL_LOC_IGNORE',

    'GROUPREF_UNI_IGNORE',
    'IN_UNI_IGNORE',
    'LITERAL_UNI_IGNORE',
    'NOT_LITERAL_UNI_IGNORE',
    'RANGE_UNI_IGNORE',

    
    
    'MIN_REPEAT', 'MAX_REPEAT',
)
del OPCODES[-2:] 


ATCODES = _makecodes(
    'AT_BEGINNING', 'AT_BEGINNING_LINE', 'AT_BEGINNING_STRING',
    'AT_BOUNDARY', 'AT_NON_BOUNDARY',
    'AT_END', 'AT_END_LINE', 'AT_END_STRING',

    'AT_LOC_BOUNDARY', 'AT_LOC_NON_BOUNDARY',

    'AT_UNI_BOUNDARY', 'AT_UNI_NON_BOUNDARY',
)


CHCODES = _makecodes(
    'CATEGORY_DIGIT', 'CATEGORY_NOT_DIGIT',
    'CATEGORY_SPACE', 'CATEGORY_NOT_SPACE',
    'CATEGORY_WORD', 'CATEGORY_NOT_WORD',
    'CATEGORY_LINEBREAK', 'CATEGORY_NOT_LINEBREAK',

    'CATEGORY_LOC_WORD', 'CATEGORY_LOC_NOT_WORD',

    'CATEGORY_UNI_DIGIT', 'CATEGORY_UNI_NOT_DIGIT',
    'CATEGORY_UNI_SPACE', 'CATEGORY_UNI_NOT_SPACE',
    'CATEGORY_UNI_WORD', 'CATEGORY_UNI_NOT_WORD',
    'CATEGORY_UNI_LINEBREAK', 'CATEGORY_UNI_NOT_LINEBREAK',
)



OP_IGNORE = {
    LITERAL: LITERAL_IGNORE,
    NOT_LITERAL: NOT_LITERAL_IGNORE,
}

OP_LOCALE_IGNORE = {
    LITERAL: LITERAL_LOC_IGNORE,
    NOT_LITERAL: NOT_LITERAL_LOC_IGNORE,
}

OP_UNICODE_IGNORE = {
    LITERAL: LITERAL_UNI_IGNORE,
    NOT_LITERAL: NOT_LITERAL_UNI_IGNORE,
}

AT_MULTILINE = {
    AT_BEGINNING: AT_BEGINNING_LINE,
    AT_END: AT_END_LINE
}

AT_LOCALE = {
    AT_BOUNDARY: AT_LOC_BOUNDARY,
    AT_NON_BOUNDARY: AT_LOC_NON_BOUNDARY
}

AT_UNICODE = {
    AT_BOUNDARY: AT_UNI_BOUNDARY,
    AT_NON_BOUNDARY: AT_UNI_NON_BOUNDARY
}

CH_LOCALE = {
    CATEGORY_DIGIT: CATEGORY_DIGIT,
    CATEGORY_NOT_DIGIT: CATEGORY_NOT_DIGIT,
    CATEGORY_SPACE: CATEGORY_SPACE,
    CATEGORY_NOT_SPACE: CATEGORY_NOT_SPACE,
    CATEGORY_WORD: CATEGORY_LOC_WORD,
    CATEGORY_NOT_WORD: CATEGORY_LOC_NOT_WORD,
    CATEGORY_LINEBREAK: CATEGORY_LINEBREAK,
    CATEGORY_NOT_LINEBREAK: CATEGORY_NOT_LINEBREAK
}

CH_UNICODE = {
    CATEGORY_DIGIT: CATEGORY_UNI_DIGIT,
    CATEGORY_NOT_DIGIT: CATEGORY_UNI_NOT_DIGIT,
    CATEGORY_SPACE: CATEGORY_UNI_SPACE,
    CATEGORY_NOT_SPACE: CATEGORY_UNI_NOT_SPACE,
    CATEGORY_WORD: CATEGORY_UNI_WORD,
    CATEGORY_NOT_WORD: CATEGORY_UNI_NOT_WORD,
    CATEGORY_LINEBREAK: CATEGORY_UNI_LINEBREAK,
    CATEGORY_NOT_LINEBREAK: CATEGORY_UNI_NOT_LINEBREAK
}


SRE_FLAG_IGNORECASE = 2 
SRE_FLAG_LOCALE = 4 
SRE_FLAG_MULTILINE = 8 
SRE_FLAG_DOTALL = 16 
SRE_FLAG_UNICODE = 32 
SRE_FLAG_VERBOSE = 64 
SRE_FLAG_DEBUG = 128 
SRE_FLAG_ASCII = 256 


SRE_INFO_PREFIX = 1 
SRE_INFO_LITERAL = 2 
SRE_INFO_CHARSET = 4