diff options
| author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-03-06 15:27:04 (GMT) |
|---|---|---|
| committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-03-06 15:27:04 (GMT) |
| commit | dab886ab0fc719dc990f5d06dc99f7ec41807827 (patch) | |
| tree | 09c9b52438420a97ac82d37147a53f42aacdd06a /Lib/sre_parse.py | |
| parent | c0ddee54b066e937b151a8598be5dba7f45f2405 (diff) | |
| download | cpython-dab886ab0fc719dc990f5d06dc99f7ec41807827.zip cpython-dab886ab0fc719dc990f5d06dc99f7ec41807827.tar.gz cpython-dab886ab0fc719dc990f5d06dc99f7ec41807827.tar.bz2 | |
Merged revisions 78729 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r78729 | ezio.melotti | 2010-03-06 17:24:08 +0200 (Sat, 06 Mar 2010) | 1 line
#6509: fix re.sub to work properly when the pattern, the string, and the replacement were all bytes. Patch by Antoine Pitrou.
........
Diffstat (limited to 'Lib/sre_parse.py')
| -rw-r--r-- | Lib/sre_parse.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index bc71b58..13737ca 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -786,12 +786,18 @@ def parse_template(source, pattern): groups = [] groupsappend = groups.append literals = [None] * len(p) + if isinstance(source, str): + encode = lambda x: x + else: + # The tokenizer implicitly decodes bytes objects as latin-1, we must + # therefore re-encode the final representation. + encode = lambda x: x.encode('latin1') for c, s in p: if c is MARK: groupsappend((i, s)) # literal[i] is already None else: - literals[i] = s + literals[i] = encode(s) i = i + 1 return groups, literals |
