Issue6509
Created on 2009-07-18 00:27 by kaizhu, last changed 2009-11-04 22:39 by pitrou.
|
msg90650 - (view) |
Author: kai zhu (kaizhu) |
Date: 2009-07-18 00:27 |
|
>>> import re
>>> compiled = re.compile(b"a(\w)")
>>> s = b"aa"
>>> s = compiled.sub(b"a\\1", s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../lib/python3.1/re.py", line 303, in filter
return sre_parse.expand_template(template, match)
File ".../lib/python3.1/sre_parse.py", line 810, in expand_template
return sep.join(literals)
TypeError: sequence item 0: expected bytes, str found
|
|
msg90651 - (view) |
Author: kai zhu (kaizhu) |
Date: 2009-07-18 01:40 |
|
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:
...
|
|
msg94907 - (view) |
Author: Antoine Pitrou (pitrou) |
Date: 2009-11-04 22:39 |
|
Here is a patch.
|
|
| Date |
User |
Action |
Args |
| 2009-11-04 22:39:42 | pitrou | set | files:
+ parse_template.patch
nosy:
+ effbot messages:
+ msg94907
keywords:
+ patch stage: patch review |
| 2009-07-19 13:45:27 | pitrou | set | nosy:
+ pitrou
versions:
+ Python 3.2 |
| 2009-07-18 10:27:00 | georg.brandl | set | priority: normal -> critical |
| 2009-07-18 08:27:26 | ezio.melotti | set | priority: normal nosy:
+ ezio.melotti
|
| 2009-07-18 01:40:53 | kaizhu | set | messages:
+ msg90651 |
| 2009-07-18 00:28:27 | kaizhu | set | components:
+ Regular Expressions |
| 2009-07-18 00:27:24 | kaizhu | create | |
|