Fix #3226 (unicity of scheduled event names)

Thanks tchiroux for raising the issue and providing the fix as well.
This commit is contained in:
mathieui 2016-09-30 20:59:31 +02:00
parent e4696e0471
commit 0c63a4bbda

View file

@ -760,6 +760,9 @@ class XMLStream(asyncio.BaseProtocol):
:param repeat: Flag indicating if the scheduled event should
be reset and repeat after executing.
"""
if name in self.scheduled_events:
raise ValueError(
"There is already a scheduled event of name: %s" % name)
if seconds is None:
seconds = RESPONSE_TIMEOUT
cb = functools.partial(callback, *args, **kwargs)
@ -769,7 +772,6 @@ class XMLStream(asyncio.BaseProtocol):
else:
handle = self.loop.call_later(seconds, self._execute_and_unschedule,
name, cb)
# Save that handle, so we can just cancel this scheduled event by
# canceling scheduled_events[name]
self.scheduled_events[name] = handle