lower() regexp function to go along with upper()

This commit is contained in:
Kiooeht 2011-03-29 00:36:02 -07:00
parent a5cce9acfc
commit 403b3ca697

View file

@ -8,6 +8,7 @@ from parsetools import timeDifference, convertTags, lexMessage
from mispeller import mispeller from mispeller import mispeller
_upperre = re.compile(r"upper\(([\w\\]+)\)") _upperre = re.compile(r"upper\(([\w\\]+)\)")
_lowerre = re.compile(r"lower\(([\w\\]+)\)")
_scramblere = re.compile(r"scramble\(([\w\\]+)\)") _scramblere = re.compile(r"scramble\(([\w\\]+)\)")
class Mood(object): class Mood(object):
@ -63,9 +64,12 @@ class pesterQuirk(object):
to = self.quirk["to"] to = self.quirk["to"]
def upperrep(m): def upperrep(m):
return mo.expand(m.group(1)).upper() return mo.expand(m.group(1)).upper()
def lowerrep(m):
return mo.expand(m.group(1)).lower()
def scramblerep(m): def scramblerep(m):
return "".join(random.sample(mo.expand(m.group(1)), len(mo.expand(m.group(1))))) return "".join(random.sample(mo.expand(m.group(1)), len(mo.expand(m.group(1)))))
to = _upperre.sub(upperrep, to) to = _upperre.sub(upperrep, to)
to = _lowerre.sub(lowerrep, to)
to = _scramblere.sub(scramblerep, to) to = _scramblere.sub(scramblerep, to)
return mo.expand(to) return mo.expand(to)
return re.sub(fr, regexprep, string) return re.sub(fr, regexprep, string)
@ -81,9 +85,12 @@ class pesterQuirk(object):
choice = random.choice(self.quirk["randomlist"]) choice = random.choice(self.quirk["randomlist"])
def upperrep(m): def upperrep(m):
return mo.expand(m.group(1)).upper() return mo.expand(m.group(1)).upper()
def lowerrep(m):
return mo.expand(m.group(1)).lower()
def scramblerep(m): def scramblerep(m):
return "".join(random.sample(mo.expand(m.group(1)), len(mo.expand(m.group(1))))) return "".join(random.sample(mo.expand(m.group(1)), len(mo.expand(m.group(1)))))
choice = _upperre.sub(upperrep, choice) choice = _upperre.sub(upperrep, choice)
choice = _lowerre.sub(lowerrep, choice)
choice = _upperre.sub(upperrep, choice) choice = _upperre.sub(upperrep, choice)
return mo.expand(choice) return mo.expand(choice)
return re.sub(self.quirk["from"], randomrep, string) return re.sub(self.quirk["from"], randomrep, string)