[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object

kai zhu report at bugs.python.org
Sat Jul 18 03:40:54 CEST 2009


kai zhu <kaizhu256 at gmail.com> added the comment:

traced culprit to sre_parse.py <line 711> (where literal is always str):

...
def parse_template(source, pattern):
    # parse 're' replacement string into list of literals and
    # group references
    s = Tokenizer(source)
    sget = s.get
    p = []
    a = p.append
    def literal(literal, p=p, pappend=a):
        if p and p[-1][0] is LITERAL:
            p[-1] = LITERAL, p[-1][1] + literal
        else:
            pappend((LITERAL, literal))
...

a possible hack-around is <line 717>:

...
    a = p.append
    def literal(literal, p=p, pappend=a):
        if isinstance(source, (bytes, bytearray)): # hack
            literal = literal.encode()             # hack str->bytes
        if p and p[-1][0] is LITERAL:
...

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6509>
_______________________________________


More information about the Python-bugs-list mailing list