[Python-bugs-list] [ python-Bugs-570057 ] Broken pre.subn() (and pre.sub())

noreply@sourceforge.net noreply@sourceforge.net
Thu, 27 Jun 2002 13:19:52 -0700


Bugs item #570057, was opened at 2002-06-17 16:27
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=570057&group_id=5470

Category: Regular Expressions
Group: Python 2.2.1
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Johan Tufvesson (tuben)
Assigned to: Fredrik Lundh (effbot)
Summary: Broken pre.subn() (and pre.sub())

Initial Comment:
The functions pre.subn() and pre.sub() are broken in
Python2.2 and 2.2.1. The following test was done on
SunOS 5.6:

Python 2.2.1 (#1, Jun 13 2002, 12:57:34) 
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for
more information.
>>> import re
>>> re.sub('(a)', '\g<1>', 'bab')
'bab'
>>> import pre as re
>>> re.sub('(a)', '\g<1>', 'bab')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/tools/lib/python2.2/pre.py", line
179, in sub
    return pattern.sub(repl, string, count)
  File "/usr/local/tools/lib/python2.2/pre.py", line
344, in sub
    return self.subn(repl, string, count)[0]
  File "/usr/local/tools/lib/python2.2/pre.py", line
366, in subn
    repl = pcre_expand(_Dummy, repl)
TypeError: 'NoneType' object is not callable

The error has also been reproduced on SunOS5.7 with the
following interpreter:
Python 2.2 (#1, Dec 28 2001, 22:25:04) 
[GCC 2.95.2 19991024 (release)] on sunos5

The error could not be reproduced on SunOS5.6 using
Python2.1.1:
Python 2.1.1 (#5, Sep 10 2001, 13:44:17) 
[GCC 2.95.2 19991024 (release)] on sunos5

NOTE: The example for re.sub() in the Python Library
manual triggers this bug when used with module pre!


----------------------------------------------------------------------

>Comment By: Fredrik Lundh (effbot)
Date: 2002-06-27 22:19

Message:
Logged In: YES 
user_id=38376

fixed in CVS

----------------------------------------------------------------------

Comment By: Fredrik Lundh (effbot)
Date: 2002-06-27 21:15

Message:
Logged In: YES 
user_id=38376

someone who didn't understand the code changed an
"except" to "except error", and the test suite doesn't
spend much energy checking that PRE works as it
should... :-(

(as a workaround, change the line after the "pcre_expand"
call to "except:")

</F>


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=570057&group_id=5470