[Python-3000] bytes regular expression?

Victor Stinner victor.stinner at haypocalc.com
Thu Aug 9 18:38:00 CEST 2007


On Thursday 09 August 2007 17:40:58 I wrote:
> My attached patch fix both bugs:
>  - convert bytes to str8 in _compile() to be able to hash it
>  - add a special version of escape() for bytes

My first try was buggy for this snippet code:
   import re
   assert type(re.sub(b'', b'', b'')) is bytes
   assert type(re.sub(b'(x)', b'[\\1]', b'x')) is bytes

My first patch mix bytes and str8 and so re.sub fails in some cases.

So here is a new patch using str8 in dictionary key and str in regex parsing 
(sre_parse.py) (and then reconvert to bytes for 'literals' variable).

Victor Stinner
http://hachoir.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3k-struni-re2.diff
Type: text/x-diff
Size: 5398 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20070809/7ff5e743/attachment.bin 


More information about the Python-3000 mailing list