mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Fixed to make sure all spawned threads set the callback's threaded attribute in the meantime, as well as changed to use utils.changeFunctionName.
This commit is contained in:
parent
cd5a1cb14b
commit
27100c6a2a
@ -42,8 +42,9 @@ import types
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import ircdb
|
import utils
|
||||||
import world
|
import world
|
||||||
|
import ircdb
|
||||||
import ircmsgs
|
import ircmsgs
|
||||||
import ircutils
|
import ircutils
|
||||||
import callbacks
|
import callbacks
|
||||||
@ -101,10 +102,7 @@ def checkCapability(f, capability):
|
|||||||
self.log.warning('%r attempted %s without %s.',
|
self.log.warning('%r attempted %s without %s.',
|
||||||
msg.prefix, f.func_name, capability)
|
msg.prefix, f.func_name, capability)
|
||||||
irc.errorNoCapability(capability)
|
irc.errorNoCapability(capability)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
f.func_name, closure=newf.func_closure)
|
|
||||||
newf.__doc__ = f.__doc__
|
|
||||||
return newf
|
|
||||||
|
|
||||||
def checkChannelCapability(f, capability):
|
def checkChannelCapability(f, capability):
|
||||||
"""Makes sure a user has a certain channel capability before running f.
|
"""Makes sure a user has a certain channel capability before running f.
|
||||||
@ -122,21 +120,30 @@ def checkChannelCapability(f, capability):
|
|||||||
self.log.warning('%r attempted %s without %s.',
|
self.log.warning('%r attempted %s without %s.',
|
||||||
msg.prefix, f.func_name, capability)
|
msg.prefix, f.func_name, capability)
|
||||||
irc.errorNoCapability(chancap)
|
irc.errorNoCapability(chancap)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
f.func_name, closure=newf.func_closure)
|
|
||||||
newf.__doc__ = f.__doc__
|
def _threadedWrapMethod(f):
|
||||||
return newf
|
"""A function to wrap methods that are to be run in a thread, so that the
|
||||||
|
callback's threaded attribute is set to True while the thread is running.
|
||||||
|
"""
|
||||||
|
def newf(self, *args, **kwargs):
|
||||||
|
originalThreaded = self.threaded
|
||||||
|
try:
|
||||||
|
self.threaded = True
|
||||||
|
return f(self, *args, **kwargs)
|
||||||
|
finally:
|
||||||
|
self.threaded = originalThreaded
|
||||||
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
|
|
||||||
def thread(f):
|
def thread(f):
|
||||||
"""Makes sure a command spawns a thread when called."""
|
"""Makes sure a command spawns a thread when called."""
|
||||||
|
f = _threadedWrapMethod(f)
|
||||||
def newf(self, irc, msg, args, *L):
|
def newf(self, irc, msg, args, *L):
|
||||||
ff = types.MethodType(f, self, self.__class__)
|
ff = types.MethodType(f, self, self.__class__)
|
||||||
t = callbacks.CommandThread(self.callCommand, ff, irc, msg, args, *L)
|
t = callbacks.CommandThread(target=irc._callCommand,
|
||||||
|
args=(f.func_name, ff, self))
|
||||||
t.start()
|
t.start()
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
f.func_name, closure=newf.func_closure)
|
|
||||||
newf.__doc__ = f.__doc__
|
|
||||||
return newf
|
|
||||||
|
|
||||||
def name(f):
|
def name(f):
|
||||||
"""Makes sure a name is available based on conf.requireRegistration."""
|
"""Makes sure a name is available based on conf.requireRegistration."""
|
||||||
@ -152,10 +159,7 @@ def name(f):
|
|||||||
L = (name,) + L
|
L = (name,) + L
|
||||||
ff = types.MethodType(f, self, self.__class__)
|
ff = types.MethodType(f, self, self.__class__)
|
||||||
ff(irc, msg, args, *L)
|
ff(irc, msg, args, *L)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
f.func_name, closure=newf.func_closure)
|
|
||||||
newf.__doc__ = f.__doc__
|
|
||||||
return newf
|
|
||||||
|
|
||||||
def channel(f):
|
def channel(f):
|
||||||
"""Gives the command an extra channel arg as if it had called getChannel"""
|
"""Gives the command an extra channel arg as if it had called getChannel"""
|
||||||
@ -164,13 +168,11 @@ def channel(f):
|
|||||||
L = (channel,) + L
|
L = (channel,) + L
|
||||||
ff = types.MethodType(f, self, self.__class__)
|
ff = types.MethodType(f, self, self.__class__)
|
||||||
ff(irc, msg, args, *L)
|
ff(irc, msg, args, *L)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
f.func_name, closure=newf.func_closure)
|
|
||||||
newf.__doc__ = f.__doc__
|
|
||||||
return newf
|
|
||||||
|
|
||||||
def urlSnarfer(f):
|
def urlSnarfer(f):
|
||||||
"""Protects the snarfer from loops and whatnot."""
|
"""Protects the snarfer from loops and whatnot."""
|
||||||
|
f = _threadedWrapMethod(f)
|
||||||
def newf(self, irc, msg, match, *L):
|
def newf(self, irc, msg, match, *L):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
cutoff = now - conf.snarfThrottle
|
cutoff = now - conf.snarfThrottle
|
||||||
@ -190,14 +192,11 @@ def urlSnarfer(f):
|
|||||||
f(self, irc, msg, match, *L)
|
f(self, irc, msg, match, *L)
|
||||||
else:
|
else:
|
||||||
L = list(L)
|
L = list(L)
|
||||||
t = threading.Thread(target=f, args=[self, irc, msg, match]+L)
|
world.threadsSpawned += 1
|
||||||
|
t = threading.Thread(target=f, args=[self,irc,msg,match]+L)
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
world.threadsSpawned += 1
|
return utils.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
|
||||||
f.func_name, closure=newf.func_closure)
|
|
||||||
newf.__doc__ = f.__doc__
|
|
||||||
return newf
|
|
||||||
|
|
||||||
|
|
||||||
class CapabilityCheckingPrivmsg(callbacks.Privmsg):
|
class CapabilityCheckingPrivmsg(callbacks.Privmsg):
|
||||||
|
Loading…
Reference in New Issue
Block a user