mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
ChannelStats & Filter & Math & Unit: use utils instead of str.translate.
This commit is contained in:
parent
88c2c130ca
commit
dcd07a2ec4
@ -297,6 +297,7 @@ class ChannelStats(callbacks.Plugin):
|
|||||||
name, channel))
|
name, channel))
|
||||||
stats = wrap(stats, ['channeldb', additional('something')])
|
stats = wrap(stats, ['channeldb', additional('something')])
|
||||||
|
|
||||||
|
_calc_match_forbidden_chars = re.compile('[_[\]]')
|
||||||
_env = {'__builtins__': types.ModuleType('__builtins__')}
|
_env = {'__builtins__': types.ModuleType('__builtins__')}
|
||||||
_env.update(math.__dict__)
|
_env.update(math.__dict__)
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
@ -311,7 +312,7 @@ class ChannelStats(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
# XXX I could do this the right way, and abstract out a safe eval,
|
# XXX I could do this the right way, and abstract out a safe eval,
|
||||||
# or I could just copy/paste from the Math plugin.
|
# or I could just copy/paste from the Math plugin.
|
||||||
if expr != expr.translate(utils.str.chars, '_[]'):
|
if self._calc_match_forbidden_chars.match(expr):
|
||||||
irc.error(_('There\'s really no reason why you should have '
|
irc.error(_('There\'s really no reason why you should have '
|
||||||
'underscores or brackets in your mathematical '
|
'underscores or brackets in your mathematical '
|
||||||
'expression. Please remove them.'), Raise=True)
|
'expression. Please remove them.'), Raise=True)
|
||||||
|
@ -656,7 +656,7 @@ class Filter(callbacks.Plugin):
|
|||||||
|
|
||||||
Returns <text> with the l's made into r's and r's made into l's.
|
Returns <text> with the l's made into r's and r's made into l's.
|
||||||
"""
|
"""
|
||||||
text = text.translate(self._azn_trans)
|
text = self._azn_trans(text)
|
||||||
irc.reply(text)
|
irc.reply(text)
|
||||||
azn = wrap(azn, ['text'])
|
azn = wrap(azn, ['text'])
|
||||||
|
|
||||||
|
@ -148,6 +148,8 @@ class Math(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
return '%s%s' % (realS, imagS)
|
return '%s%s' % (realS, imagS)
|
||||||
|
|
||||||
|
_calc_match_forbidden_chars = re.compile('[_[\]]')
|
||||||
|
_calc_remover = utils.str.MultipleRemover('_[] \t')
|
||||||
###
|
###
|
||||||
# So this is how the 'calc' command works:
|
# So this is how the 'calc' command works:
|
||||||
# First, we make a nice little safe environment for evaluation; basically,
|
# First, we make a nice little safe environment for evaluation; basically,
|
||||||
@ -167,12 +169,12 @@ class Math(callbacks.Plugin):
|
|||||||
crash to the bot with something like '10**10**10**10'. One consequence
|
crash to the bot with something like '10**10**10**10'. One consequence
|
||||||
is that large values such as '10**24' might not be exact.
|
is that large values such as '10**24' might not be exact.
|
||||||
"""
|
"""
|
||||||
if text != text.translate(utils.str.chars, '_[]'):
|
if self._calc_match_forbidden_chars.match(text):
|
||||||
irc.error(_('There\'s really no reason why you should have '
|
irc.error(_('There\'s really no reason why you should have '
|
||||||
'underscores or brackets in your mathematical '
|
'underscores or brackets in your mathematical '
|
||||||
'expression. Please remove them.'))
|
'expression. Please remove them.'))
|
||||||
return
|
return
|
||||||
#text = text.translate(utils.str.chars, '_[] \t')
|
text = self._calc_remover(text)
|
||||||
if 'lambda' in text:
|
if 'lambda' in text:
|
||||||
irc.error(_('You can\'t use lambda in this command.'))
|
irc.error(_('You can\'t use lambda in this command.'))
|
||||||
return
|
return
|
||||||
@ -221,14 +223,14 @@ class Math(callbacks.Plugin):
|
|||||||
math, and can thus cause the bot to suck up CPU. Hence it requires
|
math, and can thus cause the bot to suck up CPU. Hence it requires
|
||||||
the 'trusted' capability to use.
|
the 'trusted' capability to use.
|
||||||
"""
|
"""
|
||||||
if text != text.translate(utils.str.chars, '_[]'):
|
if self._calc_match_forbidden_chars.match(text):
|
||||||
irc.error(_('There\'s really no reason why you should have '
|
irc.error(_('There\'s really no reason why you should have '
|
||||||
'underscores or brackets in your mathematical '
|
'underscores or brackets in your mathematical '
|
||||||
'expression. Please remove them.'))
|
'expression. Please remove them.'))
|
||||||
return
|
return
|
||||||
# This removes spaces, too, but we'll leave the removal of _[] for
|
# This removes spaces, too, but we'll leave the removal of _[] for
|
||||||
# safety's sake.
|
# safety's sake.
|
||||||
text = text.translate(utils.str.chars, '_[] \t')
|
text = self._calc_remover(text)
|
||||||
if 'lambda' in text:
|
if 'lambda' in text:
|
||||||
irc.error(_('You can\'t use lambda in this command.'))
|
irc.error(_('You can\'t use lambda in this command.'))
|
||||||
return
|
return
|
||||||
|
@ -48,6 +48,7 @@ import supybot.callbacks as callbacks
|
|||||||
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
||||||
_ = PluginInternationalization('Unix')
|
_ = PluginInternationalization('Unix')
|
||||||
|
|
||||||
|
_progstats_endline_remover = utils.str.MultipleRemover('\r\n')
|
||||||
def progstats():
|
def progstats():
|
||||||
pw = pwd.getpwuid(os.getuid())
|
pw = pwd.getpwuid(os.getuid())
|
||||||
response = format('Process ID %i running as user %q and as group %q '
|
response = format('Process ID %i running as user %q and as group %q '
|
||||||
@ -55,7 +56,7 @@ def progstats():
|
|||||||
'Running on Python %s.',
|
'Running on Python %s.',
|
||||||
os.getpid(), pw[0], pw[3],
|
os.getpid(), pw[0], pw[3],
|
||||||
os.getcwd(), ' '.join(sys.argv),
|
os.getcwd(), ' '.join(sys.argv),
|
||||||
sys.version.translate(utils.str.chars, '\r\n'))
|
_progstats_endline_remover(sys.version))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
class TimeoutError(IOError):
|
class TimeoutError(IOError):
|
||||||
|
Loading…
Reference in New Issue
Block a user