Added a scramle() function for scrambling text in regexp replaces. (Works like the upper() function).
This commit is contained in:
parent
2d7e83fb67
commit
b2e5841469
1 changed files with 11 additions and 4 deletions
15
dataobjs.py
15
dataobjs.py
|
@ -8,10 +8,11 @@ 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\\]+)\)")
|
||||||
|
_scramblere = re.compile(r"scramble\(([\w\\]+)\)")
|
||||||
|
|
||||||
class Mood(object):
|
class Mood(object):
|
||||||
moods = ["chummy", "rancorous", "offline", "pleasant", "distraught",
|
moods = ["chummy", "rancorous", "offline", "pleasant", "distraught",
|
||||||
"pranky", "smooth", "ecstatic", "relaxed", "discontent",
|
"pranky", "smooth", "ecstatic", "relaxed", "discontent",
|
||||||
"devious", "sleek", "detestful", "mirthful", "manipulative",
|
"devious", "sleek", "detestful", "mirthful", "manipulative",
|
||||||
"vigorous", "perky", "acceptant", "protective", "mystified",
|
"vigorous", "perky", "acceptant", "protective", "mystified",
|
||||||
"amazed", "insolent", "bemused" ]
|
"amazed", "insolent", "bemused" ]
|
||||||
|
@ -62,7 +63,10 @@ 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 scramblerep(m):
|
||||||
|
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 = _scramblere.sub(scramblerep, to)
|
||||||
return mo.expand(to)
|
return mo.expand(to)
|
||||||
return re.sub(fr, regexprep, string)
|
return re.sub(fr, regexprep, string)
|
||||||
elif self.type == "random":
|
elif self.type == "random":
|
||||||
|
@ -77,6 +81,9 @@ 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 scramblerep(m):
|
||||||
|
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 = _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)
|
||||||
|
@ -125,7 +132,7 @@ class pesterQuirks(object):
|
||||||
q.type=='replace' or q.type=='regexp']
|
q.type=='replace' or q.type=='regexp']
|
||||||
randomrep = [q for q in self.quirklist if q.type=='random']
|
randomrep = [q for q in self.quirklist if q.type=='random']
|
||||||
spelling = [q for q in self.quirklist if q.type=='spelling']
|
spelling = [q for q in self.quirklist if q.type=='spelling']
|
||||||
|
|
||||||
newlist = []
|
newlist = []
|
||||||
for (i, o) in enumerate(lexed):
|
for (i, o) in enumerate(lexed):
|
||||||
if type(o) not in [str, unicode]:
|
if type(o) not in [str, unicode]:
|
||||||
|
@ -190,7 +197,7 @@ class PesterProfile(object):
|
||||||
else:
|
else:
|
||||||
return "C"+initials
|
return "C"+initials
|
||||||
else:
|
else:
|
||||||
return (handle[0]+caps[0]).upper()
|
return (handle[0]+caps[0]).upper()
|
||||||
def colorhtml(self):
|
def colorhtml(self):
|
||||||
if self.color:
|
if self.color:
|
||||||
return self.color.name()
|
return self.color.name()
|
||||||
|
|
Loading…
Reference in a new issue