Make utils.str.perlRoToReplacer less ambiguous.

This commit is contained in:
Valentin Lorentz 2012-08-04 17:36:15 +02:00
parent 8af6761275
commit 452c706092

View File

@ -45,7 +45,6 @@ from structures import TwoWayDictionary
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
internationalizeFunction=PluginInternationalization().internationalizeFunction internationalizeFunction=PluginInternationalization().internationalizeFunction
curry = new.instancemethod
chars = string.maketrans('', '') chars = string.maketrans('', '')
def rsplit(s, sep=None, maxsplit=-1): def rsplit(s, sep=None, maxsplit=-1):
@ -195,9 +194,11 @@ def perlReToReplacer(s):
if 'g' in flags: if 'g' in flags:
g = True g = True
flags = filter('g'.__ne__, flags) flags = filter('g'.__ne__, flags)
if isinstance(flags, list):
flags = ''.join(flags)
r = perlReToPythonRe(sep.join(('', regexp, flags))) r = perlReToPythonRe(sep.join(('', regexp, flags)))
if g: if g:
return curry(r.sub, replace) return lambda s: r.sub(replace, s)
else: else:
return lambda s: r.sub(replace, s, 1) return lambda s: r.sub(replace, s, 1)