Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

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

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 17, 2009, 5:27 PM

Post #1 of 6 (386 views)
Permalink
[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object

New submission from kai zhu <kaizhu256 [at] gmail>:

>>> 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

----------
components: Library (Lib)
messages: 90650
nosy: kaizhu
severity: normal
status: open
title: re.py - <compiled byte-object regular expr> encounter unexpected str-object
type: behavior
versions: Python 3.1

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 17, 2009, 5:28 PM

Post #2 of 6 (362 views)
Permalink
[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object [In reply to]

Changes by kai zhu <kaizhu256 [at] gmail>:


----------
components: +Regular Expressions

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 17, 2009, 6:40 PM

Post #3 of 6 (363 views)
Permalink
[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object [In reply to]

kai zhu <kaizhu256 [at] gmail> 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>
<http://bugs.python.org/issue6509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 18, 2009, 1:27 AM

Post #4 of 6 (356 views)
Permalink
[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object [In reply to]

Changes by Ezio Melotti <ezio.melotti [at] gmail>:


----------
nosy: +ezio.melotti
priority: -> normal

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 18, 2009, 3:27 AM

Post #5 of 6 (363 views)
Permalink
[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object [In reply to]

Changes by Georg Brandl <georg [at] python>:


----------
priority: normal -> critical

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 19, 2009, 6:45 AM

Post #6 of 6 (347 views)
Permalink
[issue6509] re.py - <compiled byte-object regular expr> encounter unexpected str-object [In reply to]

Changes by Antoine Pitrou <pitrou [at] free>:


----------
nosy: +pitrou
versions: +Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6509>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.